Changeset View
Changeset View
Standalone View
Standalone View
kcms/kfontinst/kcmfontinst/FontFilter.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * KFontInst - KDE Font Installer | 2 | * KFontInst - KDE Font Installer | ||
3 | * | 3 | * | ||
4 | * Copyright 2003-2007 Craig Drummond <craig@kde.org> | 4 | * Copyright 2003-2007 Craig Drummond <craig@kde.org> | ||
5 | * 2019 Guo Yunhe <i@guoyunhe.me> | ||||
5 | * | 6 | * | ||
6 | * ---- | 7 | * ---- | ||
7 | * | 8 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | 10 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | 11 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | 12 | * (at your option) any later version. | ||
12 | * | 13 | * | ||
Show All 9 Lines | |||||
22 | */ | 23 | */ | ||
23 | 24 | | |||
24 | #include "FontFilter.h" | 25 | #include "FontFilter.h" | ||
25 | #include "FontFilterProxyStyle.h" | 26 | #include "FontFilterProxyStyle.h" | ||
26 | #include "FontList.h" | 27 | #include "FontList.h" | ||
27 | #include <KIconLoader> | 28 | #include <KIconLoader> | ||
28 | #include <KToggleAction> | 29 | #include <KToggleAction> | ||
29 | #include <KSelectAction> | 30 | #include <KSelectAction> | ||
30 | #include <QIcon> | | |||
31 | #include <QMimeDatabase> | 31 | #include <QMimeDatabase> | ||
32 | #include <QLabel> | 32 | #include <QLabel> | ||
33 | #include <QPainter> | 33 | #include <QPainter> | ||
34 | #include <QStyleOption> | 34 | #include <QStyleOption> | ||
35 | #include <QSet> | 35 | #include <QSet> | ||
36 | #include <QString> | 36 | #include <QString> | ||
37 | #include <QMenu> | 37 | #include <QMenu> | ||
38 | #include <QMouseEvent> | 38 | #include <QMouseEvent> | ||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 108 | QList<SortAction>::ConstIterator s(sorted.constBegin()), | |||
109 | sEnd(sorted.constEnd()); | 109 | sEnd(sorted.constEnd()); | ||
110 | 110 | | |||
111 | for(; s!=sEnd; ++s) | 111 | for(; s!=sEnd; ++s) | ||
112 | group->addAction((*s).action); | 112 | group->addAction((*s).action); | ||
113 | } | 113 | } | ||
114 | } | 114 | } | ||
115 | 115 | | |||
116 | CFontFilter::CFontFilter(QWidget *parent) | 116 | CFontFilter::CFontFilter(QWidget *parent) | ||
117 | : KLineEdit(parent) | 117 | : QWidget(parent) | ||
118 | { | 118 | { | ||
119 | setClearButtonShown(true); | 119 | itsIcons[CRIT_FAMILY] = QIcon::fromTheme("draw-text"); | ||
120 | setTrapReturnKey(true); | 120 | itsTexts[CRIT_FAMILY] = i18n("Family"); | ||
121 | itsIcons[CRIT_STYLE] = QIcon::fromTheme("format-text-bold"); | ||||
122 | itsTexts[CRIT_STYLE] = i18n("Style"); | ||||
123 | itsIcons[CRIT_FOUNDRY] = QIcon::fromTheme("user-identity"); | ||||
124 | itsTexts[CRIT_FOUNDRY] = i18n("Foundry"); | ||||
125 | itsIcons[CRIT_FONTCONFIG] = QIcon::fromTheme("system-search"); | ||||
126 | itsTexts[CRIT_FONTCONFIG] = i18n("FontConfig Match"); | ||||
127 | itsIcons[CRIT_FILETYPE] = QIcon::fromTheme("preferences-desktop-font-installer"); | ||||
128 | itsTexts[CRIT_FILETYPE] = i18n("File Type"); | ||||
129 | itsIcons[CRIT_FILENAME] = QIcon::fromTheme("application-x-font-type1"); | ||||
130 | itsTexts[CRIT_FILENAME] = i18n("File Name"); | ||||
131 | itsIcons[CRIT_LOCATION] = QIcon::fromTheme("folder"); | ||||
132 | itsTexts[CRIT_LOCATION] = i18n("File Location"); | ||||
133 | itsIcons[CRIT_WS] = QIcon::fromTheme("character-set"); | ||||
134 | itsTexts[CRIT_WS] = i18n("Writing System"); | ||||
135 | | ||||
136 | m_layout = new QHBoxLayout; | ||||
137 | | ||||
138 | m_menuButton = new QPushButton(itsIcons[CRIT_FAMILY], itsTexts[CRIT_FAMILY], this); | ||||
139 | m_menuButton->setToolTip(i18n("Set Criteria")); | ||||
140 | m_layout->addWidget(m_menuButton); | ||||
141 | | ||||
142 | m_lineEdit = new QLineEdit(this); | ||||
143 | m_lineEdit->setClearButtonEnabled(true); | ||||
144 | m_layout->addWidget(m_lineEdit); | ||||
121 | 145 | | |||
122 | itsMenuButton = new QLabel(this); | 146 | setLayout(m_layout); | ||
123 | itsMenuButton->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); | 147 | | ||
124 | itsMenuButton->setCursor(Qt::ArrowCursor); | 148 | connect(m_lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &))); | ||
125 | itsMenuButton->setToolTip(i18n("Set Criteria")); | 149 | | ||
126 | 150 | m_menu=new QMenu(this); | |||
127 | itsMenu=new QMenu(this); | 151 | m_menuButton->setMenu(m_menu); | ||
128 | itsPixmaps[CRIT_FAMILY]=SmallIcon("draw-text"); | | |||
129 | itsPixmaps[CRIT_STYLE]=SmallIcon("format-text-bold"); | | |||
130 | itsPixmaps[CRIT_FOUNDRY]=SmallIcon("user-identity"); | | |||
131 | itsPixmaps[CRIT_FONTCONFIG]=SmallIcon("system-search"); | | |||
132 | itsPixmaps[CRIT_FILETYPE]=SmallIcon("preferences-desktop-font-installer"); | | |||
133 | itsPixmaps[CRIT_FILENAME]=SmallIcon("application-x-font-type1"); | | |||
134 | itsPixmaps[CRIT_LOCATION]=SmallIcon("folder"); | | |||
135 | itsPixmaps[CRIT_WS]=SmallIcon("character-set"); | | |||
136 | 152 | | |||
137 | itsActionGroup=new QActionGroup(this); | 153 | itsActionGroup=new QActionGroup(this); | ||
138 | addAction(CRIT_FAMILY, i18n("Family"), true); | 154 | addAction(CRIT_FAMILY, true); | ||
139 | addAction(CRIT_STYLE, i18n("Style"), false); | 155 | addAction(CRIT_STYLE, false); | ||
140 | 156 | | |||
141 | KSelectAction *foundryMenu=new KSelectAction(QIcon(itsPixmaps[CRIT_FOUNDRY]), i18n("Foundry"), this); | 157 | KSelectAction *foundryMenu=new KSelectAction(itsIcons[CRIT_FOUNDRY], itsTexts[CRIT_FOUNDRY], this); | ||
142 | itsActions[CRIT_FOUNDRY]=foundryMenu; | 158 | itsActions[CRIT_FOUNDRY]=foundryMenu; | ||
143 | itsMenu->addAction(itsActions[CRIT_FOUNDRY]); | 159 | m_menu->addAction(itsActions[CRIT_FOUNDRY]); | ||
144 | foundryMenu->setData((int)CRIT_FOUNDRY); | 160 | foundryMenu->setData((int)CRIT_FOUNDRY); | ||
145 | foundryMenu->setVisible(false); | 161 | foundryMenu->setVisible(false); | ||
146 | connect(foundryMenu, SIGNAL(triggered(QString)), SLOT(foundryChanged(QString))); | 162 | connect(foundryMenu, SIGNAL(triggered(QString)), SLOT(foundryChanged(QString))); | ||
147 | 163 | | |||
148 | addAction(CRIT_FONTCONFIG, i18n("FontConfig Match"), false); | 164 | addAction(CRIT_FONTCONFIG, false); | ||
149 | 165 | | |||
150 | KSelectAction *ftMenu=new KSelectAction(QIcon(itsPixmaps[CRIT_FILETYPE]), i18n("File Type"), this); | 166 | KSelectAction *ftMenu=new KSelectAction(itsIcons[CRIT_FILETYPE], itsTexts[CRIT_FILETYPE], this); | ||
151 | itsActions[CRIT_FILETYPE]=ftMenu; | 167 | itsActions[CRIT_FILETYPE]=ftMenu; | ||
152 | itsMenu->addAction(itsActions[CRIT_FILETYPE]); | 168 | m_menu->addAction(itsActions[CRIT_FILETYPE]); | ||
153 | ftMenu->setData((int)CRIT_FILETYPE); | 169 | ftMenu->setData((int)CRIT_FILETYPE); | ||
154 | 170 | | |||
155 | QStringList::ConstIterator it(CFontList::fontMimeTypes.constBegin()), | 171 | QStringList::ConstIterator it(CFontList::fontMimeTypes.constBegin()), | ||
156 | end(CFontList::fontMimeTypes.constEnd()); | 172 | end(CFontList::fontMimeTypes.constEnd()); | ||
157 | QMimeDatabase db; | 173 | QMimeDatabase db; | ||
158 | for(; it!=end; ++it) | 174 | for(; it!=end; ++it) | ||
159 | if((*it)!="application/vnd.kde.fontspackage") | 175 | if((*it)!="application/vnd.kde.fontspackage") | ||
160 | { | 176 | { | ||
Show All 9 Lines | 185 | foreach (QString pattern, mime.globPatterns()) | |||
170 | mimes.append(pattern.remove(QStringLiteral("*."))); | 186 | mimes.append(pattern.remove(QStringLiteral("*."))); | ||
171 | act->setData(mimes); | 187 | act->setData(mimes); | ||
172 | } | 188 | } | ||
173 | 189 | | |||
174 | sortActions(ftMenu); | 190 | sortActions(ftMenu); | ||
175 | connect(ftMenu, SIGNAL(triggered(QString)), SLOT(ftChanged(QString))); | 191 | connect(ftMenu, SIGNAL(triggered(QString)), SLOT(ftChanged(QString))); | ||
176 | itsCurrentFileTypes.clear(); | 192 | itsCurrentFileTypes.clear(); | ||
177 | 193 | | |||
178 | addAction(CRIT_FILENAME, i18n("File Name"), false); | 194 | addAction(CRIT_FILENAME, false); | ||
179 | addAction(CRIT_LOCATION, i18n("File Location"), false); | 195 | addAction(CRIT_LOCATION, false); | ||
180 | 196 | | |||
181 | KSelectAction *wsMenu=new KSelectAction(QIcon(itsPixmaps[CRIT_WS]), i18n("Writing System"), this); | 197 | KSelectAction *wsMenu=new KSelectAction(itsIcons[CRIT_WS], itsTexts[CRIT_WS], this); | ||
182 | itsActions[CRIT_WS]=wsMenu; | 198 | itsActions[CRIT_WS]=wsMenu; | ||
183 | itsMenu->addAction(itsActions[CRIT_WS]); | 199 | m_menu->addAction(itsActions[CRIT_WS]); | ||
184 | wsMenu->setData((int)CRIT_WS); | 200 | wsMenu->setData((int)CRIT_WS); | ||
185 | 201 | | |||
186 | itsCurrentWs=QFontDatabase::Any; | 202 | itsCurrentWs=QFontDatabase::Any; | ||
187 | for(int i=QFontDatabase::Latin; i<QFontDatabase::WritingSystemsCount; ++i) | 203 | for(int i=QFontDatabase::Latin; i<QFontDatabase::WritingSystemsCount; ++i) | ||
188 | { | 204 | { | ||
189 | KToggleAction *wsAct=new KToggleAction(QFontDatabase::Other==i | 205 | KToggleAction *wsAct=new KToggleAction(QFontDatabase::Other==i | ||
190 | ? i18n("Symbol/Other") | 206 | ? i18n("Symbol/Other") | ||
191 | : QFontDatabase::writingSystemName((QFontDatabase::WritingSystem)i), this); | 207 | : QFontDatabase::writingSystemName((QFontDatabase::WritingSystem)i), this); | ||
192 | 208 | | |||
193 | wsMenu->addAction(wsAct); | 209 | wsMenu->addAction(wsAct); | ||
194 | wsAct->setChecked(false); | 210 | wsAct->setChecked(false); | ||
195 | wsAct->setData(i); | 211 | wsAct->setData(i); | ||
196 | } | 212 | } | ||
197 | sortActions(wsMenu); | 213 | sortActions(wsMenu); | ||
198 | connect(wsMenu, SIGNAL(triggered(QString)), SLOT(wsChanged(QString))); | 214 | connect(wsMenu, SIGNAL(triggered(QString)), SLOT(wsChanged(QString))); | ||
199 | 215 | | |||
200 | setCriteria(CRIT_FAMILY); | 216 | setCriteria(CRIT_FAMILY); | ||
201 | setStyle(new CFontFilterStyle(this, itsMenuButton->width())); | 217 | setStyle(new CFontFilterStyle(this, m_menuButton->width())); | ||
202 | } | 218 | } | ||
203 | 219 | | |||
204 | void CFontFilter::setFoundries(const QSet<QString> ¤tFoundries) | 220 | void CFontFilter::setFoundries(const QSet<QString> ¤tFoundries) | ||
205 | { | 221 | { | ||
206 | QAction *act(((KSelectAction *)itsActions[CRIT_FOUNDRY])->currentAction()); | 222 | QAction *act(((KSelectAction *)itsActions[CRIT_FOUNDRY])->currentAction()); | ||
207 | QString prev(act && act->isChecked() ? act->text() : QString()); | 223 | QString prev(act && act->isChecked() ? act->text() : QString()); | ||
208 | bool changed(false); | 224 | bool changed(false); | ||
209 | QList<QAction *> prevFoundries(((KSelectAction *)itsActions[CRIT_FOUNDRY])->actions()); | 225 | QList<QAction *> prevFoundries(((KSelectAction *)itsActions[CRIT_FOUNDRY])->actions()); | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 264 | { | |||
252 | else | 268 | else | ||
253 | ((KSelectAction *)itsActions[CRIT_FOUNDRY])->setCurrentItem(0); | 269 | ((KSelectAction *)itsActions[CRIT_FOUNDRY])->setCurrentItem(0); | ||
254 | } | 270 | } | ||
255 | 271 | | |||
256 | itsActions[CRIT_FOUNDRY]->setVisible(((KSelectAction *)itsActions[CRIT_FOUNDRY])->actions().count()); | 272 | itsActions[CRIT_FOUNDRY]->setVisible(((KSelectAction *)itsActions[CRIT_FOUNDRY])->actions().count()); | ||
257 | } | 273 | } | ||
258 | } | 274 | } | ||
259 | 275 | | |||
260 | QSize CFontFilter::sizeHint() const | | |||
261 | { | | |||
262 | return QSize(fontMetrics().width(placeholderText())+56, KLineEdit::sizeHint().height()); | | |||
263 | } | | |||
264 | | ||||
265 | void CFontFilter::filterChanged() | 276 | void CFontFilter::filterChanged() | ||
266 | { | 277 | { | ||
267 | QAction *act(itsActionGroup->checkedAction()); | 278 | QAction *act(itsActionGroup->checkedAction()); | ||
268 | 279 | | |||
269 | if(act) | 280 | if(act) | ||
270 | { | 281 | { | ||
271 | ECriteria crit((ECriteria)act->data().toInt()); | 282 | ECriteria crit((ECriteria)act->data().toInt()); | ||
272 | 283 | | |||
273 | if(itsCurrentCriteria!=crit) | 284 | if(itsCurrentCriteria!=crit) | ||
274 | { | 285 | { | ||
275 | deselectCurrent((KSelectAction *)itsActions[CRIT_FOUNDRY]); | 286 | deselectCurrent((KSelectAction *)itsActions[CRIT_FOUNDRY]); | ||
276 | deselectCurrent((KSelectAction *)itsActions[CRIT_FILETYPE]); | 287 | deselectCurrent((KSelectAction *)itsActions[CRIT_FILETYPE]); | ||
277 | deselectCurrent((KSelectAction *)itsActions[CRIT_WS]); | 288 | deselectCurrent((KSelectAction *)itsActions[CRIT_WS]); | ||
278 | setText(QString()); | 289 | m_lineEdit->setText(QString()); | ||
279 | itsCurrentWs=QFontDatabase::Any; | 290 | itsCurrentWs=QFontDatabase::Any; | ||
280 | itsCurrentFileTypes.clear(); | 291 | itsCurrentFileTypes.clear(); | ||
281 | 292 | | |||
282 | setCriteria(crit); | 293 | setCriteria(crit); | ||
283 | setPlaceholderText(i18n("Filter by %1...", act->text())); | 294 | m_lineEdit->setPlaceholderText(i18n("Filter by %1...", act->text())); | ||
284 | setReadOnly(false); | 295 | m_lineEdit->setReadOnly(false); | ||
285 | } | 296 | } | ||
286 | } | 297 | } | ||
287 | } | 298 | } | ||
288 | 299 | | |||
289 | void CFontFilter::ftChanged(const QString &ft) | 300 | void CFontFilter::ftChanged(const QString &ft) | ||
290 | { | 301 | { | ||
291 | deselectCurrent((KSelectAction *)itsActions[CRIT_FOUNDRY]); | 302 | deselectCurrent((KSelectAction *)itsActions[CRIT_FOUNDRY]); | ||
292 | deselectCurrent((KSelectAction *)itsActions[CRIT_WS]); | 303 | deselectCurrent((KSelectAction *)itsActions[CRIT_WS]); | ||
293 | deselectCurrent(itsActionGroup); | 304 | deselectCurrent(itsActionGroup); | ||
294 | 305 | | |||
295 | QAction *act(((KSelectAction *)itsActions[CRIT_FILETYPE])->currentAction()); | 306 | QAction *act(((KSelectAction *)itsActions[CRIT_FILETYPE])->currentAction()); | ||
296 | 307 | | |||
297 | if(act) | 308 | if(act) | ||
298 | itsCurrentFileTypes=act->data().toStringList(); | 309 | itsCurrentFileTypes=act->data().toStringList(); | ||
299 | itsCurrentCriteria=CRIT_FILETYPE; | 310 | itsCurrentCriteria=CRIT_FILETYPE; | ||
300 | setReadOnly(true); | 311 | m_lineEdit->setReadOnly(true); | ||
301 | setCriteria(itsCurrentCriteria); | 312 | setCriteria(itsCurrentCriteria); | ||
302 | setText(ft); | 313 | m_lineEdit->setText(ft); | ||
303 | setPlaceholderText(text()); | 314 | m_lineEdit->setPlaceholderText(m_lineEdit->text()); | ||
304 | } | 315 | } | ||
305 | 316 | | |||
306 | void CFontFilter::wsChanged(const QString &writingSystemName) | 317 | void CFontFilter::wsChanged(const QString &writingSystemName) | ||
307 | { | 318 | { | ||
308 | deselectCurrent((KSelectAction *)itsActions[CRIT_FOUNDRY]); | 319 | deselectCurrent((KSelectAction *)itsActions[CRIT_FOUNDRY]); | ||
309 | deselectCurrent((KSelectAction *)itsActions[CRIT_FILETYPE]); | 320 | deselectCurrent((KSelectAction *)itsActions[CRIT_FILETYPE]); | ||
310 | deselectCurrent(itsActionGroup); | 321 | deselectCurrent(itsActionGroup); | ||
311 | 322 | | |||
312 | QAction *act(((KSelectAction *)itsActions[CRIT_WS])->currentAction()); | 323 | QAction *act(((KSelectAction *)itsActions[CRIT_WS])->currentAction()); | ||
313 | 324 | | |||
314 | if(act) | 325 | if(act) | ||
315 | itsCurrentWs=(QFontDatabase::WritingSystem)act->data().toInt(); | 326 | itsCurrentWs=(QFontDatabase::WritingSystem)act->data().toInt(); | ||
316 | itsCurrentCriteria=CRIT_WS; | 327 | itsCurrentCriteria=CRIT_WS; | ||
317 | setReadOnly(true); | 328 | m_lineEdit->setReadOnly(true); | ||
318 | setCriteria(itsCurrentCriteria); | 329 | setCriteria(itsCurrentCriteria); | ||
319 | setText(writingSystemName); | 330 | m_lineEdit->setText(writingSystemName); | ||
320 | setPlaceholderText(text()); | 331 | m_lineEdit->setPlaceholderText(m_lineEdit->text()); | ||
321 | } | 332 | } | ||
322 | 333 | | |||
323 | void CFontFilter::foundryChanged(const QString &foundry) | 334 | void CFontFilter::foundryChanged(const QString &foundry) | ||
324 | { | 335 | { | ||
325 | deselectCurrent((KSelectAction *)itsActions[CRIT_WS]); | 336 | deselectCurrent((KSelectAction *)itsActions[CRIT_WS]); | ||
326 | deselectCurrent((KSelectAction *)itsActions[CRIT_FILETYPE]); | 337 | deselectCurrent((KSelectAction *)itsActions[CRIT_FILETYPE]); | ||
327 | deselectCurrent(itsActionGroup); | 338 | deselectCurrent(itsActionGroup); | ||
328 | 339 | | |||
329 | itsCurrentCriteria=CRIT_FOUNDRY; | 340 | itsCurrentCriteria=CRIT_FOUNDRY; | ||
330 | setReadOnly(true); | 341 | m_lineEdit->setReadOnly(true); | ||
331 | setText(foundry); | 342 | m_lineEdit->setText(foundry); | ||
332 | setPlaceholderText(text()); | 343 | m_lineEdit->setPlaceholderText(m_lineEdit->text()); | ||
333 | setCriteria(itsCurrentCriteria); | 344 | setCriteria(itsCurrentCriteria); | ||
334 | } | 345 | } | ||
335 | 346 | | |||
336 | void CFontFilter::addAction(ECriteria crit, const QString &text, bool on) | 347 | void CFontFilter::textChanged(const QString &text) | ||
337 | { | 348 | { | ||
338 | itsActions[crit]=new KToggleAction(QIcon(itsPixmaps[crit]), | 349 | emit queryChanged(text); | ||
339 | text, this); | 350 | } | ||
340 | itsMenu->addAction(itsActions[crit]); | 351 | | ||
352 | void CFontFilter::addAction(ECriteria crit, bool on) | ||||
353 | { | ||||
354 | itsActions[crit]=new KToggleAction(itsIcons[crit], itsTexts[crit], this); | ||||
355 | m_menu->addAction(itsActions[crit]); | ||||
341 | itsActionGroup->addAction(itsActions[crit]); | 356 | itsActionGroup->addAction(itsActions[crit]); | ||
342 | itsActions[crit]->setData((int)crit); | 357 | itsActions[crit]->setData((int)crit); | ||
343 | itsActions[crit]->setChecked(on); | 358 | itsActions[crit]->setChecked(on); | ||
344 | if(on) | 359 | if(on) | ||
345 | setPlaceholderText(i18n("Filter by %1...", text)); | 360 | m_lineEdit->setPlaceholderText(i18n("Filter by %1...", itsTexts[crit])); | ||
346 | connect(itsActions[crit], SIGNAL(toggled(bool)), SLOT(filterChanged())); | 361 | connect(itsActions[crit], SIGNAL(toggled(bool)), SLOT(filterChanged())); | ||
347 | } | 362 | } | ||
348 | 363 | | |||
349 | void CFontFilter::resizeEvent(QResizeEvent *ev) | | |||
350 | { | | |||
351 | KLineEdit::resizeEvent(ev); | | |||
352 | | ||||
353 | int frameWidth(style()->pixelMetric(QStyle::PM_DefaultFrameWidth)), | | |||
354 | y((height()-itsMenuButton->height())/2); | | |||
355 | | ||||
356 | if (qApp->isLeftToRight()) | | |||
357 | itsMenuButton->move(frameWidth + 2, y); | | |||
358 | else | | |||
359 | itsMenuButton->move(size().width() - frameWidth - itsMenuButton->width() - 2, y); | | |||
360 | } | | |||
361 | | ||||
362 | void CFontFilter::mousePressEvent(QMouseEvent *ev) | | |||
363 | { | | |||
364 | if(Qt::LeftButton==ev->button() && itsMenuButton->underMouse()) | | |||
365 | itsMenu->popup(mapToGlobal(QPoint(0, height())), nullptr); | | |||
366 | else | | |||
367 | KLineEdit::mousePressEvent(ev); | | |||
368 | } | | |||
369 | | ||||
370 | void CFontFilter::setCriteria(ECriteria crit) | 364 | void CFontFilter::setCriteria(ECriteria crit) | ||
371 | { | 365 | { | ||
372 | QPixmap arrowmap(itsPixmaps[crit].width()+constArrowPad, itsPixmaps[crit].height()); | 366 | m_menuButton->setIcon(itsIcons[crit]); | ||
373 | | ||||
374 | QColor bgnd(palette().color(QPalette::Active, QPalette::Base)); | | |||
375 | bgnd.setAlphaF(0.0); | | |||
376 | arrowmap.fill(bgnd); | | |||
377 | | ||||
378 | QPainter p(&arrowmap); | | |||
379 | | ||||
380 | p.drawPixmap(0, 0, itsPixmaps[crit]); | | |||
381 | QStyleOption opt; | | |||
382 | opt.state = QStyle::State_Enabled; | | |||
383 | opt.rect = QRect(arrowmap.width()-(constArrowPad+1), arrowmap.height()-(constArrowPad+1), constArrowPad, constArrowPad); | | |||
384 | style()->drawPrimitive(QStyle::PE_IndicatorArrowDown, &opt, &p, itsMenuButton); | | |||
385 | p.end(); | | |||
386 | | ||||
387 | itsMenuButton->setPixmap(arrowmap); | | |||
388 | itsMenuButton->resize(arrowmap.width(), arrowmap.height()); | | |||
389 | itsCurrentCriteria=crit; | 367 | itsCurrentCriteria=crit; | ||
390 | 368 | | |||
391 | emit criteriaChanged(crit, ((qulonglong)1) << (int)itsCurrentWs, itsCurrentFileTypes); | 369 | emit criteriaChanged(crit, ((qulonglong)1) << (int)itsCurrentWs, itsCurrentFileTypes); | ||
392 | } | 370 | } | ||
393 | 371 | | |||
394 | } | 372 | } | ||
395 | 373 | |