2011-09-23 22:06:21 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2012-01-01 15:29:55 +01:00
|
|
|
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
2011-09-23 22:06:21 +02:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
* ============================================================ */
|
2011-06-06 19:38:37 +02:00
|
|
|
#ifndef BUTTONWITHMENU_H
|
|
|
|
#define BUTTONWITHMENU_H
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
#include "toolbutton.h"
|
2012-02-29 18:33:50 +01:00
|
|
|
#include "qz_namespace.h"
|
2011-09-11 19:15:06 +02:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
class QT_QUPZILLA_EXPORT ButtonWithMenu : public ToolButton
|
2011-06-06 19:38:37 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
struct Item {
|
|
|
|
QString text;
|
|
|
|
QIcon icon;
|
|
|
|
QVariant userData;
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
Item(const QString &a = QString(), const QIcon &b = QIcon()) {
|
2011-06-06 19:38:37 +02:00
|
|
|
text = a;
|
|
|
|
icon = b;
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
bool operator==(const Item &a) {
|
|
|
|
return (a.text == text) && (a.icon.pixmap(16, 16).toImage() == icon.pixmap(16, 16).toImage());
|
2011-06-06 19:38:37 +02:00
|
|
|
}
|
2012-02-28 18:57:05 +01:00
|
|
|
|
|
|
|
bool isEmpty() {
|
|
|
|
return (text.isEmpty() && icon.isNull());
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear() {
|
|
|
|
text = QString();
|
|
|
|
icon = QIcon();
|
|
|
|
userData = QVariant();
|
|
|
|
}
|
2011-06-06 19:38:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
explicit ButtonWithMenu(QWidget* parent = 0);
|
|
|
|
~ButtonWithMenu();
|
|
|
|
|
|
|
|
void addItem(const Item &item);
|
|
|
|
void addItems(const QList<Item> &items);
|
|
|
|
void removeItem(const Item &item);
|
2012-02-28 18:57:05 +01:00
|
|
|
void setCurrentItem(const Item &item, bool emitSignal = true);
|
2011-06-06 19:38:37 +02:00
|
|
|
|
2012-02-28 18:57:05 +01:00
|
|
|
Item currentItem();
|
2011-10-21 23:26:34 +02:00
|
|
|
QList<Item> allItems() { return m_items; }
|
|
|
|
QMenu* menu() const;
|
2011-06-06 19:38:37 +02:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void activeItemChanged(const ButtonWithMenu::Item &item);
|
|
|
|
void itemAdded(const ButtonWithMenu::Item &item);
|
|
|
|
void itemRemoved(const ButtonWithMenu::Item &item);
|
|
|
|
|
|
|
|
public slots:
|
2011-10-21 23:26:34 +02:00
|
|
|
void clearItems();
|
2011-06-06 19:38:37 +02:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void setCurrentItem();
|
2011-10-21 23:26:34 +02:00
|
|
|
void generateMenu();
|
2011-06-06 19:38:37 +02:00
|
|
|
|
|
|
|
private:
|
2011-11-06 17:01:23 +01:00
|
|
|
void wheelEvent(QWheelEvent* event);
|
2011-06-06 19:38:37 +02:00
|
|
|
|
|
|
|
QMenu* m_menu;
|
|
|
|
QList<Item> m_items;
|
2012-02-28 18:57:05 +01:00
|
|
|
Item m_currentItem;
|
2011-06-06 19:38:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(ButtonWithMenu::Item)
|
|
|
|
|
|
|
|
#endif // BUTTONWITHMENU_H
|