diff options
Diffstat (limited to 'malloryclient/mallorybutton.cpp')
-rw-r--r-- | malloryclient/mallorybutton.cpp | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/malloryclient/mallorybutton.cpp b/malloryclient/mallorybutton.cpp new file mode 100644 index 0000000..ede2e7b --- /dev/null +++ b/malloryclient/mallorybutton.cpp @@ -0,0 +1,195 @@ +// +// C++ Implementation: mallorybutton +// +// Description: +// +// +// Author: Remi Villatel <maxilys@tele2.fr>, (C) 2005 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include <qtooltip.h> +#include <qpainter.h> +#include <qpixmap.h> + +#include "enums.h" +#include "mallorybutton.h" +#include "malloryhandler.h" +#include "pixmaps.h" + +#include "embeddata.h" + +MalloryButton::MalloryButton(MalloryClient *parent, const char *name, const QString& tip, ButtonType type) : QButton(parent->widget(), name), m_client(parent), m_lastMouse(0), m_type(type), hover(false), isOnAllDesktops(false), isMaximized(false) +{ + QToolTip::add(this, tip); + setCursor(arrowCursor); + setBackgroundMode(NoBackground); + setFixedSize(MalloryHandler::buttonSize(), MalloryHandler::buttonSize()); +} + + +MalloryButton::~MalloryButton() +{ +} + +void MalloryButton::setTipText(const QString &tip) +{ + QToolTip::remove(this); + QToolTip::add(this, tip); +} + +QSize MalloryButton::sizeHint() const // MXLS +{ + return QSize(MalloryHandler::buttonSize(), MalloryHandler::buttonSize()); +} + +void MalloryButton::enterEvent(QEvent *e) +{ + hover = true; + repaint(false); + QButton::enterEvent(e); +} + +void MalloryButton::leaveEvent(QEvent *e) +{ + hover = false; + repaint(false); + QButton::enterEvent(e); +} + +void MalloryButton::mousePressEvent(QMouseEvent *e) +{ + m_lastMouse = e->button(); + QMouseEvent me(e->type(), e->pos(), e->globalPos(), LeftButton, e->state()); + QButton::mousePressEvent(&me); +} + +void MalloryButton::mouseReleaseEvent(QMouseEvent *e) +{ + m_lastMouse = e->button(); + QMouseEvent me(e->type(), e->pos(), e->globalPos(), LeftButton, e->state()); + QButton::mouseReleaseEvent(&me); +} + +void MalloryButton::drawButton(QPainter *painter) +{ + if (!MalloryHandler::initialized()) + return; + + bool active = m_client->isActive(); + int buttonSize = MalloryHandler::buttonSize(); + + int ofx = (buttonSize-16)/2; + int ofy = ofx; + + // Crush the bug the hard way! + if (ofy < 2) + ofy = 2; + + QPixmap pufferPixmap; + pufferPixmap.resize(buttonSize, buttonSize); + + QPainter pufferPainter(&pufferPixmap); + pufferPainter.drawPixmap(0, 0, active ? *Pixmaps::active_button_ground : *Pixmaps::inactive_button_ground); + + if (m_type == ButtonMenu) + { + QPixmap menu_icon = m_client->icon().pixmap(QIconSet::Small, QIconSet::Normal); + pufferPainter.drawPixmap(ofx, ofy, menu_icon); + } + else + { + // Paint the little icon on the buttons. + // Lotsa trouble with this! Stupid scope! + + if (hover && !isDown()) + { + // Hover + if (m_type == ButtonHelp) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_help_hover : *Pixmaps::inactive_help_hover); + else if (m_type == ButtonMax) + { + if (isMaximized) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_restore_hover : *Pixmaps::inactive_restore_hover); + else + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_max_hover : *Pixmaps::inactive_max_hover); + } + else if (m_type == ButtonMin) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_min_hover : *Pixmaps::inactive_min_hover); + else if (m_type == ButtonClose) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_close_hover : *Pixmaps::inactive_close_hover); + else if (m_type == ButtonOnAllDesktops) + { + if (isOnAllDesktops) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_unsticky_hover : *Pixmaps::inactive_unsticky_hover); + else + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_sticky_hover : *Pixmaps::inactive_sticky_hover); + } + else if (m_type == ButtonAbove) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_above_hover : *Pixmaps::inactive_above_hover); + else if (m_type == ButtonBelow) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_below_hover : *Pixmaps::inactive_below_hover); + } + else if (isDown()) + { + // Sunken + if (m_type == ButtonHelp) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_help_sunken : *Pixmaps::inactive_help_sunken); + else if (m_type == ButtonMax) + { + if (isMaximized) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_restore_sunken : *Pixmaps::inactive_restore_sunken); + else + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_max_sunken : *Pixmaps::inactive_max_sunken); + } + else if (m_type == ButtonMin) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_min_sunken : *Pixmaps::inactive_min_sunken); + else if (m_type == ButtonClose) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_close_sunken : *Pixmaps::inactive_close_sunken); + else if (m_type == ButtonOnAllDesktops) + { + if (isOnAllDesktops) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_unsticky_sunken : *Pixmaps::inactive_unsticky_sunken); + else + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_sticky_sunken : *Pixmaps::inactive_sticky_sunken); + } + else if (m_type == ButtonAbove) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_above_sunken : *Pixmaps::inactive_above_sunken); + else if (m_type == ButtonBelow) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_below_sunken : *Pixmaps::inactive_below_sunken); + } + else + { + // Normal + if (m_type == ButtonHelp) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_help_normal : *Pixmaps::inactive_help_normal); + else if (m_type == ButtonMax) + { + if (isMaximized) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_restore_normal : *Pixmaps::inactive_restore_normal); + else + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_max_normal : *Pixmaps::inactive_max_normal); + } + else if (m_type == ButtonMin) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_min_normal : *Pixmaps::inactive_min_normal); + else if (m_type == ButtonClose) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_close_normal : *Pixmaps::inactive_close_normal); + else if (m_type == ButtonOnAllDesktops) + { + if (isOnAllDesktops) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_unsticky_normal : *Pixmaps::inactive_unsticky_normal); + else + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_sticky_normal : *Pixmaps::inactive_sticky_normal); + } + else if (m_type == ButtonAbove) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_above_normal : *Pixmaps::inactive_above_normal); + else if (m_type == ButtonBelow) + pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_below_normal : *Pixmaps::inactive_below_normal); + } + } + pufferPainter.end(); + painter->drawPixmap(0, 0, pufferPixmap); +} +#include "mallorybutton.moc" |