1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-23 02:32:10 +02:00
falkonOfficial/src/lib/tools/toolbutton.h
David Rosca 6bdc6f90ce [ToolButton] Use QImage for multiIcon
Instead of 4 separate QPixmaps, use just one QImage and paint only
the current part (according to button state) of the image on button.
2014-04-24 11:05:41 +02:00

103 lines
3.1 KiB
C++

/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef TOOLBUTTON_H
#define TOOLBUTTON_H
#include <QToolButton>
#include <QTimer>
#include "qzcommon.h"
class QUPZILLA_EXPORT ToolButton : public QToolButton
{
Q_OBJECT
Q_PROPERTY(QSize fixedsize READ size WRITE setFixedSize)
Q_PROPERTY(int fixedwidth READ width WRITE setFixedWidth)
Q_PROPERTY(int fixedheight READ height WRITE setFixedHeight)
Q_PROPERTY(QImage multiIcon READ multiIcon WRITE setMultiIcon)
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
Q_PROPERTY(QString themeIcon READ themeIcon WRITE setThemeIcon)
public:
explicit ToolButton(QWidget* parent = 0);
// MultiIcon - Image containing pixmaps for all button states
QImage multiIcon() const;
void setMultiIcon(const QImage &image);
// ThemeIcon - Standard QToolButton with theme icon
QString themeIcon() const;
void setThemeIcon(const QString &icon);
// Icon - Standard QToolButton with icon
QIcon icon() const;
void setIcon(const QIcon &icon);
// Menu - Menu is handled in ToolButton and is not passed to QToolButton
// There won't be menu indicator shown in the button
// QToolButton::MenuButtonPopup is not supported
QMenu* menu() const;
void setMenu(QMenu* menu);
// Align the right corner of menu to the right corner of button
bool showMenuInside() const;
void setShowMenuInside(bool enable);
// Set the button to look as it was in toolbar
// (it now only sets the correct icon size)
bool toolbarButtonLook() const;
void setToolbarButtonLook(bool enable);
signals:
void middleMouseClicked();
void controlClicked();
void doubleClicked();
// It is needed to use these signals with ShowMenuInside
void aboutToShowMenu();
void aboutToHideMenu();
private slots:
void menuAboutToHide();
void showMenu();
protected:
void mousePressEvent(QMouseEvent* e);
void mouseReleaseEvent(QMouseEvent* e);
void mouseDoubleClickEvent(QMouseEvent* e);
void paintEvent(QPaintEvent* e);
private:
QImage m_multiIcon;
QString m_themeIcon;
QTimer m_pressTimer;
QMenu* m_menu;
enum Options {
MultiIconOption = 1,
ShowMenuInsideOption = 2,
ToolBarLookOption = 4
};
Q_DECLARE_FLAGS(OptionsFlags, Options)
OptionsFlags m_options;
};
#endif // TOOLBUTTON_H