File: katetabbutton.h

package info (click to toggle)
kate 4:18.08.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 30,500 kB
  • sloc: xml: 87,988; cpp: 38,094; ansic: 1,805; sh: 95; makefile: 23
file content (135 lines) | stat: -rw-r--r-- 4,113 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*   This file is part of the KDE project
 *
 *   Copyright (C) 2014 Dominik Haumann <dhauumann@kde.org>
 *
 *   This library is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU Library General Public
 *   License as published by the Free Software Foundation; either
 *   version 2 of the License, or (at your option) any later version.
 *
 *   This library is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *   Library General Public License for more details.
 *
 *   You should have received a copy of the GNU Library General Public License
 *   along with this library; see the file COPYING.LIB.  If not, write to
 *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *   Boston, MA 02110-1301, USA.
 */

#ifndef KATE_TAB_BUTTON
#define KATE_TAB_BUTTON

#include <QAbstractButton>
#include <QUrl>

class QPropertyAnimation;

class TabCloseButton : public QAbstractButton
{
    Q_OBJECT

public:
    // constructor
    TabCloseButton(QWidget * parent = nullptr);
    // paint close button depending on its state
    void paintEvent(QPaintEvent *event) override;
    // returns the size hint depending on the style
    QSize sizeHint() const override;

protected:
    void enterEvent(QEvent *event) override;
    void leaveEvent(QEvent *event) override;
};

/**
 * A \p KateTabButton represents a button on the tab bar. It can either be
 * \e activated or \e deactivated. If the state is \e deactivated it will
 * be @e activated when the mouse is pressed. It then emits the signal
 * @p activated(). The \p KateTabButton's text can be set with \p setText()
 * and an additional icon can be shown with \p setIcon().
 *
 * @author Dominik Haumann
 */
class KateTabButton : public QAbstractButton
{
    Q_OBJECT

public:
    /**
     * Constructs a new tab bar button with \a text and \a parent.
     */
    KateTabButton(const QString &text, QWidget *parent = nullptr);

    /**
     * Returns @e true, if the tabbar is the currently active tab bar.
     */
    bool isActiveTabBar() const;

    /**
     * Check whether a geometry animation is running.
     */
    bool geometryAnimationRunning() const;

    /**
     * The URL of the document this tab represents.
     * \since 17.08
     */
    QUrl url() const;

    /**
     * Sets the URL of the document this tab represents.
     * \since 17.08
     */
    void setUrl(const QUrl &url);

public Q_SLOTS:
    /**
     * Animate the button's geometry from @p startGeom to @p endGeom
     * with linear interpolation.
     */
    void setAnimatedGeometry(const QRect & startGeom, const QRect & endGeom);

Q_SIGNALS:
    /**
     * Emitted whenever the button changes state from deactivated to activated,
     * or when the button was clicked although it was already active.
     * @param tabbutton the pressed button (this)
     */
    void activated(KateTabButton *tabbutton);

    /**
     * Emitted whenever the user wants to close the tab button.
     * @param tabbutton the button that emitted this signal
     */
    void closeRequest(KateTabButton *tabbutton);

protected Q_SLOTS:
    void closeButtonClicked();

protected:
    /** paint eyecandy rectangles around the button */
    void paintEvent(QPaintEvent *ev) override;
    /** activate, and for drag & drop */
    void mousePressEvent(QMouseEvent *ev) override;
    /** possibly start drag event */
    void mouseMoveEvent(QMouseEvent *event) override;
    /** eat double click events */
    void mouseDoubleClickEvent(QMouseEvent *event) override;
    /** trigger repaint on hover enter event */
    void enterEvent(QEvent *event) override;
    /** trigger repaint on hover leave event */
    void leaveEvent(QEvent *event) override;
    /** track geometry changes to trigger proper repaint*/
    void moveEvent(QMoveEvent *event) override;

private:
    TabCloseButton * m_closeButton;
    QPropertyAnimation * m_geometryAnimation;
    QPoint m_mouseDownPosition;
    QUrl m_url;
};

#endif