Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/pageview.cpp
Show All 28 Lines | |||||
29 | #include <QHeaderView> | 29 | #include <QHeaderView> | ||
30 | #include <QLabel> | 30 | #include <QLabel> | ||
31 | #include <QLineEdit> | 31 | #include <QLineEdit> | ||
32 | #include <QTreeView> | 32 | #include <QTreeView> | ||
33 | #include <QVBoxLayout> | 33 | #include <QVBoxLayout> | ||
34 | #include <QMessageBox> | 34 | #include <QMessageBox> | ||
35 | #include <QTimer> | 35 | #include <QTimer> | ||
36 | 36 | | |||
37 | #include <KLocalizedString> | ||||
37 | #include <KMessageWidget> | 38 | #include <KMessageWidget> | ||
38 | 39 | | |||
39 | #include "filterwidget.h" | 40 | #include "filterwidget.h" | ||
40 | #include "itemdelegate.h" | 41 | #include "itemdelegate.h" | ||
41 | #include "messagebox.h" | 42 | #include "messagebox.h" | ||
42 | 43 | | |||
43 | #include <algorithm> | 44 | #include <algorithm> | ||
44 | 45 | | |||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Line(s) | 127 | { | |||
145 | m_centralView->setItemsExpandable(false); | 146 | m_centralView->setItemsExpandable(false); | ||
146 | m_centralView->setRootIsDecorated(false); | 147 | m_centralView->setRootIsDecorated(false); | ||
147 | connect(m_centralView->model(), &QAbstractItemModel::rowsInserted, m_centralView, &QTreeView::expandAll); | 148 | connect(m_centralView->model(), &QAbstractItemModel::rowsInserted, m_centralView, &QTreeView::expandAll); | ||
148 | connect(m_centralView->model(), &QAbstractItemModel::layoutChanged, m_centralView, &QTreeView::expandAll); | 149 | connect(m_centralView->model(), &QAbstractItemModel::layoutChanged, m_centralView, &QTreeView::expandAll); | ||
149 | connect(m_centralView->model(), &QAbstractItemModel::modelReset, m_centralView, &QTreeView::expandAll); | 150 | connect(m_centralView->model(), &QAbstractItemModel::modelReset, m_centralView, &QTreeView::expandAll); | ||
150 | m_centralView->setStyleSheet(QStringLiteral("QTreeView::branch { border-image: url(none.png); }")); | 151 | m_centralView->setStyleSheet(QStringLiteral("QTreeView::branch { border-image: url(none.png); }")); | ||
151 | 152 | | |||
152 | m_quickAddEdit->setObjectName(QStringLiteral("quickAddEdit")); | 153 | m_quickAddEdit->setObjectName(QStringLiteral("quickAddEdit")); | ||
153 | m_quickAddEdit->setPlaceholderText(tr("Type and press enter to add an item")); | 154 | m_quickAddEdit->setPlaceholderText(i18n("Type and press enter to add an item")); | ||
154 | connect(m_quickAddEdit, &QLineEdit::returnPressed, this, &PageView::onReturnPressed); | 155 | connect(m_quickAddEdit, &QLineEdit::returnPressed, this, &PageView::onReturnPressed); | ||
155 | 156 | | |||
156 | auto layout = new QVBoxLayout; | 157 | auto layout = new QVBoxLayout; | ||
157 | layout->setContentsMargins(0, 0, 0, 3); | 158 | layout->setContentsMargins(0, 0, 0, 3); | ||
158 | layout->addWidget(m_messageWidget); | 159 | layout->addWidget(m_messageWidget); | ||
159 | layout->addWidget(m_filterWidget); | 160 | layout->addWidget(m_filterWidget); | ||
160 | layout->addWidget(m_centralView); | 161 | layout->addWidget(m_centralView); | ||
161 | layout->addWidget(m_quickAddEdit); | 162 | layout->addWidget(m_quickAddEdit); | ||
162 | setLayout(layout); | 163 | setLayout(layout); | ||
163 | 164 | | |||
164 | m_messageBoxInterface = MessageBox::Ptr::create(); | 165 | m_messageBoxInterface = MessageBox::Ptr::create(); | ||
165 | 166 | | |||
166 | auto addItemAction = new QAction(this); | 167 | auto addItemAction = new QAction(this); | ||
167 | addItemAction->setObjectName(QStringLiteral("addItemAction")); | 168 | addItemAction->setObjectName(QStringLiteral("addItemAction")); | ||
168 | addItemAction->setText(tr("New Item")); | 169 | addItemAction->setText(i18n("New Item")); | ||
169 | addItemAction->setIcon(QIcon::fromTheme(QStringLiteral("list-add"))); | 170 | addItemAction->setIcon(QIcon::fromTheme(QStringLiteral("list-add"))); | ||
170 | addItemAction->setShortcut(Qt::CTRL | Qt::Key_N); | 171 | addItemAction->setShortcut(Qt::CTRL | Qt::Key_N); | ||
171 | connect(addItemAction, &QAction::triggered, this, &PageView::onAddItemRequested); | 172 | connect(addItemAction, &QAction::triggered, this, &PageView::onAddItemRequested); | ||
172 | 173 | | |||
173 | m_cancelAction->setObjectName(QStringLiteral("cancelAddItemAction")); | 174 | m_cancelAction->setObjectName(QStringLiteral("cancelAddItemAction")); | ||
174 | m_cancelAction->setShortcut(Qt::Key_Escape); | 175 | m_cancelAction->setShortcut(Qt::Key_Escape); | ||
175 | addAction(m_cancelAction); | 176 | addAction(m_cancelAction); | ||
176 | connect(m_cancelAction, &QAction::triggered, | 177 | connect(m_cancelAction, &QAction::triggered, | ||
177 | m_centralView, static_cast<void(QWidget::*)()>(&QWidget::setFocus)); | 178 | m_centralView, static_cast<void(QWidget::*)()>(&QWidget::setFocus)); | ||
178 | 179 | | |||
179 | auto removeItemAction = new QAction(this); | 180 | auto removeItemAction = new QAction(this); | ||
180 | removeItemAction->setObjectName(QStringLiteral("removeItemAction")); | 181 | removeItemAction->setObjectName(QStringLiteral("removeItemAction")); | ||
181 | removeItemAction->setText(tr("Remove Item")); | 182 | removeItemAction->setText(i18n("Remove Item")); | ||
182 | removeItemAction->setIcon(QIcon::fromTheme(QStringLiteral("list-remove"))); | 183 | removeItemAction->setIcon(QIcon::fromTheme(QStringLiteral("list-remove"))); | ||
183 | removeItemAction->setShortcut(Qt::Key_Delete); | 184 | removeItemAction->setShortcut(Qt::Key_Delete); | ||
184 | connect(removeItemAction, &QAction::triggered, this, &PageView::onRemoveItemRequested); | 185 | connect(removeItemAction, &QAction::triggered, this, &PageView::onRemoveItemRequested); | ||
185 | addAction(removeItemAction); | 186 | addAction(removeItemAction); | ||
186 | 187 | | |||
187 | auto promoteItemAction = new QAction(this); | 188 | auto promoteItemAction = new QAction(this); | ||
188 | promoteItemAction->setObjectName(QStringLiteral("promoteItemAction")); | 189 | promoteItemAction->setObjectName(QStringLiteral("promoteItemAction")); | ||
189 | promoteItemAction->setText(tr("Promote Item as Project")); | 190 | promoteItemAction->setText(i18n("Promote Item as Project")); | ||
190 | promoteItemAction->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_P); | 191 | promoteItemAction->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_P); | ||
191 | connect(promoteItemAction, &QAction::triggered, this, &PageView::onPromoteItemRequested); | 192 | connect(promoteItemAction, &QAction::triggered, this, &PageView::onPromoteItemRequested); | ||
192 | 193 | | |||
193 | auto filterViewAction = new QAction(this); | 194 | auto filterViewAction = new QAction(this); | ||
194 | filterViewAction->setObjectName(QStringLiteral("filterViewAction")); | 195 | filterViewAction->setObjectName(QStringLiteral("filterViewAction")); | ||
195 | filterViewAction->setText(tr("Filter...")); | 196 | filterViewAction->setText(i18n("Filter...")); | ||
196 | filterViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-find"))); | 197 | filterViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-find"))); | ||
197 | filterViewAction->setShortcut(Qt::CTRL | Qt::Key_F); | 198 | filterViewAction->setShortcut(Qt::CTRL | Qt::Key_F); | ||
198 | filterViewAction->setCheckable(true); | 199 | filterViewAction->setCheckable(true); | ||
199 | connect(filterViewAction, &QAction::triggered, this, &PageView::onFilterToggled); | 200 | connect(filterViewAction, &QAction::triggered, this, &PageView::onFilterToggled); | ||
200 | 201 | | |||
201 | m_runTaskAction = new QAction(this); | 202 | m_runTaskAction = new QAction(this); | ||
202 | m_runTaskAction->setObjectName(QStringLiteral("runTaskAction")); | 203 | m_runTaskAction->setObjectName(QStringLiteral("runTaskAction")); | ||
203 | m_runTaskAction->setShortcut(Qt::CTRL | Qt::Key_Space); | 204 | m_runTaskAction->setShortcut(Qt::CTRL | Qt::Key_Space); | ||
204 | m_runTaskAction->setText(tr("Start Now")); | 205 | m_runTaskAction->setText(i18n("Start Now")); | ||
205 | m_runTaskAction->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-start"))); | 206 | m_runTaskAction->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-start"))); | ||
206 | connect(m_runTaskAction, &QAction::triggered, this, &PageView::onRunTaskTriggered); | 207 | connect(m_runTaskAction, &QAction::triggered, this, &PageView::onRunTaskTriggered); | ||
207 | updateRunTaskAction(); | 208 | updateRunTaskAction(); | ||
208 | 209 | | |||
209 | m_actions.insert(QStringLiteral("page_view_add"), addItemAction); | 210 | m_actions.insert(QStringLiteral("page_view_add"), addItemAction); | ||
210 | m_actions.insert(QStringLiteral("page_view_remove"), removeItemAction); | 211 | m_actions.insert(QStringLiteral("page_view_remove"), removeItemAction); | ||
211 | m_actions.insert(QStringLiteral("page_view_promote"), promoteItemAction); | 212 | m_actions.insert(QStringLiteral("page_view_promote"), promoteItemAction); | ||
212 | m_actions.insert(QStringLiteral("page_view_filter"), filterViewAction); | 213 | m_actions.insert(QStringLiteral("page_view_filter"), filterViewAction); | ||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | |||||
310 | void PageView::onAddItemRequested() | 311 | void PageView::onAddItemRequested() | ||
311 | { | 312 | { | ||
312 | if (m_quickAddEdit->hasFocus()) | 313 | if (m_quickAddEdit->hasFocus()) | ||
313 | return; | 314 | return; | ||
314 | 315 | | |||
315 | const auto editTopLeft = m_quickAddEdit->geometry().topLeft(); | 316 | const auto editTopLeft = m_quickAddEdit->geometry().topLeft(); | ||
316 | const auto pos = mapToGlobal(editTopLeft); | 317 | const auto pos = mapToGlobal(editTopLeft); | ||
317 | auto popup = new PassivePopup(m_quickAddEdit); | 318 | auto popup = new PassivePopup(m_quickAddEdit); | ||
318 | popup->setText(tr("Type and press enter to add an item")); | 319 | popup->setText(i18n("Type and press enter to add an item")); | ||
319 | popup->show(); | 320 | popup->show(); | ||
320 | popup->move(pos - QPoint(0, popup->height())); | 321 | popup->move(pos - QPoint(0, popup->height())); | ||
321 | 322 | | |||
322 | m_quickAddEdit->selectAll(); | 323 | m_quickAddEdit->selectAll(); | ||
323 | m_quickAddEdit->setFocus(); | 324 | m_quickAddEdit->setFocus(); | ||
324 | } | 325 | } | ||
325 | 326 | | |||
326 | void PageView::onRemoveItemRequested() | 327 | void PageView::onRemoveItemRequested() | ||
Show All 11 Lines | 336 | foreach (const QModelIndex ¤tIndex, currentIndexes) { | |||
338 | 339 | | |||
339 | if (currentIndex.model()->rowCount(currentIndex) > 0) { | 340 | if (currentIndex.model()->rowCount(currentIndex) > 0) { | ||
340 | hasDescendants = true; | 341 | hasDescendants = true; | ||
341 | break; | 342 | break; | ||
342 | } | 343 | } | ||
343 | } | 344 | } | ||
344 | 345 | | |||
345 | if (hasDescendants) | 346 | if (hasDescendants) | ||
346 | text = tr("Do you really want to delete the selected items and their children?"); | 347 | text = i18n("Do you really want to delete the selected items and their children?"); | ||
347 | else | 348 | else | ||
348 | text = tr("Do you really want to delete the selected items?"); | 349 | text = i18n("Do you really want to delete the selected items?"); | ||
349 | 350 | | |||
350 | } else { | 351 | } else { | ||
351 | const QModelIndex ¤tIndex = currentIndexes.first(); | 352 | const QModelIndex ¤tIndex = currentIndexes.first(); | ||
352 | if (!currentIndex.isValid()) | 353 | if (!currentIndex.isValid()) | ||
353 | return; | 354 | return; | ||
354 | 355 | | |||
355 | if (currentIndex.model()->rowCount(currentIndex) > 0) | 356 | if (currentIndex.model()->rowCount(currentIndex) > 0) | ||
356 | text = tr("Do you really want to delete the selected task and all its children?"); | 357 | text = i18n("Do you really want to delete the selected task and all its children?"); | ||
357 | } | 358 | } | ||
358 | 359 | | |||
359 | if (!text.isEmpty()) { | 360 | if (!text.isEmpty()) { | ||
360 | QMessageBox::Button button = m_messageBoxInterface->askConfirmation(this, tr("Delete Tasks"), text); | 361 | QMessageBox::Button button = m_messageBoxInterface->askConfirmation(this, i18n("Delete Tasks"), text); | ||
361 | bool canRemove = (button == QMessageBox::Yes); | 362 | bool canRemove = (button == QMessageBox::Yes); | ||
362 | 363 | | |||
363 | if (!canRemove) | 364 | if (!canRemove) | ||
364 | return; | 365 | return; | ||
365 | } | 366 | } | ||
366 | 367 | | |||
367 | foreach (const QModelIndex ¤tIndex, currentIndexes) { | 368 | foreach (const QModelIndex ¤tIndex, currentIndexes) { | ||
368 | if (!currentIndex.isValid()) | 369 | if (!currentIndex.isValid()) | ||
▲ Show 20 Lines • Show All 97 Lines • Show Last 20 Lines |