Changeset View
Changeset View
Standalone View
Standalone View
ToolTips/tooltipmanager.cpp
Show All 25 Lines | |||||
26 | #include <QLabel> | 26 | #include <QLabel> | ||
27 | #include <QTimer> | 27 | #include <QTimer> | ||
28 | #include <QScrollBar> | 28 | #include <QScrollBar> | ||
29 | #include <QGridLayout> | 29 | #include <QGridLayout> | ||
30 | #include <QApplication> | 30 | #include <QApplication> | ||
31 | #include <QAbstractItemView> | 31 | #include <QAbstractItemView> | ||
32 | 32 | | |||
33 | #include <QIcon> | 33 | #include <QIcon> | ||
34 | #include <KIconLoader> | ||||
34 | #include <KColorScheme> | 35 | #include <KColorScheme> | ||
35 | #include <KToolTipWidget> | 36 | #include <KToolTipWidget> | ||
36 | 37 | | |||
38 | class IconLoaderSingleton | ||||
39 | { | ||||
40 | public: | ||||
41 | IconLoaderSingleton() = default; | ||||
42 | | ||||
43 | KIconLoader self; | ||||
44 | }; | ||||
45 | | ||||
46 | Q_GLOBAL_STATIC(IconLoaderSingleton, privateIconLoaderSelf) | ||||
47 | | ||||
37 | class ToolTipManager::Private | 48 | class ToolTipManager::Private | ||
38 | { | 49 | { | ||
39 | public: | 50 | public: | ||
40 | KToolTipWidget *tooltip = nullptr; | 51 | KToolTipWidget *tooltip = nullptr; | ||
41 | QAbstractItemView* view = nullptr; | 52 | QAbstractItemView* view = nullptr; | ||
42 | QTimer* timer = nullptr; | 53 | QTimer* timer = nullptr; | ||
43 | QModelIndex item; | 54 | QModelIndex item; | ||
44 | QRect itemRect; | 55 | QRect itemRect; | ||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Line(s) | 178 | if ( comment ) { | |||
168 | text = QStringLiteral( "<b>%1</b>" ).arg( menuItem->data() ); | 179 | text = QStringLiteral( "<b>%1</b>" ).arg( menuItem->data() ); | ||
169 | } | 180 | } | ||
170 | 181 | | |||
171 | QLabel * textLabel = new QLabel( toolTip ); | 182 | QLabel * textLabel = new QLabel( toolTip ); | ||
172 | textLabel->setForegroundRole(QPalette::ToolTipText); | 183 | textLabel->setForegroundRole(QPalette::ToolTipText); | ||
173 | textLabel->setText( text ); | 184 | textLabel->setText( text ); | ||
174 | 185 | | |||
175 | // Get icon | 186 | // Get icon | ||
176 | QIcon icon( menuItem->icon() ); | 187 | QPalette pal = textLabel->palette(); | ||
188 | for (auto state : { QPalette::Active, QPalette::Inactive, QPalette::Disabled }) { | ||||
189 | pal.setBrush(state, QPalette::WindowText, pal.toolTipText()); | ||||
190 | pal.setBrush(state, QPalette::Window, pal.toolTipBase()); | ||||
191 | } | ||||
192 | | ||||
193 | privateIconLoaderSelf->self.setCustomPalette(pal); | ||||
194 | | ||||
195 | QIcon icon = KDE::icon(menuItem->iconName(), &privateIconLoaderSelf->self); | ||||
177 | QLabel * iconLabel = new QLabel( toolTip ); | 196 | QLabel * iconLabel = new QLabel( toolTip ); | ||
178 | iconLabel->setPixmap( icon.pixmap(iconSize) ); | 197 | iconLabel->setPixmap( icon.pixmap(iconSize) ); | ||
179 | iconLabel->setMaximumSize( iconSize ); | 198 | iconLabel->setMaximumSize( iconSize ); | ||
180 | 199 | | |||
181 | // Generate layout | 200 | // Generate layout | ||
182 | QHBoxLayout * layout = new QHBoxLayout(); | 201 | QHBoxLayout * layout = new QHBoxLayout(); | ||
183 | layout->addWidget( iconLabel ); | 202 | layout->addWidget( iconLabel ); | ||
184 | layout->addWidget( textLabel ); | 203 | layout->addWidget( textLabel ); | ||
185 | 204 | | |||
186 | return layout; | 205 | return layout; | ||
187 | } | 206 | } | ||
188 | 207 | |