Skip to content

Commit

Permalink
correct handling of qt scale factor was introduced
Browse files Browse the repository at this point in the history
  • Loading branch information
nvpopov committed Jul 14, 2021
1 parent e1d5c50 commit 7f6fbfd
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 254 deletions.
1 change: 0 additions & 1 deletion data/style.qss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
* {
font-family : "Nunito";
font-size: 100%;
font-weight: normal;
color: rgb(209, 209, 209);
background: rgb(79, 79, 79);
Expand Down
15 changes: 0 additions & 15 deletions src/qppcad/core/app_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ app_state_t *app_state_t::get_inst() {
}

app_state_t::app_state_t() {

astate_evd = new app_state_event_disp_t;
m_utility_thread_count = std::thread::hardware_concurrency();

}

void app_state_t::init_glapi(){
Expand All @@ -32,7 +30,6 @@ void app_state_t::init_glapi(){
}

void app_state_t::init_shaders() {

sp_default = shader_generators::gen_sp_default();
sp_default_suprematic = shader_generators::gen_sp_default_suprematic();
sp_unit_line = shader_generators::gen_sp_unit_line();
Expand All @@ -45,7 +42,6 @@ void app_state_t::init_shaders() {
sp_buf_bs = shader_generators::gen_sp_buf_bs_sphere();
sp_2c_cylinder = shader_generators::gen_sp_2c_cylinder();
sp_2c_cylinder_suprematic = shader_generators::gen_sp_2c_cylinder_suprematic();

}

void app_state_t::init_meshes() {
Expand Down Expand Up @@ -237,11 +233,9 @@ void app_state_t::load_settings() {
settings.beginGroup("hotkey_manager");
hotkey_mgr->load_from_settings(settings);
settings.endGroup();

}

void app_state_t::save_settings() {

QSettings settings;
settings.setValue("test", 68);

Expand All @@ -250,14 +244,12 @@ void app_state_t::save_settings() {
settings.setValue("console_font_size", m_console_font_size);

if (m_fixtures_dir_is_set) {

// join fixtures dir
std::string fd_joined;
std::for_each(m_fixtures_dirs.begin(), m_fixtures_dirs.end(),
[&fd_joined](const std::string &piece){ fd_joined += piece + ";"; });

settings.setValue("fixtures_dir", QString::fromStdString(fd_joined));

}
// end of general settings

Expand All @@ -275,7 +267,6 @@ void app_state_t::save_settings() {

for (auto &rec : table->arecs)
if (rec.m_redefined) {

settings.setArrayIndex(i);
settings.setValue("number", int(rec.m_number));
settings.setValue("c_r", double(rec.m_color_jmol[0]));
Expand All @@ -284,7 +275,6 @@ void app_state_t::save_settings() {
settings.setValue("r", double(rec.m_radius));
settings.setValue("covrad", double(rec.m_covrad_slater));
i+=1;

}

settings.endArray();
Expand All @@ -307,7 +297,6 @@ void app_state_t::save_settings() {

settings.beginWriteArray("recent_files");
for (int q = 0; q < static_cast<int>(m_recent_files.size()); q++) {

settings.setArrayIndex(q);
settings.setValue("filename", QString::fromStdString(m_recent_files[q].m_file_name));
std::string ff_name =
Expand Down Expand Up @@ -341,20 +330,17 @@ void app_state_t::save_settings() {

settings.beginGroup("cache_vector");
for (auto &rec : m_env_vec3) {

QStringList vecl;
vecl.reserve(3);
for (size_t q = 0; q < 3; q++) vecl.push_back(QString("%1").arg(rec.second[q]));
settings.setValue(QString::fromStdString(rec.first), vecl);

}

settings.endGroup();

settings.beginGroup("hotkey_manager");
hotkey_mgr->save_to_settings(settings);
settings.endGroup();

}

void app_state_t::pylog(std::string logstr) {
Expand All @@ -365,7 +351,6 @@ void app_state_t::pylog(std::string logstr) {
void app_state_t::add_recent_file(const std::string &file_name,
const bool is_native,
const size_t ff_id) {

QFileInfo file_info(QString::fromStdString(file_name));
m_last_dir = file_info.absoluteDir().path();
tlog("M_LAST_DIR= {}", m_last_dir.toStdString());
Expand Down
1 change: 1 addition & 0 deletions src/qppcad/core/app_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class app_state_t {
bool m_disable_app{false};
bool m_viewport_dirty{true};
bool m_immersive_mode{false};
std::optional<float> m_qt_scale_factor{};

size_t m_gv_overview_max_atoms{15000};
size_t m_gv_overview_max_sel_types{6};
Expand Down
19 changes: 13 additions & 6 deletions src/qppcad/core/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QCommandLineParser>
#include <qppcad/core/ittnotify_support.hpp>
#include <atomic>
#include <QtGlobal>

using namespace qpp;
using namespace qpp::cad;
Expand Down Expand Up @@ -43,6 +44,18 @@ int main (int argc, char **argv) {
QCoreApplication::setOrganizationDomain("100ways.dev");
QCoreApplication::setApplicationName("qppcad");
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);

app_state_t::init_inst();
app_state_t *astate = app_state_t::get_inst();
astate->init_managers();
astate->ws_mgr->init_ws_item_bhv_mgr();
astate->load_settings();
//bool scale_factor_redefined{false};
if (qEnvironmentVariableIsSet("QT_SCALE_FACTOR")) {
astate->m_qt_scale_factor = qEnvironmentVariable("QT_SCALE_FACTOR").toFloat();
astate->size_guide.m_scale_factor = astate->m_qt_scale_factor.value_or(1.0f);
}

QApplication app(argc, argv);

Expand Down Expand Up @@ -73,18 +86,12 @@ int main (int argc, char **argv) {
std::signal(SIGTERM, on_app_exit);
}

app_state_t::init_inst();
app_state_t *astate = app_state_t::get_inst();
astate->tlog("@GIT_REVISION={}, @BUILD_DATE={}",
build_info_t::get_git_version(), build_info_t::get_git_version());

std::ifstream test_in_dev_env("../data/refs/laf3_p3.vasp");
bool under_dev_env = test_in_dev_env.good();

astate->init_managers();
astate->ws_mgr->init_ws_item_bhv_mgr();
astate->load_settings();

astate->init_fixtures();

if (under_dev_env) {
Expand Down
6 changes: 6 additions & 0 deletions src/qppcad/python/python_embedded_workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <qppcad/ws_item/ws_item_behaviour_manager.hpp>

#include <qppcad/core/app_state.hpp>
#include <QApplication>

using namespace qpp;
using namespace qpp::cad;
Expand Down Expand Up @@ -125,7 +126,12 @@ void cws_changed() {
astate->astate_evd->cur_ws_changed();
}

void ev_update() {
qApp->processEvents();
}

PYBIND11_EMBEDDED_MODULE(cad, m) {
m.def("ev_update", &ev_update);

py::class_<hs_doc_base_t> py_hist_doc_base_t(m, "hist_doc_base_t");
py_hist_doc_base_t.def("get_cur_epoch", &hs_doc_base_t::get_cur_epoch);
Expand Down
Loading

0 comments on commit 7f6fbfd

Please sign in to comment.