diff --git a/src/KJotsMain.cpp b/src/KJotsMain.cpp --- a/src/KJotsMain.cpp +++ b/src/KJotsMain.cpp @@ -51,8 +51,6 @@ component = new KJotsWidget(this, this); setCentralWidget(component); - //QT5 statusBar()->insertItem(QString(), 0, 1); - //QT5 statusBar()->setItemAlignment(0, Qt::AlignLeft | Qt::AlignVCenter); connect(component, SIGNAL(activeAnchorChanged(QString,QString)), SLOT(activeAnchorChanged(QString,QString))); @@ -73,9 +71,9 @@ void KJotsMain::activeAnchorChanged(const QString &anchorTarget, const QString &anchorText) { if (!anchorTarget.isEmpty()) { - //QT5 statusBar()->changeItem(anchorText + QLatin1String(" -> ") + anchorTarget, 0); + statusBar()->showMessage(QStringLiteral("%1 -> %2").arg(anchorText, anchorTarget)); } else { - //QT5 statusBar()->changeItem(QString(), 0); + statusBar()->clearMessage(); } } diff --git a/src/akonadi_next/CMakeLists.txt b/src/akonadi_next/CMakeLists.txt --- a/src/akonadi_next/CMakeLists.txt +++ b/src/akonadi_next/CMakeLists.txt @@ -1,5 +1,4 @@ set(akonadi_next_SRCS - note.cpp notecreatorandselector.cpp ) diff --git a/src/akonadi_next/note.h b/src/akonadi_next/note.h deleted file mode 100644 --- a/src/akonadi_next/note.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - Copyright (c) 2009 Stephen Kelly - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library 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 Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef KJOTS_NOTE_H -#define KJOTS_NOTE_H - -#include - -namespace Akonotes -{ - -/** - This is to become a convenience wrapper around KMime::MessageComposer::Ptr. -*/ -class Note -{ -public: - - static QString mimeType(); - -}; - -} - -#endif diff --git a/src/akonadi_next/note.cpp b/src/akonadi_next/note.cpp deleted file mode 100644 --- a/src/akonadi_next/note.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - Copyright (c) 2009 Stephen Kelly - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library 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 Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "note.h" - -using namespace Akonotes; - -QString Note::mimeType() -{ - return QString::fromLatin1( "text/x-vnd.akonadi.note" ); -} - diff --git a/src/kjotsmodel.cpp b/src/kjotsmodel.cpp --- a/src/kjotsmodel.cpp +++ b/src/kjotsmodel.cpp @@ -27,8 +27,8 @@ #include #include +#include -#include "akonadi_next/note.h" #include "noteshared/notelockattribute.h" #include @@ -107,7 +107,7 @@ Collection col = m_index.data(EntityTreeModel::CollectionRole).value(); if (col.isValid()) { - return col.contentMimeTypes().contains(Akonotes::Note::mimeType()); + return col.contentMimeTypes().contains(Akonadi::NoteUtils::noteMimeType()); } return false; } @@ -123,23 +123,22 @@ QVariantList KJotsEntity::entities() const { + const QAbstractItemModel *model = m_index.model(); QVariantList list; int row = 0; const int column = 0; - QModelIndex childIndex = m_index.child(row++, column); + QModelIndex childIndex = model->index(row++, column, m_index); while (childIndex.isValid()) { - QObject *obj = new KJotsEntity(childIndex); + auto obj = new KJotsEntity(childIndex); list << QVariant::fromValue(obj); - childIndex = m_index.child(row++, column); + childIndex = model->index(row++, column, m_index); } return list; } QVariantList KJotsEntity::breadcrumbs() const { QVariantList list; - int row = 0; - const int column = 0; QModelIndex parent = m_index.parent(); while (parent.isValid()) { diff --git a/src/kjotspart.cpp b/src/kjotspart.cpp --- a/src/kjotspart.cpp +++ b/src/kjotspart.cpp @@ -99,9 +99,9 @@ void KJotsPart::activeAnchorChanged(const QString &anchorTarget, const QString &anchorText) { if (!anchorTarget.isEmpty()) { - mStatusBar->statusBar()->showMessage(anchorText + QLatin1String(" -> ") + anchorTarget); + mStatusBar->statusBar()->showMessage(QStringLiteral("%1 -> %2").arg(anchorText, anchorTarget)); } else { - mStatusBar->statusBar()->showMessage(QString()); + mStatusBar->statusBar()->clearMessage(); } } diff --git a/src/kjotswidget.h b/src/kjotswidget.h --- a/src/kjotswidget.h +++ b/src/kjotswidget.h @@ -121,6 +121,7 @@ int search(bool); void migrateNoteData(const QString &migrator, const QString &type = QString()); + std::unique_ptr setupPrinter(QPrinter::PrinterMode mode = QPrinter::ScreenResolution); protected Q_SLOTS: void renderSelection(); void changeTheme(); @@ -172,8 +173,9 @@ void updateConfiguration(); + void print(QPrinter *printer); + private: - void print(QPrinter &printer); KXMLGUIClient *m_xmlGuiClient; KJotsEdit *editor; KJotsBrowser *browser; diff --git a/src/kjotswidget.cpp b/src/kjotswidget.cpp --- a/src/kjotswidget.cpp +++ b/src/kjotswidget.cpp @@ -62,8 +62,8 @@ #include #include #include +#include -#include "akonadi_next/note.h" #include "akonadi_next/notecreatorandselector.h" // Grantlee @@ -157,7 +157,7 @@ monitor->fetchCollection(true); monitor->setItemFetchScope(scope); monitor->setCollectionMonitored(Collection::root()); - monitor->setMimeTypeMonitored(Akonotes::Note::mimeType()); + monitor->setMimeTypeMonitored(Akonadi::NoteUtils::noteMimeType()); m_kjotsModel = new KJotsModel(monitor, this); @@ -330,7 +330,7 @@ connect(browser, &KJotsBrowser::copyAvailable, action, &QAction::setEnabled); action->setEnabled(false); - KStandardAction::pasteText(editor, SLOT(paste()), actionCollection); + KStandardAction::paste(editor, SLOT(paste()), actionCollection); KStandardAction::undo(editor, SLOT(undo()), actionCollection); KStandardAction::redo(editor, SLOT(redo()), actionCollection); @@ -840,7 +840,7 @@ QString title = i18nc("The default name for new books.", "New Book"); newCollection.setName(KRandom::randomString(10)); - newCollection.setContentMimeTypes(QStringList() << Akonadi::Collection::mimeType() << Akonotes::Note::mimeType()); + newCollection.setContentMimeTypes({Akonadi::Collection::mimeType(), Akonadi::NoteUtils::noteMimeType()}); Akonadi::EntityDisplayAttribute *eda = new Akonadi::EntityDisplayAttribute(); eda->setIconName(QLatin1String("x-office-address-book")); @@ -1116,128 +1116,46 @@ m_loader->setTheme(currentTheme); } +std::unique_ptr KJotsWidget::setupPrinter(QPrinter::PrinterMode mode) +{ + auto printer = new QPrinter(mode); + printer->setDocName(QStringLiteral("KJots_Print")); + printer->setCreator(QStringLiteral("KJots")); + if (!activeEditor()->textCursor().selection().isEmpty()) { + printer->setPrintRange(QPrinter::Selection); + } + return std::unique_ptr(printer); +} + void KJotsWidget::printPreviewSelection() { - QPrinter printer(QPrinter::HighResolution); - printer.setDocName(QLatin1String("KJots_Print")); - printer.setFullPage(false); - printer.setCreator(QLatin1String("KJots")); - QPrintPreviewDialog previewdlg(&printer, nullptr); - print(printer); + auto printer = setupPrinter(); + QPrintPreviewDialog previewdlg(printer.get(), nullptr); + connect(&previewdlg, &QPrintPreviewDialog::paintRequested, this, &KJotsWidget::print); previewdlg.exec(); } void KJotsWidget::printSelection() { - - QPrinter printer(QPrinter::HighResolution); - printer.setDocName(QLatin1String("KJots_Print")); - printer.setFullPage(false); - printer.setCreator(QLatin1String("KJots")); - //Not supported in Qt? - //printer->setPageSelection(QPrinter::ApplicationSide); - - //KPrinter::pageList() only works with ApplicationSide. ApplicationSide - //requires min/max pages. How am I supposed to tell how many pages there - //are before I setup the printer? - - QPointer printDialog = new QPrintDialog(&printer, this); - - QAbstractPrintDialog::PrintDialogOptions options = printDialog->enabledOptions(); - options &= ~QAbstractPrintDialog::PrintPageRange; - if (activeEditor()->textCursor().hasSelection()) { - options |= QAbstractPrintDialog::PrintSelection; + auto printer = setupPrinter(QPrinter::HighResolution); + QPrintDialog printDialog(printer.get(), this); + if (printDialog.exec() == QDialog::Accepted) { + print(printer.get()); } - printDialog->setEnabledOptions(options); - - printDialog->setWindowTitle(i18n("Send To Printer")); - if (printDialog->exec() == QDialog::Accepted) { - print(printer); - } - delete printDialog; } -void KJotsWidget::print(QPrinter &printer) +void KJotsWidget::print(QPrinter *printer) { QTextDocument printDocument; - if (printer.printRange() == QPrinter::Selection) { + if (printer->printRange() == QPrinter::Selection) { printDocument.setHtml(activeEditor()->textCursor().selection().toHtml()); } else { - //QTextCursor printCursor ( &printDocument ); QString currentTheme = m_loader->themeName(); m_loader->setTheme(QLatin1String("default")); printDocument.setHtml(renderSelectionToHtml()); m_loader->setTheme(currentTheme); } - - QPainter p(&printer); - - // Check that there is a valid device to print to. - if (p.isActive()) { - QTextDocument *doc = &printDocument; - - QRectF body = QRectF(QPointF(0, 0), doc->pageSize()); - QPointF pageNumberPos; - - QAbstractTextDocumentLayout *layout = doc->documentLayout(); - layout->setPaintDevice(p.device()); - - const int dpiy = p.device()->logicalDpiY(); - - const int margin = (int)((2 / 2.54) * dpiy); // 2 cm margins - QTextFrameFormat fmt = doc->rootFrame()->frameFormat(); - fmt.setMargin(margin); - doc->rootFrame()->setFrameFormat(fmt); - - body = QRectF(0, 0, p.device()->width(), p.device()->height()); - pageNumberPos = QPointF(body.width() - margin, - body.height() - margin - + QFontMetrics(doc->defaultFont(), p.device()).ascent() - + 5 * p.device()->logicalDpiY() / 72); - - doc->setPageSize(body.size()); - - int docCopies = printer.numCopies(); - for (int copy = 0; copy < docCopies; ++copy) { - - int lastPage = layout->pageCount(); - for (int page = 1; page <= lastPage ; ++page) { - p.save(); - p.translate(body.left(), body.top() - (page - 1) * body.height()); - QRectF view(0, (page - 1) * body.height(), body.width(), body.height()); - - QAbstractTextDocumentLayout *layout = doc->documentLayout(); - QAbstractTextDocumentLayout::PaintContext ctx; - - p.setClipRect(view); - ctx.clip = view; - - // don't use the system palette text as default text color, on HP/UX - // for example that's white, and white text on white paper doesn't - // look that nice - ctx.palette.setColor(QPalette::Text, Qt::black); - - layout->draw(&p, ctx); - - if (!pageNumberPos.isNull()) { - p.setClipping(false); - p.setFont(QFont(doc->defaultFont())); - const QString pageString = QString::number(page); - - p.drawText(qRound(pageNumberPos.x() - p.fontMetrics().width(pageString)), - qRound(pageNumberPos.y() + view.top()), - pageString); - } - - p.restore(); - - if ((page + 1) <= lastPage) { - printer.newPage(); - } - } - } - } - + printDocument.print(printer); } void KJotsWidget::selectNext(int role, int step) @@ -1819,7 +1737,7 @@ return; } - KJotsLockJob *job = new KJotsLockJob(collections, items, this); + new KJotsLockJob(collections, items, this); } void KJotsWidget::actionUnlock() @@ -1847,7 +1765,7 @@ return; } - KJotsLockJob *job = new KJotsLockJob(collections, items, KJotsLockJob::UnlockJob, this); + new KJotsLockJob(collections, items, KJotsLockJob::UnlockJob, this); } void KJotsWidget::actionSortChildrenAlpha() diff --git a/src/localresourcecreator.cpp b/src/localresourcecreator.cpp --- a/src/localresourcecreator.cpp +++ b/src/localresourcecreator.cpp @@ -21,8 +21,6 @@ #include "localresourcecreator.h" -#include "akonadi_next/note.h" - #include #include @@ -35,6 +33,7 @@ #include #include #include +#include #include @@ -112,7 +111,7 @@ collection.setParentCollection(Akonadi::Collection(id)); QString title = i18nc("The default name for new books.", "New Book"); collection.setName(KRandom::randomString(10)); - collection.setContentMimeTypes(QStringList() << Akonadi::Collection::mimeType() << Akonotes::Note::mimeType()); + collection.setContentMimeTypes({Akonadi::Collection::mimeType(), Akonadi::NoteUtils::noteMimeType()}); Akonadi::EntityDisplayAttribute *eda = new Akonadi::EntityDisplayAttribute(); eda->setIconName(QLatin1String("x-office-address-book")); @@ -140,7 +139,7 @@ Akonadi::Item item; item.setParentCollection(collectionCreateJob->collection()); - item.setMimeType(Akonotes::Note::mimeType()); + item.setMimeType(Akonadi::NoteUtils::noteMimeType()); KMime::Message::Ptr note(new KMime::Message());