Changeset View
Standalone View
app/SettingsBase.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | |||||
73 | 73 | | |||
74 | SettingsBase::~SettingsBase() | 74 | SettingsBase::~SettingsBase() | ||
75 | { | 75 | { | ||
76 | delete rootModule; | 76 | delete rootModule; | ||
77 | } | 77 | } | ||
78 | 78 | | |||
79 | QSize SettingsBase::sizeHint() const | 79 | QSize SettingsBase::sizeHint() const | ||
80 | { | 80 | { | ||
81 | qreal factor = qBound(1., QGuiApplication::primaryScreen()->physicalDotsPerInch()/96., 3.); | | |||
82 | 81 | | |||
83 | return QSize(720*factor, 600*factor); | 82 | // on smaller or portrait-rotated screens, do not max out height and/or width | ||
83 | const QSize screenSize = (QGuiApplication::primaryScreen()->availableSize()*0.9); | ||||
ngraham: you don't need to divide by 96 anymore; `devicePixelRatio()` gives you a number generally… | |||||
You forgot const. Also, you could multiply whole QSize by factor so Qt will round width and height. ;-) zzag: You forgot `const`.
Also, you could multiply whole QSize by `factor` so Qt will round width… | |||||
I know you were told to change to this, but don't do that. Qt will scale the size you give it here by the devicePixelRatio. This is scaling it twice which we don't want to do. We shouldn't need to be doing any custom high DPI code in window sizing. davidedmundson: > qreal factor = qBound(1.0, QGuiApplication::primaryScreen()->devicePixelRatio()/96., 3.0);
I… | |||||
So should I just run the "preferred size" (1024x760) through the boundedTo function for odd-sized screens? In other words, ditch the scale factor completely? As in: const QSize screenSize = (QGuiApplication::primaryScreen()->availableSize()*0.9); const QSize targetSize = QSize(1024, 700); return targetSize.boundedTo(screenSize); I thought I'd ask before updating the diff for the 19th time. :-) sharvey: So should I just run the "preferred size" (1024x760) through the `boundedTo` function for odd… | |||||
Confirmed. This works fine for me, so you can just remove the factor part entirely. Sorry for sending you down the wrong path! ngraham: Confirmed. This works fine for me, so you can just remove the `factor` part entirely. Sorry for… | |||||
84 | const QSize targetSize = QSize(1024, 700); | ||||
85 | return targetSize.boundedTo(screenSize); | ||||
86 | | ||||
84 | } | 87 | } | ||
85 | 88 | | |||
86 | void SettingsBase::initApplication() | 89 | void SettingsBase::initApplication() | ||
87 | { | 90 | { | ||
88 | // Prepare the menu of all modules | 91 | // Prepare the menu of all modules | ||
89 | categories = KServiceTypeTrader::self()->query(QStringLiteral("SystemSettingsCategory")); | 92 | categories = KServiceTypeTrader::self()->query(QStringLiteral("SystemSettingsCategory")); | ||
90 | modules = KServiceTypeTrader::self()->query(QStringLiteral("KCModule"), QStringLiteral("[X-KDE-System-Settings-Parent-Category] != ''")); | 93 | modules = KServiceTypeTrader::self()->query(QStringLiteral("KCModule"), QStringLiteral("[X-KDE-System-Settings-Parent-Category] != ''")); | ||
91 | modules += KServiceTypeTrader::self()->query(QStringLiteral("SystemSettingsExternalApp")); | 94 | modules += KServiceTypeTrader::self()->query(QStringLiteral("SystemSettingsExternalApp")); | ||
92 | rootModule = new MenuItem( true, nullptr ); | 95 | rootModule = new MenuItem( true, nullptr ); | ||
93 | initMenuList(rootModule); | 96 | initMenuList(rootModule); | ||
94 | // Handle lost+found modules... | 97 | // Handle lost+found modules... | ||
95 | if (lostFound) { | 98 | if (lostFound) { | ||
96 | for (int i = 0; i < modules.size(); ++i) { | 99 | for (int i = 0; i < modules.size(); ++i) { | ||
97 | const KService::Ptr entry = modules.at(i); | 100 | const KService::Ptr entry = modules.at(i); | ||
98 | MenuItem * infoItem = new MenuItem(false, lostFound); | 101 | MenuItem * infoItem = new MenuItem(false, lostFound); | ||
99 | infoItem->setService( entry ); | 102 | infoItem->setService( entry ); | ||
100 | qCDebug(SYSTEMSETTINGS_APP_LOG) << "Added " << entry->name(); | 103 | qCDebug(SYSTEMSETTINGS_APP_LOG) << "Added " << entry->name(); | ||
101 | } | 104 | } | ||
102 | } | 105 | } | ||
103 | 106 | | |||
104 | // Prepare the Base Data | 107 | // Prepare the Base Data | ||
You've already added a setMinimumSize() call below (under the "// enforce minimum window size" comment); do we need this second one here? ngraham: You've already added a `setMinimumSize()` call below (under the "// enforce minimum window… | |||||
105 | BaseData::instance()->setMenuItem( rootModule ); | 108 | BaseData::instance()->setMenuItem( rootModule ); | ||
ngraham: Do we actually need this? | |||||
It wasn't referenced anywhere else in the project. Probably a leftover from times long ago. sharvey: It wasn't referenced anywhere else in the project. Probably a leftover from times long ago. | |||||
106 | // Load all possible views | 109 | // Load all possible views | ||
107 | const KService::List pluginObjects = KServiceTypeTrader::self()->query( QStringLiteral("SystemSettingsView") ); | 110 | const KService::List pluginObjects = KServiceTypeTrader::self()->query( QStringLiteral("SystemSettingsView") ); | ||
108 | const int nbPlugins = pluginObjects.count(); | 111 | const int nbPlugins = pluginObjects.count(); | ||
109 | for( int pluginsDone = 0; pluginsDone < nbPlugins ; ++pluginsDone ) { | 112 | for( int pluginsDone = 0; pluginsDone < nbPlugins ; ++pluginsDone ) { | ||
110 | KService::Ptr activeService = pluginObjects.at( pluginsDone ); | 113 | KService::Ptr activeService = pluginObjects.at( pluginsDone ); | ||
111 | QString error; | 114 | QString error; | ||
112 | BaseMode * controller = activeService->createInstance<BaseMode>(this, QVariantList(), &error); | 115 | BaseMode * controller = activeService->createInstance<BaseMode>(this, QVariantList(), &error); | ||
113 | if( error.isEmpty() ) { | 116 | if( error.isEmpty() ) { | ||
114 | possibleViews.insert( activeService->library(), controller ); | 117 | possibleViews.insert( activeService->library(), controller ); | ||
115 | controller->init( activeService ); | 118 | controller->init( activeService ); | ||
116 | connect(controller, &BaseMode::changeToolBarItems, this, &SettingsBase::changeToolBar); | 119 | connect(controller, &BaseMode::changeToolBarItems, this, &SettingsBase::changeToolBar); | ||
117 | connect(controller, &BaseMode::actionsChanged, this, &SettingsBase::updateViewActions); | 120 | connect(controller, &BaseMode::actionsChanged, this, &SettingsBase::updateViewActions); | ||
118 | connect(searchText, &KLineEdit::textChanged, controller, &BaseMode::searchChanged); | 121 | connect(searchText, &KLineEdit::textChanged, controller, &BaseMode::searchChanged); | ||
119 | connect(controller, &BaseMode::viewChanged, this, &SettingsBase::viewChange); | 122 | connect(controller, &BaseMode::viewChanged, this, &SettingsBase::viewChange); | ||
120 | } else { | 123 | } else { | ||
121 | qCWarning(SYSTEMSETTINGS_APP_LOG) << QStringLiteral("View load error: ") + error; | 124 | qCWarning(SYSTEMSETTINGS_APP_LOG) << QStringLiteral("View load error: ") + error; | ||
122 | } | 125 | } | ||
123 | } | 126 | } | ||
124 | searchText->completionObject()->setIgnoreCase( true ); | 127 | searchText->completionObject()->setIgnoreCase( true ); | ||
125 | searchText->completionObject()->setItems( BaseData::instance()->menuItem()->keywords() ); | 128 | searchText->completionObject()->setItems( BaseData::instance()->menuItem()->keywords() ); | ||
126 | changePlugin(); | 129 | changePlugin(); | ||
130 | | ||||
131 | // enforce minimum window size | ||||
cfeck: Why? I use some systems in portrait mode, 768x1024 pixels. | |||||
132 | setMinimumSize(SettingsBase::sizeHint()); | ||||
127 | activateWindow(); | 133 | activateWindow(); | ||
128 | } | 134 | } | ||
129 | 135 | | |||
130 | void SettingsBase::initToolBar() | 136 | void SettingsBase::initToolBar() | ||
131 | { | 137 | { | ||
132 | // Fill the toolbar with default actions | 138 | // Fill the toolbar with default actions | ||
133 | // Exit is the very last action | 139 | // Exit is the very last action | ||
134 | quitAction = actionCollection()->addAction( KStandardAction::Quit, QStringLiteral("quit_action"), this, SLOT(close()) ); | 140 | quitAction = actionCollection()->addAction( KStandardAction::Quit, QStringLiteral("quit_action"), this, SLOT(close()) ); | ||
Show All 16 Lines | |||||
151 | connect( searchAction, SIGNAL(triggered(bool)), searchText, SLOT(setFocus())); | 157 | connect( searchAction, SIGNAL(triggered(bool)), searchText, SLOT(setFocus())); | ||
152 | actionCollection()->addAction( QStringLiteral("searchText"), searchAction ); | 158 | actionCollection()->addAction( QStringLiteral("searchText"), searchAction ); | ||
153 | // Initialise the Window | 159 | // Initialise the Window | ||
154 | setupGUI(Save|Create,QString()); | 160 | setupGUI(Save|Create,QString()); | ||
155 | menuBar()->hide(); | 161 | menuBar()->hide(); | ||
156 | 162 | | |||
157 | // Toolbar & Configuration | 163 | // Toolbar & Configuration | ||
158 | helpActionMenu->setMenu( dynamic_cast<QMenu*>( factory()->container(QStringLiteral("help"), this) ) ); | 164 | helpActionMenu->setMenu( dynamic_cast<QMenu*>( factory()->container(QStringLiteral("help"), this) ) ); | ||
159 | setMinimumSize(620,430); | | |||
Don't remove this, or else it becomes possible to resize the window to absurdly, unusably small sizes. The value could be changed, but we shouldn't remove this entirely. ngraham: Don't remove this, or else it becomes possible to resize the window to absurdly, unusably small… | |||||
Moved to line 130; keep together with initial window size setting. I went with an arbitrary but common 800x600 for the minimum size. sharvey: Moved to line 130; keep together with initial window size setting. I went with an arbitrary but… | |||||
160 | toolBar()->setMovable(false); // We don't allow any changes | 165 | toolBar()->setMovable(false); // We don't allow any changes | ||
161 | changeToolBar( BaseMode::Search | BaseMode::Configure ); | 166 | changeToolBar( BaseMode::Search | BaseMode::Configure ); | ||
162 | } | 167 | } | ||
163 | 168 | | |||
164 | void SettingsBase::initHelpMenu() | 169 | void SettingsBase::initHelpMenu() | ||
165 | { | 170 | { | ||
166 | helpActionMenu = new KActionMenu( QIcon::fromTheme(QStringLiteral("help-contents")), i18n("Help"), this ); | 171 | helpActionMenu = new KActionMenu( QIcon::fromTheme(QStringLiteral("help-contents")), i18n("Help"), this ); | ||
167 | helpActionMenu->setDelayed( false ); | 172 | helpActionMenu->setDelayed( false ); | ||
▲ Show 20 Lines • Show All 250 Lines • Show Last 20 Lines |
you don't need to divide by 96 anymore; devicePixelRatio() gives you a number generally between 1 and 4, depending on the scale factor used. In fact, you might be able to remove the entire qBounds part too, since that won't be forwards-compatible with the next decade's 16k displays...