diff --git a/src/presentation/errorhandler.cpp b/src/presentation/errorhandler.cpp index d33b88ee..9ef6cd6e 100644 --- a/src/presentation/errorhandler.cpp +++ b/src/presentation/errorhandler.cpp @@ -1,49 +1,50 @@ /* This file is part of Zanshin Copyright 2014 Mario Bensi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "errorhandler.h" +#include #include #include "utils/jobhandler.h" #include "utils/mem_fn.h" using namespace Presentation; ErrorHandler::~ErrorHandler() { } void ErrorHandler::installHandler(KJob *job, const QString &message) { auto resultHandler = std::function(std::bind(Utils::mem_fn(&ErrorHandler::displayMessage), this, job, message)); Utils::JobHandler::install(job, resultHandler); } void ErrorHandler::displayMessage(KJob *job, const QString &message) { if (job->error() != KJob::NoError) { - doDisplayMessage(QStringLiteral("%1: %2").arg(message, job->errorString())); + doDisplayMessage(QCoreApplication::translate("ErrorHandler", "%1: %2").arg(message, job->errorString())); } } diff --git a/src/widgets/applicationcomponents.cpp b/src/widgets/applicationcomponents.cpp index 27e15f73..e7204089 100644 --- a/src/widgets/applicationcomponents.cpp +++ b/src/widgets/applicationcomponents.cpp @@ -1,257 +1,257 @@ /* This file is part of Zanshin Copyright 2014 Kevin Ottens This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "applicationcomponents.h" #include #include #include #include #include #include "availablepagesview.h" #include "availablesourcesview.h" #include "editorview.h" #include "pageview.h" #include "quickselectdialog.h" using namespace Widgets; ApplicationComponents::ApplicationComponents(QWidget *parent) : QObject(parent), m_parent(parent), m_availableSourcesView(Q_NULLPTR), m_availablePagesView(Q_NULLPTR), m_pageView(Q_NULLPTR), m_editorView(Q_NULLPTR) { m_quickSelectDialogFactory = [] (QWidget *parent) { return QuickSelectDialogPtr(new QuickSelectDialog(parent)); }; auto moveItemAction = new QAction(this); moveItemAction->setObjectName(QStringLiteral("moveItemAction")); - moveItemAction->setText("Move item"); + moveItemAction->setText(tr("Move item")); moveItemAction->setShortcut(Qt::Key_M); connect(moveItemAction, &QAction::triggered, this, &ApplicationComponents::onMoveItemsRequested); m_actions.insert(QStringLiteral("page_view_move"), moveItemAction); } ApplicationComponents::~ApplicationComponents() { setModel({}); } QHash ApplicationComponents::globalActions() const { auto actions = QHash(); actions.unite(availableSourcesView()->globalActions()); actions.unite(availablePagesView()->globalActions()); actions.unite(pageView()->globalActions()); actions.unite(m_actions); return actions; } QObjectPtr ApplicationComponents::model() const { return m_model; } AvailableSourcesView *ApplicationComponents::availableSourcesView() const { if (!m_availableSourcesView) { auto availableSourcesView = new AvailableSourcesView(m_parent); if (m_model) { availableSourcesView->setModel(m_model->property("availableSources").value()); } ApplicationComponents *self = const_cast(this); self->m_availableSourcesView = availableSourcesView; } return m_availableSourcesView; } AvailablePagesView *ApplicationComponents::availablePagesView() const { if (!m_availablePagesView) { auto availablePagesView = new AvailablePagesView(m_parent); if (m_model) { availablePagesView->setModel(m_model->property("availablePages").value()); auto availableSources = m_model->property("availableSources").value(); if (availableSources) availablePagesView->setProjectSourcesModel(availableSources->property("sourceListModel").value()); } ApplicationComponents *self = const_cast(this); self->m_availablePagesView = availablePagesView; connect(self->m_availablePagesView, &AvailablePagesView::currentPageChanged, self, &ApplicationComponents::onCurrentPageChanged); } return m_availablePagesView; } PageView *ApplicationComponents::pageView() const { if (!m_pageView) { auto pageView = new PageView(m_parent); if (m_model) { pageView->setModel(m_model->property("currentPage").value()); connect(m_model.data(), SIGNAL(currentPageChanged(QObject*)), pageView, SLOT(setModel(QObject*))); } ApplicationComponents *self = const_cast(this); self->m_pageView = pageView; connect(self->m_pageView, &PageView::currentArtifactChanged, self, &ApplicationComponents::onCurrentArtifactChanged); } return m_pageView; } EditorView *ApplicationComponents::editorView() const { if (!m_editorView) { auto editorView = new EditorView(m_parent); if (m_model) { editorView->setModel(m_model->property("editor").value()); } auto self = const_cast(this); self->m_editorView = editorView; } return m_editorView; } ApplicationComponents::QuickSelectDialogFactory ApplicationComponents::quickSelectDialogFactory() const { return m_quickSelectDialogFactory; } void ApplicationComponents::setModel(const QObjectPtr &model) { if (m_model == model) return; if (m_model && m_pageView) { disconnect(m_model.data(), 0, m_pageView, 0); } // Delay deletion of the old model until we're out of scope auto tmp = m_model; Q_UNUSED(tmp); m_model = model; if (m_availableSourcesView) { m_availableSourcesView->setModel(m_model ? m_model->property("availableSources").value() : Q_NULLPTR); } if (m_availablePagesView) { m_availablePagesView->setModel(m_model ? m_model->property("availablePages").value() : Q_NULLPTR); m_availablePagesView->setProjectSourcesModel(m_model ? m_model->property("dataSourcesModel").value() : Q_NULLPTR); } if (m_pageView) { m_pageView->setModel(m_model ? m_model->property("currentPage").value() : Q_NULLPTR); if (m_model) { connect(m_model.data(), SIGNAL(currentPageChanged(QObject*)), m_pageView, SLOT(setModel(QObject*))); } } if (m_editorView) { m_editorView->setModel(m_model ? m_model->property("editor").value() : Q_NULLPTR); } } void ApplicationComponents::setQuickSelectDialogFactory(const QuickSelectDialogFactory &factory) { m_quickSelectDialogFactory = factory; } void ApplicationComponents::onCurrentPageChanged(QObject *page) { if (!m_model) return; m_model->setProperty("currentPage", QVariant::fromValue(page)); QObject *editorModel = m_model->property("editor").value(); if (editorModel) editorModel->setProperty("artifact", QVariant::fromValue(Domain::Artifact::Ptr())); } void ApplicationComponents::onCurrentArtifactChanged(const Domain::Artifact::Ptr &artifact) { if (!m_model) return; auto editorModel = m_model->property("editor").value(); if (editorModel) editorModel->setProperty("artifact", QVariant::fromValue(artifact)); } void ApplicationComponents::onMoveItemsRequested() { if (!m_model) return; if (m_pageView->selectedIndexes().size() == 0) return; auto pageListModel = m_availablePagesView->model()->property("pageListModel").value(); Q_ASSERT(pageListModel); QuickSelectDialogInterface::Ptr dlg = m_quickSelectDialogFactory(m_pageView); dlg->setModel(pageListModel); if (dlg->exec() == QDialog::Accepted) moveItems(dlg->selectedIndex(), m_pageView->selectedIndexes()); } void ApplicationComponents::moveItems(const QModelIndex &destination, const QModelIndexList &droppedItems) { Q_ASSERT(destination.isValid()); Q_ASSERT(!droppedItems.isEmpty()); auto centralListModel = droppedItems.first().model(); auto availablePagesModel = const_cast(destination.model()); // drag const auto data = centralListModel->mimeData(droppedItems); // drop availablePagesModel->dropMimeData(data, Qt::MoveAction, -1, -1, destination); } diff --git a/src/widgets/itemdelegate.cpp b/src/widgets/itemdelegate.cpp index 155b1238..48e99335 100644 --- a/src/widgets/itemdelegate.cpp +++ b/src/widgets/itemdelegate.cpp @@ -1,108 +1,108 @@ /* This file is part of Zanshin Copyright 2014 Kevin Ottens This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "itemdelegate.h" #include #include #include "domain/note.h" #include "domain/task.h" #include "presentation/querytreemodelbase.h" using namespace Widgets; ItemDelegate::ItemDelegate(QObject *parent) : QStyledItemDelegate(parent) { } QSize ItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { // Make sure they all get the height needed for a check indicator QStyleOptionViewItemV4 opt = option; opt.features = QStyleOptionViewItemV4::HasCheckIndicator; QSize res = QStyledItemDelegate::sizeHint(opt, index); return res; } void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItemV4 opt = option; initStyleOption(&opt, index); Domain::Task::Ptr task; Domain::Note::Ptr note; QVariant data = index.data(Presentation::QueryTreeModelBase::ObjectRole); auto artifact = data.value(); if (artifact) { task = artifact.dynamicCast(); note = artifact.dynamicCast(); } else { task = data.value(); note = data.value(); } if (task) { if (task->isDone()) { opt.font.setStrikeOut(true); } else { if (task->startDate().isValid() && task->startDate().date() <= QDate::currentDate()) { opt.font.setBold(true); } if (task->dueDate().isValid()) { if (task->dueDate().date() < QDate::currentDate()) { opt.font.setBold(true); opt.palette.setColor(QPalette::Text, QColor(Qt::red)); opt.palette.setColor(QPalette::HighlightedText, QColor(Qt::red)); } else if (task->dueDate().date() == QDate::currentDate()) { opt.font.setBold(true); opt.palette.setColor(QPalette::Text, QColor("orange")); opt.palette.setColor(QPalette::HighlightedText, QColor("orange")); } } } if (task->delegate().isValid()) { - opt.text = QStringLiteral("(%1) %2").arg(task->delegate().display(), opt.text); + opt.text = tr("(%1) %2").arg(task->delegate().display(), opt.text); opt.font.setItalic(true); } } if (note) { opt.features |= QStyleOptionViewItemV4::HasDecoration; opt.icon = QIcon::fromTheme(QStringLiteral("text-plain")); } const QWidget *widget = opt.widget; QStyle *style = widget ? widget->style() : QApplication::style(); style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget); } diff --git a/src/widgets/quickselectdialog.cpp b/src/widgets/quickselectdialog.cpp index b5539f66..20a697b1 100644 --- a/src/widgets/quickselectdialog.cpp +++ b/src/widgets/quickselectdialog.cpp @@ -1,128 +1,128 @@ /* This file is part of Zanshin Copyright 2014 Kevin Ottens Copyright 2015 Franck Arrecot This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "quickselectdialog.h" #include #include #include #include #include #include #include #include using namespace Widgets; QuickSelectDialog::QuickSelectDialog(QWidget *parent) : QDialog(parent), m_model(Q_NULLPTR), m_filterProxyModel(new KRecursiveFilterProxyModel(this)), m_label(new QLabel(this)), m_tree(new QTreeView(this)) { - setWindowTitle("Quick Select Dialog"); + setWindowTitle(tr("Quick Select Dialog")); m_label->setText(tr("You can start typing to filter the list of available pages")); m_filterProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); m_tree->setModel(m_filterProxyModel); m_tree->setObjectName(QStringLiteral("pagesView")); m_tree->header()->hide(); m_tree->expandAll(); m_tree->setFocus(); m_tree->setSelectionMode(QAbstractItemView::SingleSelection); m_tree->setSortingEnabled(false); m_tree->installEventFilter(this); auto buttonBox = new QDialogButtonBox(this); buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); auto mainLayout = new QVBoxLayout(this); mainLayout->addWidget(m_label); mainLayout->addWidget(m_tree); mainLayout->addWidget(buttonBox); connect(buttonBox, &QDialogButtonBox::accepted, this, &QuickSelectDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, this, &QuickSelectDialog::reject); } int QuickSelectDialog::exec() { return QDialog::exec(); } QPersistentModelIndex QuickSelectDialog::selectedIndex() const { QModelIndex selected = m_tree->currentIndex(); return m_filterProxyModel->mapToSource(selected); } void QuickSelectDialog::applyFilterChanged(const QString &textFilter) { if (textFilter.isEmpty()) m_label->setText(tr("You can start typing to filter the list of available pages")); else - m_label->setText(QString("Path: %1").arg(textFilter)); + m_label->setText(tr("Path: %1").arg(textFilter)); m_filterProxyModel->setFilterFixedString(textFilter); m_tree->expandAll(); } bool QuickSelectDialog::eventFilter(QObject *, QEvent *ev) { if (ev->type() == QEvent::KeyPress) { auto event = static_cast(ev); auto filter = m_filterProxyModel->filterRegExp().pattern(); switch (event->key()) { case Qt::Key_Backspace: filter.chop(1); break; case Qt::Key_Delete: filter = QString(); break; default: if (event->text().contains(QRegExp("^(\\w| )+$"))) { filter += event->text(); } break; } applyFilterChanged(filter); } return false; } void QuickSelectDialog::setModel(QAbstractItemModel *model) { if (model == m_model) return; m_model = model; m_filterProxyModel->setSourceModel(m_model); m_tree->expandAll(); }