File indexing completed on 2024-04-28 17:05:54

0001 /*
0002     SPDX-FileCopyrightText: 2002 Shie Erlich <erlich@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2002 Rafi Yanai <yanai@users.sourceforge.net>
0004     SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef KRSQUEEZEDTEXTLABEL_H
0010 #define KRSQUEEZEDTEXTLABEL_H
0011 
0012 // QtGui
0013 #include <QDragEnterEvent>
0014 #include <QMouseEvent>
0015 #include <QResizeEvent>
0016 
0017 #include <KWidgetsAddons/KSqueezedTextLabel>
0018 
0019 class QMouseEvent;
0020 class QDragEnterEvent;
0021 class QPaintEvent;
0022 
0023 /**
0024 This class overloads KSqueezedTextLabel and simply adds a clicked signal,
0025 so that users will be able to click the label and switch focus between panels.
0026 
0027 NEW: a special setText() method allows to choose which part of the string should
0028      be displayed (example: make sure that search results won't be cut out)
0029 */
0030 class KrSqueezedTextLabel : public KSqueezedTextLabel
0031 {
0032     Q_OBJECT
0033 public:
0034     explicit KrSqueezedTextLabel(QWidget *parent = nullptr);
0035     ~KrSqueezedTextLabel() override;
0036 
0037 public slots:
0038     void setText(const QString &text, int index = -1, int length = -1);
0039 
0040 signals:
0041     void clicked(QMouseEvent *); /**< emitted when someone clicks on the label */
0042 
0043 protected:
0044     void resizeEvent(QResizeEvent *) override
0045     {
0046         squeezeTextToLabel(_index, _length);
0047     }
0048     void mousePressEvent(QMouseEvent *e) override;
0049     void paintEvent(QPaintEvent *e) override;
0050     void squeezeTextToLabel(int index = -1, int length = -1);
0051 
0052     QString fullText;
0053 
0054 private:
0055     int _index, _length;
0056 };
0057 
0058 #endif