Changeset View
Changeset View
Standalone View
Standalone View
lib/squeezedlinklabel.h
- This file was added.
| 1 | /* | ||||
|---|---|---|---|---|---|
| 2 | Gwenview: an image viewer | ||||
| 3 | Copyright 2018 Henrik Fehlauer <rkflx@lab12.net> | ||||
| 4 | | ||||
| 5 | This program is free software; you can redistribute it and/or | ||||
| 6 | modify it under the terms of the GNU General Public License | ||||
| 7 | as published by the Free Software Foundation; either version 2 | ||||
| 8 | of the License, or (at your option) any later version. | ||||
| 9 | | ||||
| 10 | This program is distributed in the hope that it will be useful, | ||||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| 13 | GNU General Public License for more details. | ||||
| 14 | | ||||
| 15 | You should have received a copy of the GNU General Public License | ||||
| 16 | along with this program; if not, write to the Free Software | ||||
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| 18 | | ||||
| 19 | */ | ||||
| 20 | #ifndef SQUEEZEDLINKLABEL_H | ||||
| 21 | #define SQUEEZEDLINKLABEL_H | ||||
| 22 | | ||||
| 23 | #include <lib/gwenviewlib_export.h> | ||||
| 24 | | ||||
| 25 | #include <QLabel> | ||||
| 26 | | ||||
| 27 | class SqueezedLinkLabelPrivate; | ||||
| 28 | | ||||
| 29 | /** | ||||
| 30 | * KSqueezedTextLabel breaks eliding rich text content, but fixing | ||||
| 31 | * that in QFontMetrics::elidedText in a generic way would be difficult. | ||||
| 32 | * Therefore here we provide our own simplified label which can elide | ||||
| 33 | * single-line links only. | ||||
| 34 | * Since we cannot override KSqueezedTextLabel::squeezeTextToLabel, | ||||
| 35 | * we derive from QLabel instead while still taking inspiration from | ||||
| 36 | * KSqueezedTextLabel. | ||||
| 37 | */ | ||||
| 38 | | ||||
| 39 | class GWENVIEWLIB_EXPORT SqueezedLinkLabel : public QLabel | ||||
| 40 | { | ||||
| 41 | public: | ||||
| 42 | enum LabelType { | ||||
| 43 | PlainText, | ||||
| 44 | Link | ||||
| 45 | }; | ||||
| 46 | | ||||
| 47 | explicit SqueezedLinkLabel(QWidget* parent = nullptr); | ||||
| 48 | | ||||
| 49 | QSize minimumSizeHint() const override; | ||||
| 50 | QSize sizeHint() const override; | ||||
| 51 | | ||||
| 52 | void setText(const QString& text, const QString& linkTarget, const LabelType& labelType = Link); | ||||
| 53 | | ||||
| 54 | protected: | ||||
| 55 | void resizeEvent(QResizeEvent*) override; | ||||
| 56 | | ||||
| 57 | void squeezeTextToLabel(); | ||||
| 58 | | ||||
| 59 | private: | ||||
| 60 | SqueezedLinkLabelPrivate* const d; | ||||
| 61 | }; | ||||
| 62 | | ||||
| 63 | #endif // SQUEEZEDLINKLABEL_H | ||||