Changeset View
Changeset View
Standalone View
Standalone View
app/sidebar.cpp
Show All 28 Lines | |||||
29 | #include <QVBoxLayout> | 29 | #include <QVBoxLayout> | ||
30 | #include <QIcon> | 30 | #include <QIcon> | ||
31 | 31 | | |||
32 | // KDE | 32 | // KDE | ||
33 | #include <KIconLoader> | 33 | #include <KIconLoader> | ||
34 | #include <QFontDatabase> | 34 | #include <QFontDatabase> | ||
35 | 35 | | |||
36 | // Local | 36 | // Local | ||
37 | #include <lib/gwenviewconfig.h> | ||||
38 | #include <lib/signalblocker.h> | ||||
37 | 39 | | |||
38 | namespace Gwenview | 40 | namespace Gwenview | ||
39 | { | 41 | { | ||
40 | 42 | | |||
41 | /** | 43 | /** | ||
42 | * A button which always leave room for an icon, even if there is none, so that | 44 | * A button which always leave room for an icon, even if there is none, so that | ||
43 | * all button texts are correctly aligned. | 45 | * all button texts are correctly aligned. | ||
44 | */ | 46 | */ | ||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Line(s) | |||||
213 | , d(new SideBarPrivate) | 215 | , d(new SideBarPrivate) | ||
214 | { | 216 | { | ||
215 | setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)); | 217 | setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)); | ||
216 | tabBar()->setDocumentMode(true); | 218 | tabBar()->setDocumentMode(true); | ||
217 | tabBar()->setUsesScrollButtons(false); | 219 | tabBar()->setUsesScrollButtons(false); | ||
218 | tabBar()->setFocusPolicy(Qt::NoFocus); | 220 | tabBar()->setFocusPolicy(Qt::NoFocus); | ||
219 | setTabPosition(QTabWidget::South); | 221 | setTabPosition(QTabWidget::South); | ||
220 | setElideMode(Qt::ElideRight); | 222 | setElideMode(Qt::ElideRight); | ||
223 | | ||||
224 | connect(tabBar(), &QTabBar::currentChanged, [=]() { | ||||
225 | GwenviewConfig::setSideBarPage(currentPage()); | ||||
226 | }); | ||||
221 | } | 227 | } | ||
222 | 228 | | |||
223 | SideBar::~SideBar() | 229 | SideBar::~SideBar() | ||
224 | { | 230 | { | ||
225 | delete d; | 231 | delete d; | ||
226 | } | 232 | } | ||
227 | 233 | | |||
228 | QSize SideBar::sizeHint() const | 234 | QSize SideBar::sizeHint() const | ||
229 | { | 235 | { | ||
230 | return QSize(200, 200); | 236 | return QSize(200, 200); | ||
231 | } | 237 | } | ||
232 | 238 | | |||
233 | void SideBar::addPage(SideBarPage* page) | 239 | void SideBar::addPage(SideBarPage* page) | ||
234 | { | 240 | { | ||
241 | // Prevent emitting currentChanged() while populating pages | ||||
242 | SignalBlocker blocker(tabBar()); | ||||
235 | addTab(page, page->title()); | 243 | addTab(page, page->title()); | ||
236 | } | 244 | } | ||
237 | 245 | | |||
rkflx: Uh oh. I did not think of that problem…
How about moving the `connect` to the end of… | |||||
I would rather keep it in SideBar. What do you think about e.g. SideBar::enableAutoSaveConfig()? muhlenpfordt: I would rather keep it in `SideBar`. What do you think about e.g. `SideBar… | |||||
Yeah, that would make SideBar easier to understand. I assume you mean to put the connect in your new member function, and then call that after all sidebar pages have been added? If so, that plan sounds good. "Enable (…) config" was not immediately clear to me, perhaps enableConfigSaving? rkflx: Yeah, that would make `SideBar` easier to understand.
I assume you mean to put the `connect`… | |||||
Ah, wait a moment. Just found out about https://doc.qt.io/qt-5/qobject.html#blockSignals. Would this help? rkflx: Ah, wait a moment. Just found out about https://doc.qt.io/qt-5/qobject.html#blockSignals. Would… | |||||
238 | QString SideBar::currentPage() const | 246 | QString SideBar::currentPage() const | ||
239 | { | 247 | { | ||
240 | return currentWidget()->objectName(); | 248 | return currentWidget()->objectName(); | ||
241 | } | 249 | } | ||
242 | 250 | | |||
243 | void SideBar::setCurrentPage(const QString& name) | 251 | void SideBar::setCurrentPage(const QString& name) | ||
244 | { | 252 | { | ||
245 | for (int index = 0; index < count(); ++index) { | 253 | for (int index = 0; index < count(); ++index) { | ||
246 | if (widget(index)->objectName() == name) { | 254 | if (widget(index)->objectName() == name) { | ||
247 | setCurrentIndex(index); | 255 | setCurrentIndex(index); | ||
248 | } | 256 | } | ||
249 | } | 257 | } | ||
250 | } | 258 | } | ||
251 | 259 | | |||
260 | void SideBar::loadConfig() | ||||
261 | { | ||||
262 | setCurrentPage(GwenviewConfig::sideBarPage()); | ||||
263 | } | ||||
264 | | ||||
252 | } // namespace | 265 | } // namespace |
Uh oh. I did not think of that problem…
How about moving the connect to the end of setupContextManagerItems?