katetabbutton.h 4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*   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

24
#include <QPushButton>
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
25
#include <QUrl>
26

27 28
class QPropertyAnimation;

29
class TabCloseButton : public QPushButton
30 31 32 33 34
{
    Q_OBJECT

public:
    // constructor
35
    TabCloseButton(QWidget *parent = nullptr);
36
    // paint close button depending on its state
Kevin Funk's avatar
Kevin Funk committed
37
    void paintEvent(QPaintEvent *event) override;
38
    // returns the size hint depending on the style
Kevin Funk's avatar
Kevin Funk committed
39
    QSize sizeHint() const override;
40 41

protected:
Kevin Funk's avatar
Kevin Funk committed
42 43
    void enterEvent(QEvent *event) override;
    void leaveEvent(QEvent *event) override;
44 45
};

46 47 48 49
/**
 * 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
Dominik Haumann's avatar
Dominik Haumann committed
50 51
 * @p activated(). The \p KateTabButton's text can be set with \p setText()
 * and an additional icon can be shown with \p setIcon().
52 53 54
 *
 * @author Dominik Haumann
 */
55
class KateTabButton : public QAbstractButton
56 57 58 59 60
{
    Q_OBJECT

public:
    /**
Dominik Haumann's avatar
Dominik Haumann committed
61
     * Constructs a new tab bar button with \a text and \a parent.
62
     */
63
    KateTabButton(const QString &text, QWidget *parent = nullptr);
64

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

70 71 72 73 74
    /**
     * Check whether a geometry animation is running.
     */
    bool geometryAnimationRunning() const;

Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
75 76 77 78 79 80 81 82 83 84 85 86
    /**
     * 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);

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

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

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

108
protected Q_SLOTS:
109
    void closeButtonClicked();
110 111 112

protected:
    /** paint eyecandy rectangles around the button */
113 114 115 116 117
    void paintEvent(QPaintEvent *ev) override;
    /** activate, and for drag & drop */
    void mousePressEvent(QMouseEvent *ev) override;
    /** possibly start drag event */
    void mouseMoveEvent(QMouseEvent *event) override;
118
    /** eat double click events */
119
    void mouseDoubleClickEvent(QMouseEvent *event) override;
120
    /** trigger repaint on hover enter event */
121
    void enterEvent(QEvent *event) override;
122
    /** trigger repaint on hover leave event */
123
    void leaveEvent(QEvent *event) override;
124
    /** track geometry changes to trigger proper repaint*/
125
    void moveEvent(QMoveEvent *event) override;
126 127

private:
128 129
    TabCloseButton *m_closeButton;
    QPropertyAnimation *m_geometryAnimation;
130
    QPoint m_mouseDownPosition;
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
131
    QUrl m_url;
132 133 134
};

#endif