Eventviews

todoviewquicksearch.cpp
1/*
2 This file is part of KOrganizer.
3
4 SPDX-FileCopyrightText: 2004 Till Adam <adam@kde.org>
5 SPDX-FileCopyrightText: 2005 Rafal Rzepecki <divide@users.sourceforge.net>
6 SPDX-FileCopyrightText: 2008 Thomas Thrainer <tom_t@gmx.at>
7
8 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
9*/
10
11#include "todoviewquicksearch.h"
12#include <CalendarSupport/KCalPrefs>
13
14#include <Akonadi/TagSelectionComboBox>
15
16#include <Libkdepim/KCheckComboBox>
17
18#include <CalendarSupport/CategoryHierarchyReader>
19
20#include <KCalendarCore/CalFilter>
21
22#include <KLocalizedString>
23#include <QLineEdit>
24
25#include <QHBoxLayout>
26
27TodoViewQuickSearch::TodoViewQuickSearch(QWidget *parent)
28 : QWidget(parent)
29 , mSearchLine(new QLineEdit(this))
30 , mCategoryCombo(new Akonadi::TagSelectionComboBox(this))
31 , mPriorityCombo(new KPIM::KCheckComboBox(this))
32{
33 auto layout = new QHBoxLayout(this);
34 // no special margin because it is added by the view
35 layout->setContentsMargins({});
36
37 mSearchLine->setToolTip(i18nc("@info:tooltip", "Filter on matching summaries"));
38 mSearchLine->setWhatsThis(i18nc("@info:whatsthis", "Enter text here to filter the to-dos that are shown by matching summaries."));
39 mSearchLine->setPlaceholderText(i18nc("@label in QuickSearchLine", "Search Summaries…"));
40 mSearchLine->setClearButtonEnabled(true);
41 connect(mSearchLine, &QLineEdit::textChanged, this, &TodoViewQuickSearch::searchTextChanged);
42
43 layout->addWidget(mSearchLine, 3);
44
45 mCategoryCombo->setCheckable(true);
46 mCategoryCombo->setToolTip(i18nc("@info:tooltip", "Filter on these tags"));
47 mCategoryCombo->setWhatsThis(i18nc("@info:whatsthis",
48 "Use this combobox to filter the to-dos that are shown by "
49 "a list of selected tags."));
50 const QString defaultText = i18nc("@item:inlistbox", "Select Tags");
51 mCategoryCombo->lineEdit()->setPlaceholderText(defaultText);
52
53 connect(mCategoryCombo, &Akonadi::TagSelectionComboBox::selectionChanged, this, [this]() {
54 Q_EMIT filterCategoryChanged(mCategoryCombo->selectionNames());
55 });
56
57 layout->addWidget(mCategoryCombo, 1);
58
59 {
60 // Make the combo big enough so that "Select Categories" fits.
61 QFontMetrics fm = mCategoryCombo->lineEdit()->fontMetrics();
62
63 // QLineEdit::sizeHint() returns a nice size to fit 17 'x' chars.
64 const int currentPreferedWidth = mCategoryCombo->lineEdit()->sizeHint().width();
65
66 // Calculate a nice size for "Select Categories"
67 const int newPreferedWidth = currentPreferedWidth - fm.boundingRect(QLatin1Char('x')).width() * 17 + fm.boundingRect(defaultText).width();
68
69 const int pixelsToAdd = newPreferedWidth - mCategoryCombo->lineEdit()->width();
70 mCategoryCombo->setMinimumWidth(mCategoryCombo->width() + pixelsToAdd);
71 }
72
73 mPriorityCombo->setToolTip(i18nc("@info:tooltip", "Filter on these priorities"));
74 mPriorityCombo->setWhatsThis(i18nc("@info:whatsthis",
75 "Use this combobox to filter the to-dos that are shown by "
76 "a list of selected priorities."));
77 mPriorityCombo->lineEdit()->setPlaceholderText(i18nc("@item:inlistbox", "Select Priority"));
78 connect(mPriorityCombo, &KPIM::KCheckComboBox::checkedItemsChanged, this, [this]() {
79 Q_EMIT filterPriorityChanged(mPriorityCombo->checkedItems(Qt::UserRole));
80 });
81
82 layout->addWidget(mPriorityCombo, 1);
83 fillPriorities();
84}
85
86void TodoViewQuickSearch::reset()
87{
88 mSearchLine->clear();
89 mCategoryCombo->setCurrentIndex(0);
90 mPriorityCombo->setCurrentIndex(0);
91}
92
93void TodoViewQuickSearch::fillPriorities()
94{
95 QStringList priorityValues;
96 priorityValues.append(i18nc("@action:inmenu priority is unspecified", "unspecified"));
97 priorityValues.append(i18nc("@action:inmenu highest priority", "%1 (highest)", 1));
98 for (int p = 2; p < 10; ++p) {
99 if (p == 5) {
100 priorityValues.append(i18nc("@action:inmenu medium priority", "%1 (medium)", p));
101 } else if (p == 9) {
102 priorityValues.append(i18nc("@action:inmenu lowest priority", "%1 (lowest)", p));
103 } else {
104 priorityValues.append(i18nc("@action:inmenu", "%1", p));
105 }
106 }
107 // TODO: Using the same method as for categories to fill mPriorityCombo
108 CalendarSupport::CategoryHierarchyReaderQComboBox(mPriorityCombo).read(priorityValues);
109}
110
111#include "moc_todoviewquicksearch.cpp"
void checkedItemsChanged(const QStringList &items)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setCurrentIndex(int index)
QRect boundingRect(QChar ch) const const
void clear()
void textChanged(const QString &text)
void append(QList< T > &&value)
int width() const const
UserRole
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:56 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.