summaryrefslogtreecommitdiffstats
path: root/yakuake/src/image_button.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 19:26:02 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 19:26:02 +0000
commitbd2ea3c166a0815f02187a84c7cbf7f7c4b117a3 (patch)
tree88008b1681b6ac25c35296532c34ba72f2f47d2a /yakuake/src/image_button.cpp
downloadyakuake-bd2ea3c166a0815f02187a84c7cbf7f7c4b117a3.tar.gz
yakuake-bd2ea3c166a0815f02187a84c7cbf7f7c4b117a3.zip
Added KDE3 version of Yakuake
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/yakuake@1097626 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'yakuake/src/image_button.cpp')
-rw-r--r--yakuake/src/image_button.cpp181
1 files changed, 181 insertions, 0 deletions
diff --git a/yakuake/src/image_button.cpp b/yakuake/src/image_button.cpp
new file mode 100644
index 0000000..f6253c8
--- /dev/null
+++ b/yakuake/src/image_button.cpp
@@ -0,0 +1,181 @@
+/*
+ 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 2 of the License, or
+ (at your option) any later version.
+*/
+
+/*
+ Copyright (C) 2005 Francois Chazal <neptune3k@free.fr>
+ Copyright (C) 2006-2007 Eike Hein <hein@kde.org>
+*/
+
+
+#include "image_button.h"
+#include "image_button.moc"
+#include "settings.h"
+
+#include <qwhatsthis.h>
+#include <qtimer.h>
+
+#include <kglobalsettings.h>
+
+
+ImageButton::ImageButton(QWidget* parent, const char* name, bool translucency) : TranslucentWidget(parent, name, translucency)
+{
+ state = 0;
+ toggle = false;
+ pressed = false;
+ delay_popup = false;
+
+ popup_menu = NULL;
+ popup_timer = NULL;
+}
+
+ImageButton::~ImageButton()
+{
+}
+
+void ImageButton::setToggleButton(bool toggled)
+{
+ /* Sets the toggling ability. */
+
+ pressed = false;
+ toggle = toggled;
+}
+
+void ImageButton::setToggled(bool enable)
+{
+ if (toggle)
+ {
+ state = 0;
+
+ if (enable)
+ pressed = true;
+ else
+ pressed = false;
+
+ repaint();
+ }
+}
+
+void ImageButton::setPopupMenu(QPopupMenu* menu)
+{
+ popup_menu = menu;
+ popup_timer = new QTimer(this);
+ connect(popup_timer, SIGNAL(timeout()), this, SLOT(showPopupMenu()));
+}
+
+void ImageButton::showPopupMenu()
+{
+ popup_menu->exec(mapToGlobal(QPoint(0, height())));
+}
+
+void ImageButton::setUpPixmap(const QString& path, bool use_alpha_mask)
+{
+ up_pixmap.load(path);
+ resize(up_pixmap.size());
+
+ if (up_pixmap.hasAlphaChannel()) setMask(*up_pixmap.mask());
+
+ if (use_alpha_mask)
+ setUseTranslucency(true);
+ else
+ setMask(QRegion(up_pixmap.rect()));
+}
+
+void ImageButton::setOverPixmap(const QString& path)
+{
+ over_pixmap.load(path);
+}
+
+void ImageButton::setDownPixmap(const QString& path)
+{
+ down_pixmap.load(path);
+}
+
+void ImageButton::enterEvent(QEvent*)
+{
+ state = pressed ? 2 : 1;
+
+ repaint();
+}
+
+void ImageButton::leaveEvent(QEvent*)
+{
+ state = 0;
+
+ if (popup_timer) popup_timer->stop();
+
+ repaint();
+}
+
+void ImageButton::mousePressEvent(QMouseEvent*)
+{
+ if (QWhatsThis::inWhatsThisMode()) return;
+
+ state = 2;
+
+ if (popup_timer) popup_timer->stop();
+
+ repaint();
+
+ if (popup_menu)
+ {
+ if (delay_popup)
+ popup_timer->start(600, true);
+ else
+ popup_menu->exec(mapToGlobal(QPoint(0, height())));
+ }
+}
+
+void ImageButton::mouseReleaseEvent(QMouseEvent*)
+{
+ if (QWhatsThis::inWhatsThisMode()) return;
+
+ // Don't process event if press and release didn't
+ // occur within the button.
+ if (!state > 0) return;
+
+ state = toggle ? 0 : 1;
+ pressed = toggle ? !pressed : false;
+
+ if (popup_timer) popup_timer->stop();
+
+ repaint();
+
+ if (toggle)
+ emit toggled(pressed);
+ else
+ emit clicked();
+}
+
+void ImageButton::paintEvent(QPaintEvent*)
+{
+ QPainter painter(this);
+
+ erase();
+
+ if (!useTranslucency())
+ painter.fillRect(0, 0, width(), height(), Settings::skinbgcolor());
+
+ switch (state)
+ {
+ case 0:
+ if (pressed)
+ painter.drawPixmap(0, 0, down_pixmap);
+ else
+ painter.drawPixmap(0, 0, up_pixmap);
+ break;
+
+ case 1:
+ painter.drawPixmap(0, 0, over_pixmap);
+ break;
+
+ case 2:
+ painter.drawPixmap(0, 0, down_pixmap);
+ break;
+ }
+
+ painter.end();
+}