diff --git a/applets/clipboard/contents/ui/ImageItemDelegate.qml b/applets/clipboard/contents/ui/ImageItemDelegate.qml --- a/applets/clipboard/contents/ui/ImageItemDelegate.qml +++ b/applets/clipboard/contents/ui/ImageItemDelegate.qml @@ -24,7 +24,8 @@ KQuickControlsAddons.QPixmapItem { id: previewPixmap - height: Math.round(width * (nativeHeight/nativeWidth) + units.smallSpacing * 2) + width: Math.min(nativeWidth, width) + height: Math.min(nativeHeight, Math.round(width * (nativeHeight/nativeWidth) + units.smallSpacing * 2)) pixmap: DecorationRole fillMode: KQuickControlsAddons.QPixmapItem.PreserveAspectFit } diff --git a/klipper/historyimageitem.h b/klipper/historyimageitem.h --- a/klipper/historyimageitem.h +++ b/klipper/historyimageitem.h @@ -37,7 +37,7 @@ } return false; } - const QPixmap& image() const override { return m_data; } + const QPixmap& image() const override; QMimeData* mimeData() const override; void write( QDataStream& stream ) const override; diff --git a/klipper/historyimageitem.cpp b/klipper/historyimageitem.cpp --- a/klipper/historyimageitem.cpp +++ b/klipper/historyimageitem.cpp @@ -18,8 +18,11 @@ */ #include "historyimageitem.h" -#include +#include "historymodel.h" + #include +#include +#include namespace { QByteArray compute_uuid(const QPixmap& data) { @@ -39,13 +42,12 @@ QString HistoryImageItem::text() const { if ( m_text.isNull() ) { - m_text = QStringLiteral( "%1x%2x%3 %4" ) + m_text = QStringLiteral( "▨ %1x%2 %3bpp" ) .arg( m_data.width() ) .arg( m_data.height() ) .arg( m_data.depth() ); } return m_text; - } /* virtual */ @@ -60,3 +62,12 @@ return data; } +const QPixmap& HistoryImageItem::image() const { + if (m_model->displayImages()) { + return m_data; + } + static QPixmap imageIcon( + QIcon::fromTheme(QStringLiteral("viewimage")).pixmap(QSize(48, 48)) + ); + return imageIcon; +} diff --git a/klipper/historyitem.h b/klipper/historyitem.h --- a/klipper/historyitem.h +++ b/klipper/historyitem.h @@ -100,9 +100,12 @@ QByteArray next_uuid() const; void setModel(HistoryModel *model); + +protected: + HistoryModel *m_model; + private: QByteArray m_uuid; - HistoryModel *m_model; }; inline diff --git a/klipper/historyitem.cpp b/klipper/historyitem.cpp --- a/klipper/historyitem.cpp +++ b/klipper/historyitem.cpp @@ -30,8 +30,8 @@ #include "historymodel.h" HistoryItem::HistoryItem(const QByteArray& uuid) - : m_uuid(uuid) - , m_model(nullptr) + : m_model(nullptr) + , m_uuid(uuid) { } diff --git a/klipper/historymodel.h b/klipper/historymodel.h --- a/klipper/historymodel.h +++ b/klipper/historymodel.h @@ -46,6 +46,9 @@ int maxSize() const; void setMaxSize(int size); + bool displayImages() const; + void setDisplayImages(bool show); + void clear(); void moveToTop(const QByteArray &uuid); void moveTopToBack(); @@ -64,6 +67,7 @@ void moveToTop(int row); QList> m_items; int m_maxSize; + bool m_displayImages; QMutex m_mutex; }; @@ -72,6 +76,14 @@ return m_maxSize; } +inline bool HistoryModel::displayImages() const { + return m_displayImages; +} + +inline void HistoryModel::setDisplayImages(bool show) { + m_displayImages = show; +} + Q_DECLARE_METATYPE(HistoryItemType) #endif diff --git a/klipper/klipper.h b/klipper/klipper.h --- a/klipper/klipper.h +++ b/klipper/klipper.h @@ -145,6 +145,8 @@ void newClipData( QClipboard::Mode ); void slotClearClipboard(); + void slotHistoryChanged(); + void slotQuit(); void slotStartShowTimer(); @@ -159,8 +161,6 @@ QClipboard* m_clip; - QSharedPointer m_last; - QTime m_showTimer; History* m_history; diff --git a/klipper/klipper.cpp b/klipper/klipper.cpp --- a/klipper/klipper.cpp +++ b/klipper/klipper.cpp @@ -116,6 +116,7 @@ m_history = new History( this ); m_popup = new KlipperPopup(m_history); m_popup->setShowHelp(m_mode == KlipperMode::Standalone); + connect(m_history, &History::changed, this, &Klipper::slotHistoryChanged); connect(m_history, &History::changed, m_popup, &KlipperPopup::slotHistoryChanged); connect(m_history, &History::topIsUserSelectedSet, m_popup, &KlipperPopup::slotTopIsUserSelectedSet); @@ -288,7 +289,6 @@ void Klipper::clearClipboardHistory() { updateTimestamp(); - slotClearClipboard(); history()->slotClear(); saveSession(); } @@ -330,6 +330,8 @@ // this will cause it to loadSettings too setURLGrabberEnabled(m_bURLGrabber); history()->setMaxSize( KlipperSettings::maxClipItems() ); + history()->model()->setDisplayImages(!m_bIgnoreImages); + // Convert 4.3 settings if (KlipperSettings::synchronize() != 3) { // 2 was the id of "Ignore selection" radiobutton @@ -604,23 +606,24 @@ return HistoryItemPtr(); } Ignore lock( m_locklevel ); - HistoryItemPtr item = HistoryItem::create( clipData ); - bool saveHistory = true; - if (clipData->data(QStringLiteral("x-kde-passwordManagerHint")) == QByteArrayLiteral("secret")) { - saveHistory = false; - } - if (clipData->hasImage() && m_bIgnoreImages) { - saveHistory = false; + if (!(history()->empty())) { + if (m_bIgnoreImages && history()->first()->mimeData()->hasImage()) { + history()->remove(history()->first()); + } } - m_last = item; + HistoryItemPtr item = HistoryItem::create( clipData ); - if (saveHistory) { + bool saveToHistory = true; + if (clipData->data(QStringLiteral("x-kde-passwordManagerHint")) == QByteArrayLiteral("secret")) { + saveToHistory = false; + } + if (saveToHistory) { history()->insert( item ); } - return item; + return item; } void Klipper::newClipData( QClipboard::Mode mode ) @@ -636,6 +639,13 @@ } +void Klipper::slotHistoryChanged() +{ + if (history()->empty()) { + slotClearClipboard(); + } +} + // Protection against too many clipboard data changes. Lyx responds to clipboard data // requests with setting new clipboard data, so if Lyx takes over clipboard, // Klipper notices, requests this data, this triggers "new" clipboard contents @@ -697,7 +707,7 @@ // This won't quite work, but it's close enough for now. // The trouble is that the top selection =! top clipboard // but we don't track that yet. We will.... - auto top = m_last; + auto top = history()->first(); if ( top ) { setClipboard( *top, selectionMode ? Selection : Clipboard); } @@ -721,7 +731,7 @@ } if ( changed && clipEmpty && m_bNoNullClipboard ) { - auto top = m_last; + auto top = history()->first(); if ( top ) { // keep old clipboard after someone set it to null qCDebug(KLIPPER_LOG) << "Resetting clipboard (Prevent empty clipboard)"; @@ -992,7 +1002,6 @@ KMessageBox::Dangerous); if (clearHist == KMessageBox::Yes) { history()->slotClear(); - slotClearClipboard(); saveHistory(); } diff --git a/klipper/tray.h b/klipper/tray.h --- a/klipper/tray.h +++ b/klipper/tray.h @@ -32,7 +32,7 @@ KlipperTray(); public Q_SLOTS: - void slotSetToolTipFromHistory(); + void slotUpdateToolTip(); private: Klipper* m_klipper; diff --git a/klipper/tray.cpp b/klipper/tray.cpp --- a/klipper/tray.cpp +++ b/klipper/tray.cpp @@ -43,23 +43,22 @@ m_klipper = new Klipper( this, KSharedConfig::openConfig()); setContextMenu( m_klipper->popup() ); setAssociatedWidget( m_klipper->popup() ); - connect( m_klipper->history(), &History::changed, this, &KlipperTray::slotSetToolTipFromHistory); - slotSetToolTipFromHistory(); + connect(m_klipper->history(), &History::changed, this, &KlipperTray::slotUpdateToolTip); + connect(m_klipper, &Klipper::activeItemChanged, this, &KlipperTray::slotUpdateToolTip); + slotUpdateToolTip(); } -void KlipperTray::slotSetToolTipFromHistory() +void KlipperTray::slotUpdateToolTip() { const int TOOLTIP_LENGTH_LIMIT = 200; - if (m_klipper->history()->empty()) { - setToolTipSubTitle( i18n("Clipboard is empty")); - } else { - HistoryItemConstPtr top = m_klipper->history()->first(); - if (top->text().length() <= TOOLTIP_LENGTH_LIMIT) { - setToolTipSubTitle(top->text()); + HistoryItemConstPtr active = m_klipper->activeItem(); + if (active) { + if (active->text().length() <= TOOLTIP_LENGTH_LIMIT) { + setToolTipSubTitle(active->text()); } else { - setToolTipSubTitle(top->text().left(TOOLTIP_LENGTH_LIMIT - 3) + QStringLiteral("...") ); + setToolTipSubTitle(active->text().left(TOOLTIP_LENGTH_LIMIT - 3) + QStringLiteral("...") ); } + } else { + setToolTipSubTitle( i18n("Clipboard is empty")); } } - -