From kde-commits Sat Aug 31 22:22:21 2013 From: =?utf-8?q?Thomas_L=C3=BCbking?= Date: Sat, 31 Aug 2013 22:22:21 +0000 To: kde-commits Subject: [trojita/thomas_attachment_layout] src/Gui: other attachment changes Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=137798775125764 Git commit abffc02cc349dfbaa14bc97a0251fe14d9d6c611 by Thomas L=C3=BCbking. Committed on 19/08/2013 at 22:09. Pushed by luebking into branch 'thomas_attachment_layout'. other attachment changes M +94 -52 src/Gui/AttachmentView.cpp M +7 -1 src/Gui/AttachmentView.h http://commits.kde.org/trojita/abffc02cc349dfbaa14bc97a0251fe14d9d6c611 diff --git a/src/Gui/AttachmentView.cpp b/src/Gui/AttachmentView.cpp index e0d81e3..3e4c226 100644 --- a/src/Gui/AttachmentView.cpp +++ b/src/Gui/AttachmentView.cpp @@ -30,6 +30,7 @@ #include "Imap/Model/Utils.h" = #include +#include #include #include #include @@ -39,6 +40,8 @@ #include #include #include +#include +#include #include #include #if QT_VERSION >=3D QT_VERSION_CHECK(5, 0, 0) @@ -52,41 +55,68 @@ namespace Gui = AttachmentView::AttachmentView(QWidget *parent, Imap::Network::MsgPartNetA= ccessManager *manager, const QModelIndex &partIndex, MessageView *= messageView, QWidget *contentWidget): - QFrame(parent), m_partIndex(partIndex), m_downloadButton(0), m_message= View(messageView), m_downloadAttachment(0), + QFrame(parent), m_partIndex(partIndex), m_messageView(messageView), m_= downloadAttachment(0), m_openAttachment(0), m_showHideAttachment(0), m_netAccess(manager), m_= tmpFile(0), m_contentWidget(contentWidget) { - QVBoxLayout *contentLayout =3D new QVBoxLayout(this); - QWidget *attachmentControls =3D new QWidget(); - contentLayout->addWidget(attachmentControls); - if (m_contentWidget) { - contentLayout->addWidget(m_contentWidget); - } + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + setFrameStyle(QFrame::NoFrame); = - QHBoxLayout *layout =3D new QHBoxLayout(attachmentControls); + QStyleOption opt; + opt.initFrom(this); // not actually required by styles may assume the = parameter and segfault otherwise + + const int padding =3D style()->pixelMetric(QStyle::PM_DefaultFrameWidt= h, &opt, this); + setContentsMargins(padding, 0, padding, 0); + + QHBoxLayout *layout =3D new QHBoxLayout(); + layout->setContentsMargins(0,0,0,0); + + // should be PM_LayoutHorizontalSpacing, but is not implemented by man= y Qt4 styles -including oxygen- for other conflicts + const int spacing =3D style()->pixelMetric(QStyle::PM_DefaultLayoutSpa= cing, &opt, this); + layout->setSpacing(0); = // Icon on the left - QLabel *lbl =3D new QLabel(); - static const QSize iconSize(22, 22); + m_icon =3D new QToolButton(this); + m_icon->setAttribute(Qt::WA_NoMousePropagation, false); // inform us f= or DnD + m_icon->setAutoRaise(true); + m_icon->setIconSize(QSize(22,22)); + m_icon->setToolButtonStyle(Qt::ToolButtonIconOnly); + + m_menu =3D new QMenu(this); + m_downloadAttachment =3D m_menu->addAction(loadIcon(QLatin1String("doc= ument-save-as")), tr("Download")); + m_openAttachment =3D m_menu->addAction(tr("Open Directly")); + connect(m_downloadAttachment, SIGNAL(triggered()), this, SLOT(slotDown= loadAttachment())); + connect(m_openAttachment, SIGNAL(triggered()), this, SLOT(slotOpenAtta= chment())); + if (m_contentWidget) { + m_showHideAttachment =3D m_menu->addAction(loadIcon(QLatin1String(= "view-preview")), tr("Show Preview")); + m_showHideAttachment->setCheckable(true); + m_showHideAttachment->setChecked(!m_contentWidget->isHidden()); + connect(m_showHideAttachment, SIGNAL(triggered(bool)), m_contentWi= dget, SLOT(setVisible(bool))); + } + + m_icon->setDefaultAction(m_downloadAttachment); = QString mimeDescription =3D partIndex.data(Imap::Mailbox::RolePartMime= Type).toString(); QString rawMime =3D mimeDescription; QMimeType mimeType =3D QMimeDatabase().mimeTypeForName(mimeDescription= ); if (mimeType.isValid() && !mimeType.isDefault()) { mimeDescription =3D mimeType.comment(); - QIcon icon =3D QIcon::fromTheme(mimeType.iconName(), - QIcon::fromTheme(mimeType.genericIco= nName(), loadIcon(QLatin1String("mail-attachment"))) - ); - lbl->setPixmap(icon.pixmap(iconSize)); + QIcon icn =3D QIcon::fromTheme(mimeType.iconName(), + QIcon::fromTheme(mimeType.genericIcon= Name(), loadIcon(QLatin1String("mail-attachment"))) + ); + m_icon->setIcon(icn); } else { - lbl->setPixmap(loadIcon(QLatin1String("mail-attachment")).pixmap(i= conSize)); + m_icon->setIcon(loadIcon(QLatin1String("mail-attachment"))); } - layout->addWidget(lbl); + layout->addWidget(m_icon); + + // space between icon and label + layout->addSpacing(spacing); = - QWidget *labelArea =3D new QWidget(); - QVBoxLayout *subLayout =3D new QVBoxLayout(labelArea); + QVBoxLayout *subLayout =3D new QVBoxLayout; + subLayout->setContentsMargins(0,0,0,0); // The file name shall be mouse-selectable - lbl =3D new QLabel(); + QLabel *lbl =3D new QLabel(this); lbl->setTextFormat(Qt::PlainText); lbl->setText(partIndex.data(Imap::Mailbox::RolePartFileName).toString(= )); lbl->setTextInteractionFlags(Qt::TextSelectableByMouse); @@ -98,43 +128,40 @@ AttachmentView::AttachmentView(QWidget *parent, Imap::= Network::MsgPartNetAccessM if (rawMime !=3D mimeDescription) { lbl->setToolTip(rawMime); } - QFont f =3D lbl->font(); + QFont f(lbl->font()); f.setItalic(true); - f.setPointSizeF(f.pointSizeF() * 0.8); + if (f.pointSize() > -1) // don't try the below on pixel fonts ever. + f.setPointSizeF(f.pointSizeF() * 0.8); lbl->setFont(f); subLayout->addWidget(lbl); - layout->addWidget(labelArea); - layout->addStretch(); - - // Download/Open buttons - m_downloadButton =3D new QToolButton(); - m_downloadButton->setPopupMode(QToolButton::MenuButtonPopup); - m_downloadButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed= ); - m_downloadButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - - QMenu *menu =3D new QMenu(this); - m_downloadAttachment =3D menu->addAction(loadIcon(QLatin1String("docum= ent-save-as")), tr("Download")); - m_openAttachment =3D menu->addAction(tr("Open Directly")); - connect(m_downloadAttachment, SIGNAL(triggered()), this, SLOT(slotDown= loadAttachment())); - connect(m_openAttachment, SIGNAL(triggered()), this, SLOT(slotOpenAtta= chment())); - if (m_contentWidget) { - m_showHideAttachment =3D menu->addAction(loadIcon(QLatin1String("v= iew-preview")), tr("Show Preview")); - m_showHideAttachment->setCheckable(true); - m_showHideAttachment->setChecked(!m_contentWidget->isHidden()); - connect(m_showHideAttachment, SIGNAL(triggered(bool)), m_contentWi= dget, SLOT(setVisible(bool))); - } + layout->addLayout(subLayout); = - m_downloadButton->setMenu(menu); - m_downloadButton->setDefaultAction(m_downloadAttachment); + // space between label and arrow + layout->addSpacing(spacing); = - layout->addWidget(m_downloadButton); - setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - setFrameStyle(QFrame::StyledPanel | QFrame::Raised); + // Arrow + QToolButton *arrow =3D new QToolButton(this); + connect(arrow, SIGNAL(pressed()), SLOT(showMenu())); + arrow->setArrowType(Qt::DownArrow); + arrow->setAutoRaise(true); + + layout->addWidget(arrow); + + // push to left against non expanding labels + layout->addStretch(100); + + QVBoxLayout *contentLayout =3D new QVBoxLayout(this); + contentLayout->addLayout(layout); + if (m_contentWidget) { + contentLayout->addWidget(m_contentWidget); + } } = void AttachmentView::slotDownloadAttachment() { - m_downloadButton->setEnabled(false); + QIcon icn =3D m_icon->icon(); // set to the default action by ::setEna= bled + m_downloadAttachment->setEnabled(false); + m_icon->setIcon(icn); = Imap::Network::FileDownloadManager *manager =3D new Imap::Network::Fil= eDownloadManager(this, m_netAccess, m_partIndex); connect(manager, SIGNAL(fileNameRequested(QString*)), this, SLOT(slotF= ileNameRequested(QString*))); @@ -180,7 +207,9 @@ void AttachmentView::slotFileNameRequested(QString *fil= eName) = void AttachmentView::enableDownloadAgain() { - m_downloadButton->setEnabled(true); + QIcon icn =3D m_icon->icon(); // set to the default action by ::setEna= bled + m_downloadAttachment->setEnabled(true); + m_icon->setIcon(icn); } = void AttachmentView::onOpenFailed() @@ -206,13 +235,26 @@ void AttachmentView::openDownloadedAttachment() m_openAttachment->setEnabled(true); } = +void AttachmentView::showMenu() +{ + static_cast(sender())->setDown(false); + QPoint p =3D QCursor::pos(); + p.rx() -=3D m_menu->width()/2; + m_menu->popup(p); +} + void AttachmentView::mousePressEvent(QMouseEvent *event) { - QWidget *child =3D childAt(event->pos()); - if (child =3D=3D m_downloadButton) { - // We shouldn't really interfere with its operation + m_dragStartPos =3D event->pos(); + QFrame::mousePressEvent(event); +} + +void AttachmentView::mouseMoveEvent(QMouseEvent *event) +{ + QFrame::mouseMoveEvent(event); + + if ((m_dragStartPos - event->pos()).manhattanLength() < QApplication:= :startDragDistance()) return; - } = if (m_partIndex.data(Imap::Mailbox::RoleMessageUid) =3D=3D 0) { return; diff --git a/src/Gui/AttachmentView.h b/src/Gui/AttachmentView.h index 7b54530..8ae5387 100644 --- a/src/Gui/AttachmentView.h +++ b/src/Gui/AttachmentView.h @@ -26,6 +26,7 @@ #include #include "Gui/AbstractPartWidget.h" = +class QMenu; class QNetworkReply; class QPushButton; class QTemporaryFile; @@ -60,6 +61,7 @@ public: virtual QString quoteMe() const; virtual void reloadContents(); protected: + virtual void mouseMoveEvent(QMouseEvent *event); virtual void mousePressEvent(QMouseEvent *event); private slots: void slotDownloadAttachment(); @@ -70,22 +72,26 @@ private slots: void slotFileNameRequested(QString *fileName); void enableDownloadAgain(); void onOpenFailed(); + void showMenu(); = private: QPersistentModelIndex m_partIndex; - QToolButton *m_downloadButton; = MessageView *m_messageView; = QAction *m_downloadAttachment; QAction *m_openAttachment; QAction *m_showHideAttachment; + QMenu *m_menu; + QToolButton *m_icon; = Imap::Network::MsgPartNetAccessManager *m_netAccess; = QTemporaryFile *m_tmpFile; QWidget *m_contentWidget; = + QPoint m_dragStartPos; + AttachmentView(const AttachmentView &); // don't implement AttachmentView &operator=3D(const AttachmentView &); // don't implement };