diff --git a/src/akonadi-contacts/textbrowser.cpp b/src/akonadi-contacts/textbrowser.cpp index 9e0c7ceb..cbbc0d4e 100644 --- a/src/akonadi-contacts/textbrowser.cpp +++ b/src/akonadi-contacts/textbrowser.cpp @@ -1,151 +1,150 @@ /* Copyright (c) 2012-2019 Montel Laurent 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 "textbrowser_p.h" -#include #include #include #include #include #include #include #include #include #include #include using namespace Akonadi; TextBrowser::TextBrowser(QWidget *parent) : QTextBrowser(parent) { setOpenLinks(false); } void TextBrowser::slotCopyData() { #ifndef QT_NO_CLIPBOARD QClipboard *clip = QApplication::clipboard(); // put the data into the mouse selection and the clipboard if (mDataToCopy.type() == QVariant::Pixmap) { clip->setPixmap(mDataToCopy.value(), QClipboard::Clipboard); clip->setPixmap(mDataToCopy.value(), QClipboard::Selection); } else { clip->setText(mDataToCopy.toString(), QClipboard::Clipboard); clip->setText(mDataToCopy.toString(), QClipboard::Selection); } #endif } #ifndef QT_NO_CONTEXTMENU void TextBrowser::contextMenuEvent(QContextMenuEvent *event) { #ifndef QT_NO_CLIPBOARD QMenu popup; QAction *act = KStandardAction::copy(this, &TextBrowser::copy, this); act->setEnabled(!textCursor().selectedText().isEmpty()); act->setShortcut(QKeySequence()); popup.addAction(act); // Create a new action to correspond with what is under the click act = new QAction(i18nc("@action:inmenu Copy the text of a general item", "Copy Item"), this); mDataToCopy.clear(); // nothing found to copy yet QString link = anchorAt(event->pos()); if (!link.isEmpty()) { if (link.startsWith(QLatin1String("mailto:"))) { mDataToCopy = KCodecs::decodeRFC2047String(QUrl(link).path()); // Action text matches that used in KMail act->setText(i18nc("@action:inmenu Copy a displayed email address", "Copy Email Address")); } else { // A link, but it could be one of our internal ones. There is // no point in copying these. Internal links are always in the // form "protocol:?argument", whereas valid external links should // be in the form starting with "protocol://". if (!link.contains(QRegExp(QStringLiteral("^\\w+:\\?")))) { mDataToCopy = link; // Action text matches that used in Konqueror act->setText(i18nc("@action:inmenu Copy a link URL", "Copy Link URL")); } } } if (!mDataToCopy.isValid()) { // no link was found above QTextCursor curs = cursorForPosition(event->pos()); QString text = curs.block().text(); // try the text under cursor if (!text.isEmpty()) { // curs().block().text() over an image (contact photo or QR code) // returns a string starting with the character 0xFFFC (Unicode // object replacement character). See the documentation for // QTextImageFormat. if (text.startsWith(QChar(0xFFFC))) { QTextCharFormat charFormat = curs.charFormat(); if (charFormat.isImageFormat()) { QTextImageFormat imageFormat = charFormat.toImageFormat(); QString imageName = imageFormat.name(); QVariant imageResource = document()->resource(QTextDocument::ImageResource, QUrl(imageName)); QPixmap pix = imageResource.value(); if (!pix.isNull()) { // There may be other images (e.g. contact type icons) that // there is no point in copying. if (imageName == QLatin1String("contact_photo")) { mDataToCopy = pix; act->setText(i18nc("@action:inmenu Copy a contact photo", "Copy Photo")); } else if (imageName == QLatin1String("qrcode")) { mDataToCopy = pix; act->setText(i18nc("@action:inmenu Copy a QR code image", "Copy Code")); } } } } else { // Added by our formatter (but not I18N'ed) for a mobile // telephone number. See // kdepim/kaddressbook/grantlee/grantleecontactformatter.cpp and // kdepimlibs/akonadi/contact/standardcontactformatter.cpp text.remove(QRegExp(QStringLiteral("\\s*\\(SMS\\)$"))); // For an item which was formatted with line breaks (as
// in HTML), the returned text contains the character 0x2028 // (Unicode line separator). Convert any of these back to newlines. text.replace(QChar(0x2028), QLatin1Char('\n')); mDataToCopy = text; } } } if (mDataToCopy.isValid()) { connect(act, &QAction::triggered, this, &TextBrowser::slotCopyData); } else { act->setEnabled(false); } popup.addAction(act); popup.exec(event->globalPos()); #endif } #endif diff --git a/src/contact-editor/editor/widgets/preferredlineeditwidget.cpp b/src/contact-editor/editor/widgets/preferredlineeditwidget.cpp index be64a9b7..73ff46a1 100644 --- a/src/contact-editor/editor/widgets/preferredlineeditwidget.cpp +++ b/src/contact-editor/editor/widgets/preferredlineeditwidget.cpp @@ -1,76 +1,70 @@ /* This file is part of Contact Editor. Copyright (C) 2016-2019 Laurent Montel 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 "preferredlineeditwidget.h" -#include -#include #include #include using namespace ContactEditor; PreferredLineEditWidget::PreferredLineEditWidget(QWidget *parent) : KLineEdit(parent) , mPreferred(false) { mIconEnabled = QIcon::fromTheme(QStringLiteral("rating")); - KIconLoader loader; - QImage iconDisabled - = mIconEnabled.pixmap(loader.currentSize(KIconLoader::Panel)).toImage(); - KIconEffect::toGray(iconDisabled, 1.0); - mIconDisabled = QIcon(QPixmap::fromImage(iconDisabled)); + mIconDisabled = QIcon::fromTheme(QStringLiteral("rating-unrated")); mPreferredAction = addAction(mIconDisabled, QLineEdit::TrailingPosition); mPreferredAction->setObjectName(QStringLiteral("preferredaction")); mPreferredAction->setToolTip(i18n("Set as Preferred")); connect(mPreferredAction, &QAction::triggered, this, &PreferredLineEditWidget::slotPreferredStatusChanged); } PreferredLineEditWidget::~PreferredLineEditWidget() { } void PreferredLineEditWidget::slotPreferredStatusChanged() { if (isReadOnly()) { return; } mPreferred = !mPreferred; updatePreferredIcon(); Q_EMIT preferredChanged(this); } void PreferredLineEditWidget::updatePreferredIcon() { mPreferredAction->setIcon(mPreferred ? mIconEnabled : mIconDisabled); } void PreferredLineEditWidget::setPreferred(bool preferred) { if (mPreferred != preferred) { mPreferred = preferred; updatePreferredIcon(); } } bool PreferredLineEditWidget::preferred() const { return mPreferred; }