diff --git a/CMakeLists.txt b/CMakeLists.txt index 17ddbe5..6d92c6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,127 +1,127 @@ set(KDEPIM_VERSION_NUMBER "5.11.40") cmake_minimum_required(VERSION 3.5) project(knotes VERSION ${KDEPIM_VERSION_NUMBER}) set(KF5_MIN_VERSION "5.58.0") find_package(ECM ${KF5_MIN_VERSION} CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${knotes_SOURCE_DIR}/cmake/modules ${ECM_MODULE_PATH}) include(ECMInstallIcons) include(ECMSetupVersion) include(ECMAddTests) include(GenerateExportHeader) include(ECMGenerateHeaders) include(FeatureSummary) include(CheckFunctionExists) include(ECMGeneratePriFile) include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(ECMAddAppIcon) include(ECMQtDeclareLoggingCategory) # Do NOT add quote set(KDEPIM_DEV_VERSION alpha) # add an extra space if(DEFINED KDEPIM_DEV_VERSION) set(KDEPIM_DEV_VERSION " ${KDEPIM_DEV_VERSION}") endif() set(KDEPIM_VERSION "${KDEPIM_VERSION_NUMBER}${KDEPIM_DEV_VERSION}") set(KDEPIM_LIB_VERSION "${KDEPIM_VERSION_NUMBER}") set(KDEPIM_LIB_SOVERSION "5") set(AKONADINOTES_LIB_VERSION "5.11.40") set(AKONADI_VERSION "5.11.40") set(CALENDARUTILS_LIB_VERSION "5.11.40") set(KDEPIM_APPS_LIB_VERSION "5.11.40") set(KONTACTINTERFACE_LIB_VERSION "5.11.40") set(KPIMTEXTEDIT_LIB_VERSION "5.11.40") set(LIBKDEPIM_LIB_VERSION "5.11.40") set(KMIME_LIB_VERSION "5.11.40") set(PIMCOMMON_LIB_VERSION "5.11.40") set(GRANTLEETHEME_LIB_VERSION "5.11.41") set(QT_REQUIRED_VERSION "5.10.0") find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED DBus Network PrintSupport Test Widgets Xml) find_package(Qt5X11Extras NO_MODULE) find_package(Grantlee5 "5.1" CONFIG REQUIRED) # Find KF5 package find_package(KF5Completion ${KF5_MIN_VERSION} REQUIRED) find_package(KF5Config ${KF5_MIN_VERSION} REQUIRED) find_package(KF5ConfigWidgets ${KF5_MIN_VERSION} REQUIRED) find_package(KF5CoreAddons ${KF5_MIN_VERSION} REQUIRED) find_package(KF5Crash ${KF5_MIN_VERSION} REQUIRED) find_package(KF5DBusAddons ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5DNSSD ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5DocTools ${KF5_MIN_VERSION} REQUIRED) find_package(KF5GlobalAccel ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5IconThemes ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5ItemModels ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5ItemViews ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5KCMUtils ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5NewStuff ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Notifications ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5NotifyConfig ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Parts ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5TextWidgets ${KF5_MIN_VERSION} REQUIRED) find_package(KF5WidgetsAddons ${KF5_MIN_VERSION} REQUIRED) find_package(KF5WindowSystem ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5XmlGui ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Notifications ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5KDELibs4Support ${KF5_MIN_VERSION} CONFIG REQUIRED) # Find KdepimLibs Package find_package(KF5Akonadi ${AKONADI_VERSION} CONFIG REQUIRED) find_package(KF5AkonadiNotes ${AKONADINOTES_LIB_VERSION} CONFIG REQUIRED) find_package(KF5CalendarUtils ${CALENDARUTILS_LIB_VERSION} CONFIG REQUIRED) find_package(KF5KontactInterface ${KONTACTINTERFACE_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Libkdepim ${LIBKDEPIM_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Mime ${KMIME_LIB_VERSION} CONFIG REQUIRED) find_package(KF5PimCommonAkonadi ${PIMCOMMON_LIB_VERSION} CONFIG REQUIRED) find_package(KF5PimTextEdit ${KPIMTEXTEDIT_LIB_VERSION} CONFIG REQUIRED) find_package(KF5GrantleeTheme ${GRANTLEETHEME_LIB_VERSION} CONFIG REQUIRED) find_package(KF5AkonadiSearch "5.11.40" CONFIG REQUIRED) set_package_properties(KF5AkonadiSearch PROPERTIES DESCRIPTION "The Akonadi Search libraries" URL "http://www.kde.org" TYPE REQUIRED PURPOSE "Provides search capabilities in KMail and Akonadi") if (NOT APPLE) find_package(X11) endif() set(KDEPIM_HAVE_X11 ${X11_FOUND}) set(CMAKE_MODULE_PATH ${knotes_SOURCE_DIR}/cmake/modules ${ECM_MODULE_PATH}) find_package(Xsltproc) set_package_properties(Xsltproc PROPERTIES DESCRIPTION "XSLT processor from libxslt" TYPE REQUIRED PURPOSE "Required to generate D-Bus interfaces for all Akonadi resources.") include_directories(${knotes_SOURCE_DIR} ${knotes_BINARY_DIR}) -#add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) +add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) add_definitions(-DQT_NO_FOREACH) set(CMAKE_CXX_STANDARD 14) configure_file(knotes-version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/knotes-version.h @ONLY) add_subdirectory(noteshared) add_subdirectory(src) add_subdirectory(notesagent) install( FILES knotes.categories knotes.renamecategories DESTINATION ${KDE_INSTALL_CONFDIR} ) add_subdirectory(doc) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/notesagent/notesmanager.cpp b/notesagent/notesmanager.cpp index 20a5b04..5eed7cc 100644 --- a/notesagent/notesmanager.cpp +++ b/notesagent/notesmanager.cpp @@ -1,222 +1,222 @@ /* Copyright (C) 2013-2019 Montel Laurent 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) any later version. 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "notesmanager.h" #include "notesharedglobalconfig.h" #include "network/notesnetworkreceiver.h" #include "job/createnewnotejob.h" #include "akonadi/noteschangerecorder.h" #include "attributes/notealarmattribute.h" #include "attributes/notedisplayattribute.h" #include "attributes/notelockattribute.h" #include "notesagentalarmdialog.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include NotesManager::NotesManager(QObject *parent) : QObject(parent) , mListener(nullptr) , mCheckAlarm(nullptr) { mSession = new Akonadi::Session("KNotes Session", this); mNoteRecorder = new NoteShared::NotesChangeRecorder(this); mNoteRecorder->changeRecorder()->setSession(mSession); connect(mNoteRecorder->changeRecorder(), &Akonadi::Monitor::itemAdded, this, &NotesManager::slotItemAdded); connect(mNoteRecorder->changeRecorder(), &Akonadi::Monitor::itemChanged, this, &NotesManager::slotItemChanged); connect(mNoteRecorder->changeRecorder(), &Akonadi::Monitor::itemRemoved, this, &NotesManager::slotItemRemoved); auto job = new Akonadi::CollectionFetchJob(Akonadi::Collection::root(), Akonadi::CollectionFetchJob::Recursive, mSession); job->fetchScope().setContentMimeTypes({ Akonadi::NoteUtils::noteMimeType() }); job->fetchScope().setFetchIdOnly(true); connect(job, &Akonadi::CollectionFetchJob::collectionsReceived, this, &NotesManager::slotCollectionsReceived); } NotesManager::~NotesManager() { clear(); } void NotesManager::clear() { delete mListener; mListener = nullptr; if (mCheckAlarm && mCheckAlarm->isActive()) { mCheckAlarm->stop(); } } void NotesManager::slotCollectionsReceived(const Akonadi::Collection::List &collections) { for (const Akonadi::Collection &col : collections) { if (!col.contentMimeTypes().contains(Akonadi::NoteUtils::noteMimeType())) { continue; } auto job = new Akonadi::ItemFetchJob(col, mSession); job->setDeliveryOption(Akonadi::ItemFetchJob::EmitItemsInBatches); job->fetchScope().fetchAttribute(); job->fetchScope().fetchAttribute(); job->fetchScope().fetchAttribute(); job->fetchScope().fetchAttribute(); job->fetchScope().fetchFullPayload(true); connect(job, &Akonadi::ItemFetchJob::itemsReceived, this, [this](const Akonadi::Item::List &items) { for (const Akonadi::Item &item : items) { slotItemAdded(item); } }); } } void NotesManager::slotItemAdded(const Akonadi::Item &item) { if (item.hasAttribute()) { mListItem.append(item); } } void NotesManager::slotItemRemoved(const Akonadi::Item &item) { mListItem.removeAll(item); } void NotesManager::slotItemChanged(const Akonadi::Item &item, const QSet &set) { if (set.contains("ATR:NoteAlarmAttribute")) { mListItem.removeAll(item); if (item.hasAttribute()) { mListItem.append(item); } else { if (mAlarmDialog) { mAlarmDialog->removeAlarm(item); } } } } void NotesManager::slotCheckAlarm() { QDateTime from = NoteShared::NoteSharedGlobalConfig::self()->alarmsLastChecked().addSecs(1); if (!from.isValid()) { - from.setTime_t(0); + from.setSecsSinceEpoch(0); } const QDateTime now = QDateTime::currentDateTime(); NoteShared::NoteSharedGlobalConfig::self()->setAlarmsLastChecked(now); Akonadi::Item::List lst; for (const Akonadi::Item &item : qAsConst(mListItem)) { const NoteShared::NoteAlarmAttribute *attrAlarm = item.attribute(); if (attrAlarm) { if (attrAlarm->dateTime() < QDateTime::currentDateTime()) { lst.append(item); } } } if (!lst.isEmpty()) { if (!mAlarmDialog) { mAlarmDialog = new NotesAgentAlarmDialog; } mAlarmDialog->addListAlarm(lst); mAlarmDialog->show(); } mCheckAlarm->start(); } void NotesManager::load() { updateNetworkListener(); if (!mCheckAlarm) { mCheckAlarm = new QTimer(this); } else if (mCheckAlarm->isActive()) { mCheckAlarm->stop(); } mCheckAlarm->setInterval(1000 * 60 * NoteShared::NoteSharedGlobalConfig::checkInterval()); connect(mCheckAlarm, &QTimer::timeout, this, &NotesManager::slotCheckAlarm); slotCheckAlarm(); } void NotesManager::stopAll() { clear(); } void NotesManager::slotAcceptConnection() { // Accept the connection and make KNotesNetworkReceiver do the job QTcpSocket *s = mListener->nextPendingConnection(); if (s) { NoteShared::NotesNetworkReceiver *recv = new NoteShared::NotesNetworkReceiver(s); connect(recv, &NoteShared::NotesNetworkReceiver::sigNoteReceived, this, &NotesManager::slotNewNote); } } void NotesManager::slotNewNote(const QString &name, const QString &text) { KNotification::event(QStringLiteral("receivednotes"), QString(), i18n("Note Received"), QStringLiteral("knotes"), nullptr, KNotification::CloseOnTimeout, QStringLiteral("akonadi_notes_agent")); NoteShared::CreateNewNoteJob *job = new NoteShared::CreateNewNoteJob(this, nullptr); //For the moment it doesn't support richtext. job->setRichText(false); job->setNote(name, text); job->start(); } void NotesManager::updateNetworkListener() { delete mListener; mListener = nullptr; if (NoteShared::NoteSharedGlobalConfig::receiveNotes()) { // create the socket and start listening for connections mListener = new QTcpServer; mListener->listen(QHostAddress::Any, NoteShared::NoteSharedGlobalConfig::port()); connect(mListener, &QTcpServer::newConnection, this, &NotesManager::slotAcceptConnection); } } diff --git a/src/apps/knotesakonaditray.cpp b/src/apps/knotesakonaditray.cpp index d8f2b4d..62e0dea 100644 --- a/src/apps/knotesakonaditray.cpp +++ b/src/apps/knotesakonaditray.cpp @@ -1,99 +1,99 @@ /* Copyright (C) 2013-2019 Montel Laurent 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) any later version. 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "knotesakonaditray.h" #include #include "knotesglobalconfig.h" #include #include #include #include #include #include KNotesAkonadiTray::KNotesAkonadiTray(QWidget *parent) : KStatusNotifierItem(parent) , mIcon(QIcon::fromTheme(QStringLiteral("knotes"))) { setToolTipTitle(i18n("KNotes: Sticky notes by KDE")); setToolTipIconByName(QStringLiteral("knotes")); setStatus(KStatusNotifierItem::Active); setCategory(KStatusNotifierItem::ApplicationStatus); setStandardActionsEnabled(false); //Initialize updateNumberOfNotes(0); } KNotesAkonadiTray::~KNotesAkonadiTray() { } void KNotesAkonadiTray::slotGeneralPaletteChanged() { const KColorScheme scheme(QPalette::Active, KColorScheme::View); mTextColor = scheme.foreground(KColorScheme::LinkText).color(); } void KNotesAkonadiTray::updateNumberOfNotes(int number) { if (KNotesGlobalConfig::self()->systemTrayShowNotes() && number != 0) { const int overlaySize = KIconLoader::SizeSmallMedium; const QString countString = QString::number(number); QFont countFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont); countFont.setBold(true); // decrease the size of the font for the number of unread messages if the // number doesn't fit into the available space float countFontSize = countFont.pointSizeF(); QFontMetrics qfm(countFont); - const int width = qfm.width(countString); + const int width = qfm.boundingRect(countString).width(); if (width > (overlaySize - 2)) { countFontSize *= float(overlaySize - 2) / float(width); countFont.setPointSizeF(countFontSize); } // Paint the number in a pixmap QPixmap overlayPixmap(overlaySize, overlaySize); overlayPixmap.fill(Qt::transparent); QPainter p(&overlayPixmap); p.setFont(countFont); if (!mTextColor.isValid()) { slotGeneralPaletteChanged(); } p.setBrush(Qt::NoBrush); p.setPen(mTextColor); p.setOpacity(1.0); p.drawText(overlayPixmap.rect(), Qt::AlignCenter, countString); p.end(); QPixmap iconPixmap = mIcon.pixmap(overlaySize, overlaySize); QPainter pp(&iconPixmap); pp.drawPixmap(0, 0, overlayPixmap); pp.end(); setIconByPixmap(iconPixmap); } else { setIconByPixmap(mIcon); } } diff --git a/src/knoteedit.cpp b/src/knoteedit.cpp index c52b9ae..109194e 100644 --- a/src/knoteedit.cpp +++ b/src/knoteedit.cpp @@ -1,694 +1,694 @@ /******************************************************************* KNotes -- Notes for the KDE project Copyright (c) 1997-2013, The KNotes Developers 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) any later version. 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 "knoteedit.h" #include "notes/knote.h" #include "editor/noteeditorutils.h" #include #include #include #include #include #include #include #include #include #include static const short ICON_SIZE = 10; KNoteEdit::KNoteEdit(KActionCollection *actions, QWidget *parent) : KTextEdit(parent) , m_note(nullptr) , m_actions(actions) { setAcceptDrops(true); setWordWrapMode(QTextOption::WordWrap); setLineWrapMode(WidgetWidth); if (acceptRichText()) { setAutoFormatting(AutoAll); } else { setAutoFormatting(AutoNone); } // create the actions modifying the text format m_textBold = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-text-bold")), i18n("Bold"), this); actions->addAction(QStringLiteral("format_bold"), m_textBold); actions->setDefaultShortcut(m_textBold, QKeySequence(Qt::CTRL + Qt::Key_B)); m_textItalic = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-text-italic")), i18n("Italic"), this); actions->addAction(QStringLiteral("format_italic"), m_textItalic); actions->setDefaultShortcut(m_textItalic, QKeySequence(Qt::CTRL + Qt::Key_I)); m_textUnderline = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-text-underline")), i18n("Underline"), this); actions->addAction(QStringLiteral("format_underline"), m_textUnderline); actions->setDefaultShortcut(m_textUnderline, QKeySequence(Qt::CTRL + Qt::Key_U)); m_textStrikeOut = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-text-strikethrough")), i18n("Strike Out"), this); actions->addAction(QStringLiteral("format_strikeout"), m_textStrikeOut); actions->setDefaultShortcut(m_textStrikeOut, QKeySequence(Qt::CTRL + Qt::Key_S)); connect(m_textBold, &KToggleAction::toggled, this, &KNoteEdit::textBold); connect(m_textItalic, &KToggleAction::toggled, this, &KNoteEdit::setFontItalic); connect(m_textUnderline, &KToggleAction::toggled, this, &KNoteEdit::setFontUnderline); connect(m_textStrikeOut, &KToggleAction::toggled, this, &KNoteEdit::textStrikeOut); m_textAlignLeft = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-justify-left")), i18n("Align Left"), this); actions->addAction(QStringLiteral("format_alignleft"), m_textAlignLeft); connect(m_textAlignLeft, &KToggleAction::triggered, this, &KNoteEdit::textAlignLeft); actions->setDefaultShortcut(m_textAlignLeft, QKeySequence(Qt::ALT + Qt::Key_L)); m_textAlignLeft->setChecked(true); // just a dummy, will be updated later m_textAlignCenter = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-justify-center")), i18n("Align Center"), this); actions->addAction(QStringLiteral("format_aligncenter"), m_textAlignCenter); connect(m_textAlignCenter, &KToggleAction::triggered, this, &KNoteEdit::textAlignCenter); actions->setDefaultShortcut(m_textAlignCenter, QKeySequence(Qt::ALT + Qt::Key_C)); m_textAlignRight = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-justify-right")), i18n("Align Right"), this); actions->addAction(QStringLiteral("format_alignright"), m_textAlignRight); connect(m_textAlignRight, &KToggleAction::triggered, this, &KNoteEdit::textAlignRight); actions->setDefaultShortcut(m_textAlignRight, QKeySequence(Qt::ALT + Qt::Key_R)); m_textAlignBlock = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-justify-fill")), i18n("Align Block"), this); actions->addAction(QStringLiteral("format_alignblock"), m_textAlignBlock); connect(m_textAlignBlock, &KToggleAction::triggered, this, &KNoteEdit::textAlignBlock); actions->setDefaultShortcut(m_textAlignBlock, QKeySequence(Qt::ALT + Qt::Key_B)); QActionGroup *group = new QActionGroup(this); group->addAction(m_textAlignLeft); group->addAction(m_textAlignCenter); group->addAction(m_textAlignRight); group->addAction(m_textAlignBlock); m_textList = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-list-ordered")), i18n("List"), this); actions->addAction(QStringLiteral("format_list"), m_textList); connect(m_textList, &KToggleAction::triggered, this, &KNoteEdit::textList); m_textSuper = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-text-superscript")), i18n("Superscript"), this); actions->addAction(QStringLiteral("format_super"), m_textSuper); connect(m_textSuper, &KToggleAction::triggered, this, &KNoteEdit::textSuperScript); m_textSub = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-text-subscript")), i18n("Subscript"), this); actions->addAction(QStringLiteral("format_sub"), m_textSub); connect(m_textSub, &KToggleAction::triggered, this, &KNoteEdit::textSubScript); m_textIncreaseIndent = new QAction(QIcon::fromTheme(QStringLiteral("format-indent-more")), i18n("Increase Indent"), this); actions->addAction(QStringLiteral("format_increaseindent"), m_textIncreaseIndent); actions->setDefaultShortcut(m_textIncreaseIndent, QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_I)); connect(m_textIncreaseIndent, &QAction::triggered, this, &KNoteEdit::textIncreaseIndent); m_textDecreaseIndent = new QAction(QIcon::fromTheme(QStringLiteral("format-indent-less")), i18n("Decrease Indent"), this); actions->addAction(QStringLiteral("format_decreaseindent"), m_textDecreaseIndent); actions->setDefaultShortcut(m_textDecreaseIndent, QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_D)); connect(m_textDecreaseIndent, &QAction::triggered, this, &KNoteEdit::textDecreaseIndent); group = new QActionGroup(this); group->addAction(m_textIncreaseIndent); group->addAction(m_textDecreaseIndent); QPixmap pix(ICON_SIZE, ICON_SIZE); pix.fill(Qt::black); // just a dummy, gets updated before widget is shown m_textColor = new QAction(i18n("Text Color..."), this); actions->addAction(QStringLiteral("format_color"), m_textColor); m_textColor->setIcon(pix); connect(m_textColor, &QAction::triggered, this, &KNoteEdit::slotTextColor); QAction *act = new QAction(QIcon::fromTheme(QStringLiteral("format-fill-color")), i18n("Text Background Color..."), this); actions->addAction(QStringLiteral("text_background_color"), act); connect(act, &QAction::triggered, this, &KNoteEdit::slotTextBackgroundColor); m_textFont = new KFontAction(i18n("Text Font"), this); actions->addAction(QStringLiteral("format_font"), m_textFont); connect(m_textFont, qOverload(&KFontAction::triggered), this, &KNoteEdit::setFontFamily); m_textSize = new KFontSizeAction(i18n("Text Size"), this); actions->addAction(QStringLiteral("format_size"), m_textSize); connect(m_textSize, &KFontSizeAction::fontSizeChanged, this, &KNoteEdit::setTextFontSize); mChangeCaseActionMenu = new PimCommon::KActionMenuChangeCase(this); mChangeCaseActionMenu->appendInActionCollection(actions); connect(mChangeCaseActionMenu, &PimCommon::KActionMenuChangeCase::upperCase, this, &KNoteEdit::slotUpperCase); connect(mChangeCaseActionMenu, &PimCommon::KActionMenuChangeCase::lowerCase, this, &KNoteEdit::slotLowerCase); connect(mChangeCaseActionMenu, &PimCommon::KActionMenuChangeCase::sentenceCase, this, &KNoteEdit::slotSentenceCase); connect(mChangeCaseActionMenu, &PimCommon::KActionMenuChangeCase::reverseCase, this, &KNoteEdit::slotReverseCase); QAction *action = new QAction(QIcon::fromTheme(QStringLiteral("knotes_date")), i18n("Insert Date"), this); actions->addAction(QStringLiteral("insert_date"), action); connect(action, &QAction::triggered, this, &KNoteEdit::slotInsertDate); action = new QAction(QIcon::fromTheme(QStringLiteral("checkmark")), i18n("Insert Checkmark"), this); actions->addAction(QStringLiteral("insert_checkmark"), action); connect(action, &QAction::triggered, this, &KNoteEdit::slotInsertCheckMark); // QTextEdit connections connect(this, &KNoteEdit::currentCharFormatChanged, this, &KNoteEdit::slotCurrentCharFormatChanged); connect(this, &KNoteEdit::cursorPositionChanged, this, &KNoteEdit::slotCursorPositionChanged); slotCurrentCharFormatChanged(currentCharFormat()); slotCursorPositionChanged(); } KNoteEdit::~KNoteEdit() { } void KNoteEdit::setColor(const QColor &fg, const QColor &bg) { mDefaultBackgroundColor = bg; mDefaultForegroundColor = fg; QPalette p = palette(); // better: from light(150) to light(100) to light(75) // QLinearGradient g( width()/2, 0, width()/2, height() ); // g.setColorAt( 0, bg ); // g.setColorAt( 1, bg.darker(150) ); p.setColor(QPalette::Window, bg); // p.setBrush( QPalette::Window, g ); p.setColor(QPalette::Base, bg); // p.setBrush( QPalette::Base, g ); p.setColor(QPalette::WindowText, fg); p.setColor(QPalette::Text, fg); p.setColor(QPalette::Button, bg.darker(116)); p.setColor(QPalette::ButtonText, fg); //p.setColor( QPalette::Highlight, bg ); //p.setColor( QPalette::HighlightedText, fg ); // order: Light, Midlight, Button, Mid, Dark, Shadow // the shadow p.setColor(QPalette::Light, bg.lighter(180)); p.setColor(QPalette::Midlight, bg.lighter(150)); p.setColor(QPalette::Mid, bg.lighter(150)); p.setColor(QPalette::Dark, bg.darker(108)); p.setColor(QPalette::Shadow, bg.darker(116)); setPalette(p); setTextColor(fg); } void KNoteEdit::setNote(KNote *_note) { m_note = _note; } void KNoteEdit::slotReverseCase() { QTextCursor cursor = textCursor(); KPIMTextEdit::EditorUtil editorUtil; editorUtil.reverseCase(cursor); } void KNoteEdit::slotSentenceCase() { QTextCursor cursor = textCursor(); KPIMTextEdit::EditorUtil editorUtil; editorUtil.sentenceCase(cursor); } void KNoteEdit::slotUpperCase() { QTextCursor cursor = textCursor(); KPIMTextEdit::EditorUtil editorUtil; editorUtil.upperCase(cursor); } void KNoteEdit::slotLowerCase() { QTextCursor cursor = textCursor(); KPIMTextEdit::EditorUtil editorUtil; editorUtil.lowerCase(cursor); } QMenu *KNoteEdit::mousePopupMenu() { QMenu *popup = KTextEdit::mousePopupMenu(); if (popup) { QTextCursor cursor = textCursor(); if (!isReadOnly()) { if (cursor.hasSelection()) { popup->addSeparator(); popup->addAction(mChangeCaseActionMenu); } popup->addSeparator(); QAction *act = m_actions->action(QStringLiteral("insert_date")); popup->addAction(act); popup->addSeparator(); act = m_actions->action(QStringLiteral("insert_checkmark")); popup->addAction(act); } } return popup; } void KNoteEdit::setText(const QString &text) { if (acceptRichText() && Qt::mightBeRichText(text)) { setHtml(text); } else { setPlainText(text); } } QString KNoteEdit::text() const { if (acceptRichText()) { return toHtml(); } else { return toPlainText(); } } void KNoteEdit::setTextFont(const QFont &font) { setCurrentFont(font); // make this font default so that if user deletes note content // font is remembered document()->setDefaultFont(font); } void KNoteEdit::setTextFontSize(int size) { setFontPointSize(size); } void KNoteEdit::setTabStop(int tabs) { QFontMetrics fm(font()); - setTabStopWidth(fm.width(QLatin1Char('x')) * tabs); + setTabStopDistance(fm.boundingRect(QLatin1Char('x')).width() * tabs); } void KNoteEdit::setAutoIndentMode(bool newmode) { m_autoIndentMode = newmode; } /** public slots **/ void KNoteEdit::setRichText(bool f) { if (f == acceptRichText()) { return; } setAcceptRichText(f); if (f) { setAutoFormatting(AutoAll); } else { setAutoFormatting(AutoNone); } const QString t = toPlainText(); if (f) { // if the note contains html source try to render it if (Qt::mightBeRichText(t)) { setHtml(t); } else { setPlainText(t); } enableRichTextActions(true); } else { setPlainText(t); enableRichTextActions(false); } } void KNoteEdit::textBold(bool b) { if (!acceptRichText()) { return; } QTextCharFormat f; f.setFontWeight(b ? QFont::Bold : QFont::Normal); mergeCurrentCharFormat(f); } void KNoteEdit::textStrikeOut(bool s) { if (!acceptRichText()) { return; } QTextCharFormat f; f.setFontStrikeOut(s); mergeCurrentCharFormat(f); } void KNoteEdit::slotTextColor() { if (!acceptRichText()) { return; } if (m_note) { m_note->setBlockSave(true); } QColor c = QColorDialog::getColor(textColor(), this); if (c.isValid()) { setTextColor(c); } if (m_note) { m_note->setBlockSave(false); } } void KNoteEdit::slotTextBackgroundColor() { if (!acceptRichText()) { return; } if (m_note) { m_note->setBlockSave(true); } const QColor c = QColorDialog::getColor(textBackgroundColor(), this); if (c.isValid()) { setTextBackgroundColor(c); } if (m_note) { m_note->setBlockSave(false); } } void KNoteEdit::textAlignLeft() { if (!acceptRichText()) { return; } setAlignment(Qt::AlignLeft); m_textAlignLeft->setChecked(true); } void KNoteEdit::textAlignCenter() { if (!acceptRichText()) { return; } setAlignment(Qt::AlignCenter); m_textAlignCenter->setChecked(true); } void KNoteEdit::textAlignRight() { if (!acceptRichText()) { return; } setAlignment(Qt::AlignRight); m_textAlignRight->setChecked(true); } void KNoteEdit::textAlignBlock() { if (!acceptRichText()) { return; } setAlignment(Qt::AlignJustify); m_textAlignBlock->setChecked(true); } void KNoteEdit::textList() { if (!acceptRichText()) { return; } QTextCursor c = textCursor(); c.beginEditBlock(); if (m_textList->isChecked()) { QTextListFormat lf; QTextBlockFormat bf = c.blockFormat(); lf.setIndent(bf.indent() + 1); bf.setIndent(0); lf.setStyle(QTextListFormat::ListDisc); c.setBlockFormat(bf); c.createList(lf); } else { QTextBlockFormat bf; bf.setObjectIndex(-1); c.setBlockFormat(bf); } c.endEditBlock(); } void KNoteEdit::textSuperScript() { if (!acceptRichText()) { return; } QTextCharFormat f; if (m_textSuper->isChecked()) { if (m_textSub->isChecked()) { m_textSub->setChecked(false); } f.setVerticalAlignment(QTextCharFormat::AlignSuperScript); } else { f.setVerticalAlignment(QTextCharFormat::AlignNormal); } mergeCurrentCharFormat(f); } void KNoteEdit::textSubScript() { if (!acceptRichText()) { return; } QTextCharFormat f; if (m_textSub->isChecked()) { if (m_textSuper->isChecked()) { m_textSuper->setChecked(false); } f.setVerticalAlignment(QTextCharFormat::AlignSubScript); } else { f.setVerticalAlignment(QTextCharFormat::AlignNormal); } mergeCurrentCharFormat(f); } void KNoteEdit::textIncreaseIndent() { if (!acceptRichText()) { return; } QTextBlockFormat f = textCursor().blockFormat(); f.setIndent(f.indent() + 1); textCursor().setBlockFormat(f); } void KNoteEdit::textDecreaseIndent() { if (!acceptRichText()) { return; } QTextBlockFormat f = textCursor().blockFormat(); short int curIndent = f.indent(); if (curIndent > 0) { f.setIndent(curIndent - 1); } textCursor().setBlockFormat(f); } /** protected methods **/ void KNoteEdit::keyPressEvent(QKeyEvent *e) { KTextEdit::keyPressEvent(e); if (m_autoIndentMode && ((e->key() == Qt::Key_Return) || (e->key() == Qt::Key_Enter))) { autoIndent(); } } void KNoteEdit::focusInEvent(QFocusEvent *e) { KTextEdit::focusInEvent(e); setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); } void KNoteEdit::focusOutEvent(QFocusEvent *e) { setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); KTextEdit::focusOutEvent(e); } /** private slots **/ void KNoteEdit::slotCurrentCharFormatChanged(const QTextCharFormat &f) { if (!acceptRichText()) { return; } // font changes m_textFont->setFont(f.fontFamily()); m_textSize->setFontSize((f.fontPointSize() > 0) ? (int)f.fontPointSize() : 10); m_textBold->setChecked(f.font().bold()); m_textItalic->setChecked(f.fontItalic()); m_textUnderline->setChecked(f.fontUnderline()); m_textStrikeOut->setChecked(f.fontStrikeOut()); // color changes QPixmap pix(ICON_SIZE, ICON_SIZE); pix.fill(f.foreground().color()); m_textColor->QAction::setIcon(pix); // vertical alignment changes QTextCharFormat::VerticalAlignment va = f.verticalAlignment(); if (va == QTextCharFormat::AlignNormal) { m_textSuper->setChecked(false); m_textSub->setChecked(false); } else if (va == QTextCharFormat::AlignSuperScript) { m_textSuper->setChecked(true); } else if (va == QTextCharFormat::AlignSubScript) { m_textSub->setChecked(true); } } void KNoteEdit::slotCursorPositionChanged() { if (!acceptRichText()) { return; } // alignment changes const Qt::Alignment a = alignment(); if (a & Qt::AlignLeft) { m_textAlignLeft->setChecked(true); } else if (a & Qt::AlignHCenter) { m_textAlignCenter->setChecked(true); } else if (a & Qt::AlignRight) { m_textAlignRight->setChecked(true); } else if (a & Qt::AlignJustify) { m_textAlignBlock->setChecked(true); } } /** private methods **/ void KNoteEdit::autoIndent() { QTextCursor c = textCursor(); QTextBlock b = c.block(); QString string; while ((b.previous().length() > 0) && string.trimmed().isEmpty()) { b = b.previous(); string = b.text(); } if (string.trimmed().isEmpty()) { return; } // This routine returns the whitespace before the first non white space // character in string. // It is assumed that string contains at least one non whitespace character // ie \n \r \t \v \f and space QString indentString; const int len = string.length(); int i = 0; while (i < len && string.at(i).isSpace()) { indentString += string.at(i++); } if (!indentString.isEmpty()) { c.insertText(indentString); } } void KNoteEdit::enableRichTextActions(bool enabled) { m_textColor->setEnabled(enabled); m_textFont->setEnabled(enabled); m_textSize->setEnabled(enabled); m_textBold->setEnabled(enabled); m_textItalic->setEnabled(enabled); m_textUnderline->setEnabled(enabled); m_textStrikeOut->setEnabled(enabled); m_textAlignLeft->setEnabled(enabled); m_textAlignCenter->setEnabled(enabled); m_textAlignRight->setEnabled(enabled); m_textAlignBlock->setEnabled(enabled); m_textList->setEnabled(enabled); m_textSuper->setEnabled(enabled); m_textSub->setEnabled(enabled); m_textIncreaseIndent->setEnabled(enabled); m_textDecreaseIndent->setEnabled(enabled); } void KNoteEdit::slotInsertDate() { NoteShared::NoteEditorUtils noteEditorUtils; noteEditorUtils.insertDate(this); } void KNoteEdit::slotInsertCheckMark() { QTextCursor cursor = textCursor(); NoteShared::NoteEditorUtils noteEditorUtils; noteEditorUtils.addCheckmark(cursor); } void KNoteEdit::setCursorPositionFromStart(int pos) { if (pos > 0) { QTextCursor cursor = textCursor(); //Fix html pos cursor cursor.setPosition(qMin(pos, cursor.document()->characterCount() - 1)); setTextCursor(cursor); ensureCursorVisible(); } } int KNoteEdit::cursorPositionFromStart() const { return textCursor().position(); } diff --git a/src/kontactplugin/knotesselectdeletenotesdialog.cpp b/src/kontactplugin/knotesselectdeletenotesdialog.cpp index 50794bf..9578409 100644 --- a/src/kontactplugin/knotesselectdeletenotesdialog.cpp +++ b/src/kontactplugin/knotesselectdeletenotesdialog.cpp @@ -1,101 +1,101 @@ /* Copyright (C) 2013-2019 Montel Laurent 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) any later version. 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "knotesselectdeletenotesdialog.h" #include "knotesiconview.h" #include #include #include #include #include #include #include #include KNotesSelectDeleteNotesListWidget::KNotesSelectDeleteNotesListWidget(QWidget *parent) : QListWidget(parent) { } KNotesSelectDeleteNotesListWidget::~KNotesSelectDeleteNotesListWidget() { } void KNotesSelectDeleteNotesListWidget::setItems(const QList &items) { for (KNotesIconViewItem *item : items) { QListWidgetItem *i = new QListWidgetItem(this); if (item->readOnly()) { i->setText(item->realName() + QLatin1Char(' ') + i18n("(note locked, it will not removed)")); - i->setTextColor(Qt::red); + i->setForeground(Qt::red); } else { i->setText(item->realName()); } } } KNotesSelectDeleteNotesDialog::KNotesSelectDeleteNotesDialog(const QList &items, QWidget *parent) : QDialog(parent) { setWindowTitle(i18nc("@title:window", "Confirm Delete")); QVBoxLayout *mainLayout = new QVBoxLayout(this); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); connect(buttonBox, &QDialogButtonBox::accepted, this, &KNotesSelectDeleteNotesDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, this, &KNotesSelectDeleteNotesDialog::reject); buttonBox->button(QDialogButtonBox::Cancel)->setDefault(true); setModal(true); QWidget *w = new QWidget; QVBoxLayout *lay = new QVBoxLayout; w->setLayout(lay); QLabel *lab = new QLabel(i18ncp("@info", "Do you really want to delete this note?", "Do you really want to delete these %1 notes?", items.count())); lay->addWidget(lab); mSelectedListWidget = new KNotesSelectDeleteNotesListWidget; lay->addWidget(mSelectedListWidget); mainLayout->addWidget(w); mSelectedListWidget->setItems(items); okButton->setText(KStandardGuiItem::del().text()); mainLayout->addWidget(buttonBox); readConfig(); } KNotesSelectDeleteNotesDialog::~KNotesSelectDeleteNotesDialog() { writeConfig(); } void KNotesSelectDeleteNotesDialog::readConfig() { KConfigGroup grp(KSharedConfig::openConfig(), "KNotesSelectDeleteNotesDialog"); const QSize size = grp.readEntry("Size", QSize(300, 200)); if (size.isValid()) { resize(size); } } void KNotesSelectDeleteNotesDialog::writeConfig() { KConfigGroup grp(KSharedConfig::openConfig(), "KNotesSelectDeleteNotesDialog"); grp.writeEntry("Size", size()); grp.sync(); } diff --git a/src/kontactplugin/summarywidget.cpp b/src/kontactplugin/summarywidget.cpp index 1604178..672a7cc 100644 --- a/src/kontactplugin/summarywidget.cpp +++ b/src/kontactplugin/summarywidget.cpp @@ -1,255 +1,255 @@ /* This file is part of Kontact. Copyright (c) 2003 Tobias Koenig Copyright (C) 2014-2019 Laurent Montel 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) any later version. 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. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include "summarywidget.h" #include "knotesinterface.h" #include "akonadi/noteschangerecorder.h" #include "akonadi/notesakonaditreemodel.h" #include "attributes/notedisplayattribute.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include KNotesSummaryWidget::KNotesSummaryWidget(KontactInterface::Plugin *plugin, QWidget *parent) : KontactInterface::Summary(parent) , mPlugin(plugin) , mInProgress(false) { mDefaultPixmap = KIconLoader::global()->loadIcon(QStringLiteral("knotes"), KIconLoader::Desktop); QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setSpacing(3); - mainLayout->setMargin(3); + mainLayout->setContentsMargins(3, 3, 3, 3); QWidget *header = createHeader(this, QStringLiteral("view-pim-notes"), i18n("Popup Notes")); mainLayout->addWidget(header); mLayout = new QGridLayout(); mainLayout->addItem(mLayout); mLayout->setSpacing(3); mLayout->setRowStretch(6, 1); KIconLoader loader(QStringLiteral("knotes")); mPixmap = loader.loadIcon(QStringLiteral("knotes"), KIconLoader::Small); Akonadi::Session *session = new Akonadi::Session("KNotes Session", this); mNoteRecorder = new NoteShared::NotesChangeRecorder(this); mNoteRecorder->changeRecorder()->setSession(session); mNoteTreeModel = new NoteShared::NotesAkonadiTreeModel(mNoteRecorder->changeRecorder(), this); connect(mNoteTreeModel, &NoteShared::NotesAkonadiTreeModel::rowsInserted, this, &KNotesSummaryWidget::updateFolderList); connect(mNoteRecorder->changeRecorder(), &Akonadi::Monitor::itemChanged, this, &KNotesSummaryWidget::updateFolderList); connect(mNoteRecorder->changeRecorder(), &Akonadi::Monitor::itemRemoved, this, &KNotesSummaryWidget::updateFolderList); mSelectionModel = new QItemSelectionModel(mNoteTreeModel); mModelProxy = new KCheckableProxyModel(this); mModelProxy->setSelectionModel(mSelectionModel); mModelProxy->setSourceModel(mNoteTreeModel); KSharedConfigPtr _config = KSharedConfig::openConfig(QStringLiteral("kcmknotessummaryrc")); mModelState = new KViewStateMaintainer(_config->group("CheckState"), this); mModelState->setSelectionModel(mSelectionModel); } KNotesSummaryWidget::~KNotesSummaryWidget() { } void KNotesSummaryWidget::updateFolderList() { if (mInProgress) { return; } mInProgress = true; qDeleteAll(mLabels); mLabels.clear(); int counter = 0; mModelState->restoreState(); displayNotes(QModelIndex(), counter); mInProgress = false; if (counter == 0) { QLabel *label = new QLabel(i18n("No notes found"), this); label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); mLayout->addWidget(label, 0, 0); mLabels.append(label); } QList::const_iterator lit; QList::const_iterator lend(mLabels.constEnd()); for (lit = mLabels.constBegin(); lit != lend; ++lit) { (*lit)->show(); } } void KNotesSummaryWidget::displayNotes(const QModelIndex &parent, int &counter) { const int nbCol = mModelProxy->rowCount(parent); for (int i = 0; i < nbCol; ++i) { const QModelIndex child = mModelProxy->index(i, 0, parent); const Akonadi::Item item = mModelProxy->data(child, Akonadi::EntityTreeModel::ItemRole).value(); if (item.isValid()) { createNote(item, counter); ++counter; } displayNotes(child, counter); } } void KNotesSummaryWidget::slotPopupMenu(const QString ¬e) { QMenu popup(this); const QAction *modifyNoteAction = popup.addAction( KIconLoader::global()->loadIcon(QStringLiteral("document-edit"), KIconLoader::Small), i18n("Modify Note...")); popup.addSeparator(); const QAction *deleteNoteAction = popup.addAction( KIconLoader::global()->loadIcon(QStringLiteral("edit-delete"), KIconLoader::Small), i18n("Delete Note...")); const QAction *ret = popup.exec(QCursor::pos()); if (ret == deleteNoteAction) { deleteNote(note); } else if (ret == modifyNoteAction) { slotSelectNote(note); } } void KNotesSummaryWidget::deleteNote(const QString ¬e) { org::kde::kontact::KNotes knotes(QStringLiteral("org.kde.kontact"), QStringLiteral("/KNotes"), QDBusConnection::sessionBus()); knotes.killNote(note.toLongLong()); } void KNotesSummaryWidget::createNote(const Akonadi::Item &item, int counter) { if (!item.hasPayload()) { return; } KMime::Message::Ptr noteMessage = item.payload(); if (!noteMessage) { return; } const KMime::Headers::Subject *const subject = noteMessage->subject(false); const QString subStr = subject ? subject->asUnicodeString() : QString(); KUrlLabel *urlLabel = new KUrlLabel(QString::number(item.id()), subStr, this); urlLabel->installEventFilter(this); urlLabel->setAlignment(Qt::AlignLeft); urlLabel->setWordWrap(true); connect(urlLabel, qOverload(&KUrlLabel::leftClickedUrl), this, &KNotesSummaryWidget::slotSelectNote); connect(urlLabel, qOverload(&KUrlLabel::rightClickedUrl), this, &KNotesSummaryWidget::slotPopupMenu); mLayout->addWidget(urlLabel, counter, 1); QColor color; if (item.hasAttribute()) { color = item.attribute()->backgroundColor(); } // Folder icon. KIconEffect effect; QPixmap pixmap = effect.apply(mDefaultPixmap, KIconEffect::Colorize, 1, color, false); QLabel *label = new QLabel(this); label->setAlignment(Qt::AlignVCenter); QIcon icon(pixmap); label->setPixmap(icon.pixmap(label->height() / 1.5)); label->setMaximumWidth(label->minimumSizeHint().width()); mLayout->addWidget(label, counter, 0); mLabels.append(label); mLabels.append(urlLabel); } void KNotesSummaryWidget::updateSummary(bool force) { Q_UNUSED(force); updateFolderList(); } void KNotesSummaryWidget::slotSelectNote(const QString ¬e) { if (!mPlugin->isRunningStandalone()) { mPlugin->core()->selectPlugin(mPlugin); } else { mPlugin->bringToForeground(); } org::kde::kontact::KNotes knotes(QStringLiteral("org.kde.kontact"), QStringLiteral("/KNotes"), QDBusConnection::sessionBus()); knotes.editNote(note.toLongLong()); } bool KNotesSummaryWidget::eventFilter(QObject *obj, QEvent *e) { if (obj->inherits("KUrlLabel")) { KUrlLabel *label = static_cast(obj); if (e->type() == QEvent::Enter) { Q_EMIT message(i18n("Read Popup Note: \"%1\"", label->text())); } else if (e->type() == QEvent::Leave) { Q_EMIT message(QString()); } } return KontactInterface::Summary::eventFilter(obj, e); } QStringList KNotesSummaryWidget::configModules() const { return QStringList() << QStringLiteral("kcmknotessummary.desktop"); } diff --git a/src/print/knoteprinter.cpp b/src/print/knoteprinter.cpp index 1e2d08e..013d4fa 100644 --- a/src/print/knoteprinter.cpp +++ b/src/print/knoteprinter.cpp @@ -1,144 +1,144 @@ /* Copyright (C) 2013-2019 Montel Laurent 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) any later version. 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "knoteprinter.h" #include "print/knoteprintobject.h" #include "knotegrantleeprint.h" #include #include #include #include #include #include #include #include #include #include "knotes_debug.h" #include #include #include KNotePrinter::KNotePrinter(QObject *parent) : QObject(parent) { } KNotePrinter::~KNotePrinter() { } void KNotePrinter::setDefaultFont(const QFont &font) { m_defaultFont = font; } QFont KNotePrinter::defaultFont() const { return m_defaultFont; } void KNotePrinter::doPrintPreview(const QString &htmlText) { mHtmlPreviewText = htmlText; QPrinter printer(QPrinter::HighResolution); printer.setOutputFormat(QPrinter::PdfFormat); printer.setCollateCopies(true); PimCommon::KPimPrintPreviewDialog previewdlg(&printer, nullptr); connect(&previewdlg, &QPrintPreviewDialog::paintRequested, this, &KNotePrinter::slotPrinterPage); previewdlg.exec(); } void KNotePrinter::slotPrinterPage(QPrinter *printer) { print(*(printer), mHtmlPreviewText); } void KNotePrinter::doPrint(const QString &htmlText, const QString &dialogCaption) { QPrinter printer(QPrinter::HighResolution); //printer.setFullPage( true ); //disabled, causes asymmetric margins QPointer printDialog = new QPrintDialog(&printer); printDialog->setWindowTitle(dialogCaption); if (!printDialog->exec() || !printDialog) { delete printDialog; return; } print(printer, htmlText); } void KNotePrinter::print(QPrinter &printer, const QString &htmlText) { const int margin = 30; //pt //set to 40 when setFullPage() works again int marginX = margin * printer.logicalDpiX() / 72; int marginY = margin * printer.logicalDpiY() / 72; QRect typeArea(marginX, marginY, printer.width() - marginX * 2, printer.height() - marginY * 2); QTextDocument textDoc; textDoc.setHtml(htmlText); textDoc.documentLayout()->setPaintDevice(&printer); textDoc.setPageSize(typeArea.size()); textDoc.setDefaultFont(m_defaultFont); QPainter painter(&printer); QRect clip(typeArea); painter.translate(marginX, marginY); clip.translate(-marginX, -marginY); for (int page = 1; page <= textDoc.pageCount(); ++page) { textDoc.drawContents(&painter, clip); clip.translate(0, typeArea.height()); painter.translate(0, -typeArea.height()); painter.setFont(m_defaultFont); const QString pageNumber(QString::number(page)); painter.drawText( - clip.right() - painter.fontMetrics().width(pageNumber), + clip.right() - painter.fontMetrics().boundingRect(pageNumber).width(), clip.bottom() + painter.fontMetrics().ascent() + 5, pageNumber); if (page < textDoc.pageCount()) { printer.newPage(); } } } void KNotePrinter::printNotes(const QList &lst, const QString &themePath, bool preview) { mGrantleePrint.reset(new KNoteGrantleePrint(themePath)); if (mGrantleePrint->errorMessage().isEmpty()) { const QString htmlText = mGrantleePrint->notesToHtml(lst); const QString dialogCaption = i18np("Print Note", "Print %1 notes", lst.count()); if (preview) { doPrintPreview(htmlText); } else { doPrint(htmlText, dialogCaption); } } else { KMessageBox::error(nullptr, i18n("Printing theme was not found."), i18n("Printing error")); } }