KontactInterface

summary.cpp
1/*
2 This file is part of the KDE Kontact Plugin Interface Library.
3
4 SPDX-FileCopyrightText: 2003 Cornelius Schumacher <schumacher@kde.org>
5 SPDX-FileCopyrightText: 2003 Daniel Molkentin <molkentin@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#include "summary.h"
11using namespace Qt::Literals::StringLiterals;
12
13#include <QDrag>
14#include <QDragEnterEvent>
15#include <QDropEvent>
16#include <QFont>
17#include <QFontDatabase>
18#include <QHBoxLayout>
19#include <QIcon>
20#include <QLabel>
21#include <QMimeData>
22#include <QMouseEvent>
23#include <QPainter>
24#include <QPixmap>
25#include <QStyle>
26
27using namespace KontactInterface;
28
29//@cond PRIVATE
30namespace KontactInterface
31{
32class SummaryMimeData : public QMimeData
33{
34 Q_OBJECT
35public:
36 bool hasFormat(const QString &format) const override
37 {
38 return format == "application/x-kontact-summary"_L1;
39 }
40};
41}
42//@endcond
43
44//@cond PRIVATE
45class Q_DECL_HIDDEN Summary::SummaryPrivate
46{
47public:
48 QPoint mDragStartPoint;
49};
50//@endcond
51
53 : QWidget(parent)
54 , d(new SummaryPrivate)
55{
57 setAcceptDrops(true);
58}
59
60Summary::~Summary() = default;
61
63{
64 return 1;
65}
66
67QWidget *Summary::createHeader(QWidget *parent, const QString &iconname, const QString &heading)
68{
69 auto box = new QWidget(parent);
70 auto hbox = new QHBoxLayout(box);
71 hbox->setContentsMargins({});
72 hbox->setSpacing(0);
73 box->setAutoFillBackground(true);
74
75 QIcon icon = QIcon::fromTheme(iconname);
76
77 auto label = new QLabel(box);
78 hbox->addWidget(label);
79 label->setPixmap(icon.pixmap(style()->pixelMetric(QStyle::PM_ToolBarIconSize)));
80
81 label->setFixedSize(label->sizeHint());
82 label->setAcceptDrops(true);
83
84 label = new QLabel(heading, box);
85 hbox->addWidget(label);
86 label->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
87
88 box->setMaximumHeight(box->minimumSizeHint().height());
89
90 return box;
91}
92
94{
95 return {};
96}
97
99{
100}
101
103{
104 Q_UNUSED(force)
105}
106
107void Summary::mousePressEvent(QMouseEvent *event)
108{
109 d->mDragStartPoint = event->pos();
110
112}
113
114void Summary::mouseMoveEvent(QMouseEvent *event)
115{
116 if ((event->buttons() & Qt::LeftButton) && (event->pos() - d->mDragStartPoint).manhattanLength() > 4) {
117 auto drag = new QDrag(this);
118 drag->setMimeData(new SummaryMimeData());
119 drag->setObjectName("SummaryWidgetDrag"_L1);
120
121 QPixmap pm = grab();
122 if (pm.width() > 300) {
124 }
125
126 QPainter painter;
127 painter.begin(&pm);
129 painter.drawRect(0, 0, pm.width(), pm.height());
130 painter.end();
131 drag->setPixmap(pm);
132 drag->exec(Qt::MoveAction);
133 } else {
135 }
136}
137
138void Summary::dragEnterEvent(QDragEnterEvent *event)
139{
140 if (event->mimeData()->hasFormat(QStringLiteral("application/x-kontact-summary"))) {
141 event->acceptProposedAction();
142 }
143}
144
145void Summary::dropEvent(QDropEvent *event)
146{
147 const int alignment = (event->position().y() < (height() / 2) ? Qt::AlignTop : Qt::AlignBottom);
148 Q_EMIT summaryWidgetDropped(this, event->source(), alignment);
149}
150
151#include <summary.moc>
152
153#include "moc_summary.cpp"
Base class for summary widgets in Kontact.
Definition summary.h:27
~Summary() override
Destroys the summary widget.
virtual QStringList configModules() const
Returns a list of names identifying configuration modules for this summary widget.
Definition summary.cpp:93
virtual int summaryHeight() const
Returns the logical height of summary widget.
Definition summary.cpp:62
QWidget * createHeader(QWidget *parent, const QString &icon, const QString &heading)
Creates a heading for a typical summary view with an icon and a heading.
Definition summary.cpp:67
Summary(QWidget *parent)
Creates a new summary widget.
Definition summary.cpp:52
void summaryWidgetDropped(QWidget *target, QObject *object, int alignment)
virtual void updateSummary(bool force=false)
This method is called if the displayed information should be updated.
Definition summary.cpp:102
virtual void configChanged()
This method is called whenever the configuration has been changed.
Definition summary.cpp:98
QFont systemFont(SystemFont type)
QPixmap pixmap(QWindow *window, const QSize &size, Mode mode, State state) const const
QIcon fromTheme(const QString &name)
QImage scaled(const QSize &size, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const const
Q_EMITQ_EMIT
QObject * parent() const const
bool begin(QPaintDevice *device)
void drawRect(const QRect &rectangle)
bool end()
void setPen(Qt::PenStyle style)
QPixmap fromImage(QImage &&image, Qt::ImageConversionFlags flags)
int height() const const
QImage toImage() const const
int width() const const
PM_ToolBarIconSize
AlignLeft
KeepAspectRatio
MoveAction
LeftButton
SmoothTransformation
QWidget(QWidget *parent, Qt::WindowFlags f)
void setAcceptDrops(bool on)
virtual bool event(QEvent *event) override
void setFont(const QFont &)
QPixmap grab(const QRect &rectangle)
virtual void mouseMoveEvent(QMouseEvent *event)
virtual void mousePressEvent(QMouseEvent *event)
QStyle * style() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:55 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.