From 78bc9664ef5f23a7b405b5d940bc891a0ebbf841 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 1 Feb 2013 17:25:32 -0600 Subject: Fix FTBFS --- lib/kofficeui/tkaction.cpp | 300 -------------------- lib/kofficeui/tkaction.h | 126 --------- lib/kofficeui/tktoolbarbutton.cpp | 532 ------------------------------------ lib/kofficeui/tktoolbarbutton.h | 228 ---------------- lib/kofficeui/ttdeaction.cpp | 300 ++++++++++++++++++++ lib/kofficeui/ttdeaction.h | 126 +++++++++ lib/kofficeui/ttdetoolbarbutton.cpp | 532 ++++++++++++++++++++++++++++++++++++ lib/kofficeui/ttdetoolbarbutton.h | 228 ++++++++++++++++ 8 files changed, 1186 insertions(+), 1186 deletions(-) delete mode 100644 lib/kofficeui/tkaction.cpp delete mode 100644 lib/kofficeui/tkaction.h delete mode 100644 lib/kofficeui/tktoolbarbutton.cpp delete mode 100644 lib/kofficeui/tktoolbarbutton.h create mode 100644 lib/kofficeui/ttdeaction.cpp create mode 100644 lib/kofficeui/ttdeaction.h create mode 100644 lib/kofficeui/ttdetoolbarbutton.cpp create mode 100644 lib/kofficeui/ttdetoolbarbutton.h (limited to 'lib') diff --git a/lib/kofficeui/tkaction.cpp b/lib/kofficeui/tkaction.cpp deleted file mode 100644 index 56c626f8..00000000 --- a/lib/kofficeui/tkaction.cpp +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Kivio - Visual Modelling and Flowcharting - * Copyright (C) 2000 theKompany.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 2 - * 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, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "tkaction.h" -#include "tktoolbarbutton.h" -#include "tkcombobox.h" - -#include -#include - -#include -#include - -#define SET_FOR_ALL_CONTAINER(WIDGET_TYPE,METHOD_NAME,VALUE) \ - for( int id = 0; id < containerCount(); ++id ) { \ - TQWidget* w = container(id); \ - if ( w->inherits("TDEToolBar") ) { \ - TQWidget* r = static_cast(w)->getWidget(itemId(id)); \ - if (qstrcmp(r->name(),"KTToolBarLayout")==0) \ - r = (TQWidget*)r->child("widget"); \ - if ( r && r->inherits(#WIDGET_TYPE) ) { \ - WIDGET_TYPE* b = static_cast(r); \ - b->METHOD_NAME(VALUE); \ - } \ - } \ - } - -TTDEAction::TTDEAction(TQObject* parent, const char* name) -: TDEAction( "", 0, parent, name ) -{ - m_imode = TK::IconOnly; -} - -TTDEAction::~TTDEAction() -{ -} - -int TTDEAction::plug(TQWidget* widget, int index) -{ - if ( widget->inherits("TDEToolBar") ) { - TDEToolBar* bar = static_cast(widget); - int id_ = TDEAction::getToolButtonID(); - TDEInstance *instance; - - if ( parentCollection() ) - instance = parentCollection()->instance(); - else - instance = TDEGlobal::instance(); - - TTDEToolBarButton* b = new TTDEToolBarButton(icon(),plainText(),bar,name(),instance); - // we don't need clicked() and buttonClicked(), do we? - // connect(b,TQT_SIGNAL(clicked()),TQT_SLOT(slotActivated())); - b->setIconMode(m_imode); - initToolBarButton(b); - - bar->insertWidget( id_, 100, b, index ); - addContainer(bar,id_); - connect( bar, TQT_SIGNAL(destroyed()), this, TQT_SLOT(slotDestroyed()) ); - - return containerCount() - 1; - } - return TDEAction::plug(widget,index); -} - -void TTDEAction::initToolBarButton(TTDEToolBarButton* button) -{ - connect(button,TQT_SIGNAL(buttonClicked()),TQT_SLOT(slotActivated())); -} - -TK::IconMode TTDEAction::iconMode() -{ - return m_imode; -} - -void TTDEAction::setIconMode(TK::IconMode mode) -{ - m_imode = mode; - SET_FOR_ALL_CONTAINER(TTDEToolBarButton,setIconMode,mode) -} - -void TTDEAction::setText(const TQString& text) -{ - TDEAction::setText(text); - updateLayout(); -} - -void TTDEAction::setIcon(const TQString& icon) -{ - TDEAction::setIcon(icon); - updateLayout(); -} - -void TTDEAction::updateLayout() -{ - int len = containerCount(); - for( int id = 0; id < len; ++id ) { - TQWidget* w = container( id ); - if (w->inherits("TDEToolBar")) { - TQWidget* r = static_cast(w)->getWidget(itemId(id)); - if (qstrcmp(r->name(),"KTToolBarLayout")==0) { - updateLayout(r); - } - } - } -} - -TQWidget* TTDEAction::createLayout(TQWidget* parent, TQWidget* children) -{ - TQWidget* base = new TQWidget(parent,"KTToolBarLayout"); - TQLabel* textLabel = new TQLabel(base,"text"); - textLabel->setMinimumHeight(1); - TQLabel* pixLabel = new TQLabel(base,"pixmap"); - children->reparent(base,TQPoint(0,0)); - children->setName("widget"); - TQHBoxLayout* layout = new TQHBoxLayout(base,0,3); - layout->setResizeMode(TQLayout::Minimum); - layout->addWidget(textLabel); - layout->addWidget(pixLabel); - layout->addWidget(children,1); - - updateLayout(base); - return base; -} - -void TTDEAction::updateLayout(TQWidget* base) -{ - TQLabel* textLabel = (TQLabel*)base->child("text"); - TQLabel* pixLabel = (TQLabel*)base->child("pixmap"); - TQWidget* w = (TQWidget*)base->child("widget"); - - if (!textLabel || !pixLabel || !w) - return; - - if (!text().isEmpty() && m_imode != TK::IconOnly ) { - textLabel->setText(text()); - textLabel->show(); - } else - textLabel->hide(); - - TQPixmap pix; - if (hasIcon()) - pix = iconSet(KIcon::Small).pixmap(); - - if (!icon().isEmpty()) - pix = BarIcon(icon()); - - if (!pix.isNull() && m_imode != TK::TextOnly) { - pixLabel->setPixmap(pix); - pixLabel->show(); - } else - pixLabel->hide(); - - base->setFixedWidth( w->sizeHint().width() + - (textLabel->isVisible() ? textLabel->sizeHint().width():0) + - (pixLabel->isVisible() ? pixLabel->sizeHint().width():0) ); -} -/******************************************************************************/ -TKBaseSelectAction::TKBaseSelectAction( TQObject* parent, const char* name ) -: TTDEAction(parent,name) -{ - m_current = 0; - m_editable = false; -} - -TKBaseSelectAction::~TKBaseSelectAction() -{ -} - -int TKBaseSelectAction::plug(TQWidget* widget, int index) -{ - if ( widget->inherits("TDEToolBar") ) - { - TDEToolBar* bar = static_cast( widget ); - int id_ = TDEAction::getToolButtonID(); - - TKComboBox* cb = new TKComboBox(m_editable,bar); - initComboBox(cb); - cb->setMinimumWidth( cb->sizeHint().width() ); - TQWidget* base = createLayout(bar,cb); - - bar->insertWidget( id_, 100, base, index ); - addContainer( bar, id_ ); - - connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); - - setCurrentItem(currentItem()); - - return containerCount() - 1; - } - return -1; -} - -int TKBaseSelectAction::currentItem() -{ - return m_current; -} - -void TKBaseSelectAction::initComboBox(TKComboBox* cb) -{ - connect(cb,TQT_SIGNAL(activated(int)),TQT_SLOT(slotActivated(int))); -} - -void TKBaseSelectAction::setEditable(bool editable) -{ - m_editable = editable; - SET_FOR_ALL_CONTAINER(TKComboBox,setEditable,editable) -} - -bool TKBaseSelectAction::isEditable() -{ - return m_editable; -} - -void TKBaseSelectAction::setCurrentItem(int index) -{ - m_current = index; - SET_FOR_ALL_CONTAINER(TKComboBox,setCurrentItem,index) -} - -void TKBaseSelectAction::slotActivated(int id) -{ - if ( m_current == id ) - return; - - m_current = id; - setCurrentItem(id); - activate(id); -} - -void TKBaseSelectAction::activate(int id) -{ - emit activated(id); -} -/******************************************************************************/ -TTDESelectAction::TTDESelectAction( TQObject* parent, const char* name ) -: TKBaseSelectAction(parent,name) -{ -} - -TTDESelectAction::~TTDESelectAction() -{ -} - -void TTDESelectAction::initComboBox(TKComboBox* cb) -{ - TKBaseSelectAction::initComboBox(cb); - connect(cb,TQT_SIGNAL(activated(const TQString&)),TQT_SLOT(slotActivated(const TQString&))); - cb->insertStringList(items()); -} - -void TTDESelectAction::slotActivated(const TQString& text) -{ - emit activated(text); -} - -void TTDESelectAction::setItems(const TQStringList& lst ) -{ - m_list = lst; - m_current = -1; - - SET_FOR_ALL_CONTAINER(TKComboBox,clear, ) - SET_FOR_ALL_CONTAINER(TKComboBox,insertStringList,lst) - - // Disable if empty and not editable - setEnabled ( lst.count() > 0 || m_editable ); -} - -TQStringList TTDESelectAction::items() const -{ - return m_list; -} - -void TTDESelectAction::clear() -{ - SET_FOR_ALL_CONTAINER(TKComboBox,clear, ) -} - -void TTDESelectAction::setEditText(const TQString& text) -{ - SET_FOR_ALL_CONTAINER(TKComboBox,setEditText,text) -} - -#undef SET_FOR_ALL_CONTAINER -#include "tkaction.moc" diff --git a/lib/kofficeui/tkaction.h b/lib/kofficeui/tkaction.h deleted file mode 100644 index 736bb141..00000000 --- a/lib/kofficeui/tkaction.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Kivio - Visual Modelling and Flowcharting - * Copyright (C) 2000 theKompany.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 2 - * 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, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef TKACTION_H -#define TKACTION_H - -#include -#include -#include -namespace TK { - enum IconMode { IconOnly, IconAndText, TextOnly }; -} - -class TTDEToolBarButton; -class TKComboBox; - -class KOFFICEUI_EXPORT TTDEAction : public TDEAction -{ Q_OBJECT - -public: - TTDEAction(TQObject* parent, const char* name); - ~TTDEAction(); - - virtual int plug(TQWidget* widget, int index = -1); - - TK::IconMode iconMode(); - -protected: - virtual void initToolBarButton(TTDEToolBarButton*); - - TQWidget* createLayout(TQWidget* parent, TQWidget* children); - void updateLayout(); - virtual void updateLayout(TQWidget*); - -public slots: - virtual void setIconMode(TK::IconMode); - void setText(const TQString&); - void setIcon(const TQString&); - -private: - TK::IconMode m_imode; - class TTDEActionPrivate; - TTDEActionPrivate *d; -}; -/******************************************************************************/ -class KOFFICEUI_EXPORT TKBaseSelectAction : public TTDEAction -{ Q_OBJECT - -friend class TTDESelectAction; -public: - TKBaseSelectAction(TQObject* parent, const char* name); - ~TKBaseSelectAction(); - - virtual int plug(TQWidget* widget, int index = -1); - - int currentItem(); - bool isEditable(); - - void activate(int); - -protected: - virtual void initComboBox(TKComboBox*); - -public slots: - virtual void setCurrentItem(int index); - virtual void setEditable(bool); - -protected slots: - virtual void slotActivated(int); - -signals: - void activated(int); - -private: - int m_current; - bool m_editable; - class TKBaseSelectActionPrivate; - TKBaseSelectActionPrivate *d; -}; -/******************************************************************************/ -class KOFFICEUI_EXPORT TTDESelectAction : public TKBaseSelectAction -{ Q_OBJECT - -public: - TTDESelectAction(TQObject* parent, const char* name); - ~TTDESelectAction(); - - TQStringList items() const; - -public slots: - virtual void setItems(const TQStringList& ); - virtual void setEditText(const TQString&); - virtual void clear(); - -protected: - virtual void initComboBox(TKComboBox*); - -protected slots: - void slotActivated(const TQString&); - -signals: - void activated(const TQString&); - -private: - TQStringList m_list; - class TTDESelectActionPrivate; - TTDESelectActionPrivate *d; -}; -/******************************************************************************/ -#endif diff --git a/lib/kofficeui/tktoolbarbutton.cpp b/lib/kofficeui/tktoolbarbutton.cpp deleted file mode 100644 index c4c8e27b..00000000 --- a/lib/kofficeui/tktoolbarbutton.cpp +++ /dev/null @@ -1,532 +0,0 @@ -/* - * Kivio - Visual Modelling and Flowcharting - * Copyright (C) 2000 theKompany.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 2 - * 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, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -// Delay in ms before delayed popup pops up -#define POPUP_DELAY 500 - -class TTDEToolBarButton::TTDEToolBarButtonPrivate -{ -public: - TTDEToolBarButtonPrivate() - { - m_iconMode = TK::IconOnly; - m_isPopup = false; - m_isToggle = false; - m_isOn = false; - m_isRaised = false; - m_autoRaised = true; - ignoreNextMousePress = false; - - m_text = TQString(); - m_iconName = TQString(); - m_arrowPressed = false; - m_delayTimer = 0L; - m_popup = 0L; - - m_disabledIconName = TQString(); - m_defaultIconName = TQString(); - - m_instance = TDEGlobal::instance(); - } - - ~TTDEToolBarButtonPrivate() - { - delete m_delayTimer; - m_delayTimer = 0; - } - - bool m_isPopup; - bool m_isToggle; - bool m_isOn; - bool m_isRaised; - bool m_autoRaised; - bool m_arrowPressed; - bool ignoreNextMousePress; - - TQString m_text; - TQString m_iconName; - TQString m_disabledIconName; - TQString m_defaultIconName; - - TK::IconMode m_iconMode; - - TQTimer *m_delayTimer; - TQPopupMenu *m_popup; - - TDEInstance *m_instance; -}; - -TTDEToolBarButton::TTDEToolBarButton( const TQString& icon, const TQString& txt, - TQWidget* parent, const char* name, - TDEInstance *instance ) -: TQToolButton(parent,name) -{ - d = new TTDEToolBarButtonPrivate; - d->m_text = txt; - d->m_instance = instance; - - setFocusPolicy( TQ_NoFocus ); - - connect(this, TQT_SIGNAL(clicked()), TQT_SLOT(slotClicked()) ); - connect(this, TQT_SIGNAL(pressed()), TQT_SLOT(slotPressed()) ); - connect(this, TQT_SIGNAL(released()), TQT_SLOT(slotReleased()) ); - - installEventFilter(this); - - setIcon(icon); - modeChange(); -} - -TTDEToolBarButton::TTDEToolBarButton( const TQPixmap& pixmap, const TQString& txt, TQWidget* parent, const char* name ) -: TQToolButton(parent,name ) -{ - d = new TTDEToolBarButtonPrivate; - d->m_text = txt; - - setFocusPolicy( TQ_NoFocus ); - - connect(this, TQT_SIGNAL(clicked()), TQT_SLOT(slotClicked()) ); - connect(this, TQT_SIGNAL(pressed()), TQT_SLOT(slotPressed()) ); - connect(this, TQT_SIGNAL(released()), TQT_SLOT(slotReleased()) ); - - installEventFilter(this); - - setPixmap(pixmap); - modeChange(); -} - -TTDEToolBarButton::~TTDEToolBarButton() -{ - delete d; -} - -TQString TTDEToolBarButton::text() -{ - return d->m_text; -} - -void TTDEToolBarButton::modeChange() -{ - TQToolTip::add(this,d->m_text); - - int border = 3; - int w = 2*border; - int h = 2*border; - - if (pixmap()) { - w += pixmap()->width(); - h = TQMAX(h,pixmap()->height()+2*border); - if (d->m_iconMode == TK::IconAndText && !d->m_text.isEmpty()) - w += border; - } - - if ((d->m_iconMode==TK::IconAndText||d->m_iconMode==TK::TextOnly) && !d->m_text.isEmpty()) - { - TQFont tmp_font = TDEGlobalSettings::toolBarFont(); - TQFontMetrics fm(tmp_font); - - h = TQMAX(h,fm.lineSpacing()+2*border); - w += fm.width(d->m_text); - } - - if (d->m_popup && !d->m_isToggle) - w += 11; - - TQSize size(w,h); - setMinimumSize(size); - - updateGeometry(); -} - -void TTDEToolBarButton::setEnabled( bool enabled ) -{ - if (isEnabled()==enabled) - return; - - TQToolButton::setPixmap( (enabled ? defaultPixmap : disabledPixmap) ); - TQToolButton::setEnabled( enabled ); -} - -void TTDEToolBarButton::setText( const TQString& text) -{ - d->m_text = text; - repaint(false); -} - -void TTDEToolBarButton::setIcon( const TQString& icon ) -{ - d->m_iconName = icon; - int iconSize = 16; - - setPixmap( BarIcon(icon, iconSize, KIcon::ActiveState, d->m_instance), false ); - setDisabledPixmap( BarIcon(icon, iconSize, KIcon::DisabledState, d->m_instance) ); - setDefaultPixmap( BarIcon(icon, iconSize, KIcon::DefaultState, d->m_instance) ); -} - -void TTDEToolBarButton::setDisabledIcon( const TQString &icon ) -{ - d->m_disabledIconName = icon; - int iconSize = 16; - setDisabledPixmap( BarIcon(icon, iconSize, KIcon::DisabledState, d->m_instance) ); -} - -void TTDEToolBarButton::setDefaultIcon( const TQString &icon ) -{ - d->m_defaultIconName = icon; - int iconSize = 16; - setDefaultPixmap( BarIcon(icon, iconSize, KIcon::DefaultState, d->m_instance) ); -} - -TQPixmap TTDEToolBarButton::getActivePixmap() const -{ - return activePixmap; -} - -void TTDEToolBarButton::setPixmap( const TQPixmap &pixmap ) -{ - setPixmap( pixmap, true ); -} - -void TTDEToolBarButton::setPixmap( const TQPixmap &pixmap, bool generate ) -{ - activePixmap = pixmap; - - if ( generate ) - { - makeDefaultPixmap(); - makeDisabledPixmap(); - } - else - { - if (defaultPixmap.isNull()) - defaultPixmap = activePixmap; - if (disabledPixmap.isNull()) - disabledPixmap = activePixmap; - } - - TQToolButton::setPixmap( isEnabled() ? defaultPixmap : disabledPixmap ); -} - -void TTDEToolBarButton::setDefaultPixmap( const TQPixmap &pixmap ) -{ - defaultPixmap = pixmap; - TQToolButton::setPixmap( isEnabled() ? defaultPixmap : disabledPixmap ); -} - -void TTDEToolBarButton::setDisabledPixmap( const TQPixmap &pixmap ) -{ - disabledPixmap = pixmap; - TQToolButton::setPixmap( isEnabled() ? defaultPixmap : disabledPixmap ); -} - -void TTDEToolBarButton::setPopup(TQPopupMenu *p) -{ - d->m_popup = p; - d->m_popup->setFont(TDEGlobalSettings::toolBarFont()); - p->installEventFilter(this); - - modeChange(); -} - -TQPopupMenu *TTDEToolBarButton::popup() -{ - return d->m_popup; -} - -void TTDEToolBarButton::setDelayedPopup (TQPopupMenu *p, bool toggle ) -{ - d->m_isPopup = true; - setToggle(toggle); - - if (!d->m_delayTimer) { - d->m_delayTimer = new TQTimer(this); - connect(d->m_delayTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotDelayTimeout())); - } - - setPopup(p); -} - -void TTDEToolBarButton::setRaised(bool f) -{ - d->m_isRaised = f; - repaint(false); -} - -void TTDEToolBarButton::setAutoRaised(bool f) -{ - d->m_autoRaised = f; -} - -void TTDEToolBarButton::leaveEvent(TQEvent *) -{ - if (!d->m_isToggle && !(d->m_popup && d->m_popup->isVisible()) ) { - TQToolButton::setPixmap(isEnabled() ? defaultPixmap : disabledPixmap); - if (d->m_autoRaised) - setRaised(false); - } -} - -void TTDEToolBarButton::enterEvent(TQEvent *) -{ - if (!d->m_isToggle) { - if (isEnabled()) { - TQToolButton::setPixmap(activePixmap); - if (d->m_autoRaised) - setRaised(true); - } else { - TQToolButton::setPixmap(disabledPixmap); - } - repaint(false); - } -} - -bool TTDEToolBarButton::eventFilter(TQObject *o, TQEvent *ev) -{ - if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(this) ) - if (ev->type() == TQEvent::MouseButtonPress && d->m_popup && d->m_isPopup ) { - if (!d->m_isToggle) { - d->m_arrowPressed = arrowPressed( mapFromGlobal(TQCursor::pos()) ); - } else { - d->m_delayTimer->start(POPUP_DELAY); - } - } - - if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(d->m_popup)) { - switch (ev->type()) - { - case TQEvent::Show: - on(true); - return false; - case TQEvent::Hide: - on(false); - setDown(false); - if ( !geometry().contains(parentWidget()->mapFromGlobal(TQCursor::pos())) ) - leaveEvent(0L); - return false; - break; - case TQEvent::MouseButtonPress: { - d->m_arrowPressed = arrowPressed( mapFromGlobal(TQCursor::pos()) ); - d->ignoreNextMousePress = d->m_arrowPressed; - break; - } - default: - break; - } - } - return false; -} - -void TTDEToolBarButton::drawButton( TQPainter* p ) -{ -#define DRAW_PIXMAP_AND_TEXT \ - int x = 3;\ - if (pixmap()) {\ - style().drawItem( p, TQRect( x, 0, pixmap()->width(), height() ), AlignCenter, colorGroup(), isEnabled(), pixmap(), TQString() );\ - if (d->m_iconMode==TK::IconAndText && !d->m_text.isEmpty()) {\ - x += pixmap()->width() + 3;\ - }\ - }\ - if ((d->m_iconMode==TK::IconAndText||d->m_iconMode==TK::TextOnly) && !d->m_text.isEmpty()) {\ - TQFontMetrics fm(TDEGlobalSettings::toolBarFont());\ - style().drawItem( p, TQRect( x, 0, fm.width(d->m_text), height() ), AlignCenter, colorGroup(), isEnabled(), 0, d->m_text );\ - } - - const char* arrow[] = { - "7 4 2 1", - "# c Black", - ". c None", - "#######", - ".#####.", - "..###..", - "...#..."}; - TQPixmap arrow_pix(arrow); - bool f = d->m_isOn || isDown(); - - if (d->m_popup && !d->m_isToggle) - { - if (d->m_isPopup) - { - TQStyle::SFlags flags = TQStyle::Style_Default; - if (isEnabled()) flags |= TQStyle::Style_Enabled; - if (isOn()) flags |= TQStyle::Style_On; - if (d->m_isRaised) flags |= TQStyle::Style_Raised; - if (hasFocus()) flags |= TQStyle::Style_HasFocus; - - style().drawComplexControl( TQStyle::CC_ToolButton, p, this, TQRect( 0, 0, width()-12, height() ), colorGroup(), flags, TQStyle::SC_ToolButton ); - style().drawComplexControl( TQStyle::CC_ToolButton, p, this, TQRect( width()-13, 0, 13, height() ), colorGroup(), flags, TQStyle::SC_ToolButton ); - style().drawItem( p, TQRect( width()-13, 0, 13, height() ), AlignCenter, colorGroup(), isEnabled(), &arrow_pix, TQString() ); - if ( d->m_isRaised ) - qDrawShadeLine( p, width()-12, 0, width()-12, height(), colorGroup(), true ); - DRAW_PIXMAP_AND_TEXT - } else { - style().drawControl( TQStyle::CE_PushButton, p, this, TQRect( 0, 0, width(), height() ), isEnabled() ? colorGroup() : palette().disabled(), f ); - DRAW_PIXMAP_AND_TEXT - int z = f ? 1:0; - p->drawPixmap(width()-11+z,(height()-4)/2+z ,arrow_pix); - } - } else { - style().drawControl( TQStyle::CE_PushButton, p, this, TQRect( 0, 0, width(), height() ), isEnabled() ? colorGroup() : palette().disabled(), f ); - DRAW_PIXMAP_AND_TEXT - } -} - -void TTDEToolBarButton::paletteChange(const TQPalette &) -{ - makeDisabledPixmap(); - if ( !isEnabled() ) - TQToolButton::setPixmap( disabledPixmap ); - else - TQToolButton::setPixmap( defaultPixmap ); - repaint(false); -} - -void TTDEToolBarButton::makeDefaultPixmap() -{ - if (activePixmap.isNull()) - return; - - KIconEffect effect; - defaultPixmap = effect.apply(activePixmap, KIcon::Toolbar, KIcon::DefaultState); -} - -void TTDEToolBarButton::makeDisabledPixmap() -{ - if (activePixmap.isNull()) - return; - - KIconEffect effect; - disabledPixmap = effect.apply(activePixmap, KIcon::Toolbar, KIcon::DisabledState); -} - -TQSize TTDEToolBarButton::sizeHint() const -{ - return minimumSize(); -} - -TQSize TTDEToolBarButton::minimumSizeHint() const -{ - return minimumSize(); -} - -void TTDEToolBarButton::showMenu() -{ - TQPoint p ( mapToGlobal( TQPoint( 0, 0 ) ) ); - const int deskHeight = TDEGlobalSettings::desktopGeometry(this).height(); - if ( p.y() + height() + d->m_popup->height() > deskHeight ) - p.setY( p.y() - d->m_popup->height() ); - else - p.setY( p.y() + height( )); - - d->m_popup->popup(p); -} - -void TTDEToolBarButton::slotDelayTimeout() -{ - d->m_delayTimer->stop(); - showMenu(); -} - -void TTDEToolBarButton::slotClicked() -{ - if ( d->ignoreNextMousePress ) { - d->ignoreNextMousePress=false; - return; - } - - if (d->m_popup && !d->m_isPopup) - showMenu(); - else - emit buttonClicked(); -} - -void TTDEToolBarButton::slotPressed() -{ - if ( d->ignoreNextMousePress ) - return; - - if (d->m_popup) { - if (!d->m_isPopup || d->m_isPopup && d->m_arrowPressed) - showMenu(); - } - else - emit buttonPressed(); - - d->ignoreNextMousePress = false; -} - -void TTDEToolBarButton::slotReleased() -{ - if (d->m_popup && d->m_isPopup) - d->m_delayTimer->stop(); - - emit buttonReleased(); -} - -void TTDEToolBarButton::slotToggled() -{ - emit buttonToggled(); -} - -void TTDEToolBarButton::on(bool flag) -{ - d->m_isOn = flag; - repaint(); -} - -void TTDEToolBarButton::toggle() -{ - on(!d->m_isOn); -} - -void TTDEToolBarButton::setToggle(bool flag) -{ - d->m_isToggle = flag; - if (flag == true) - connect(this, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotToggled())); - else - disconnect(this, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotToggled())); - - modeChange(); - repaint(); -} - -void TTDEToolBarButton::setIconMode( TK::IconMode m ) -{ - d->m_iconMode = m; - modeChange(); - repaint(); -} - -#include diff --git a/lib/kofficeui/tktoolbarbutton.h b/lib/kofficeui/tktoolbarbutton.h deleted file mode 100644 index 14d3b285..00000000 --- a/lib/kofficeui/tktoolbarbutton.h +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Kivio - Visual Modelling and Flowcharting - * Copyright (C) 2000 theKompany.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 2 - * 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, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef TKTOOLBARBUTTON_H -#define TKTOOLBARBUTTON_H - -#include - -#include -#include -#include - -class TDEToolBar; -class TDEInstance; -class TQPopupMenu; -class TQPainter; - -class TTDEToolBarButton : public TQToolButton -{ Q_OBJECT - -public: - TTDEToolBarButton(const TQString& icon, const TQString& txt, - TQWidget* parent = 0, const char *name=0L, - TDEInstance *_instance = TDEGlobal::instance()); - - TTDEToolBarButton(const TQPixmap&, const TQString&, TQWidget* parent=0, const char* name=0); - ~TTDEToolBarButton(); - - void setIconMode(TK::IconMode); - void setRaised(bool); - void setAutoRaised(bool); - - /** - * Enable/Disable this button - * - * @param enable Defaults to true - */ - void setEnabled(bool enable = true); - - /** - * Set the pixmap directly for this button. This pixmap should be - * the active one... the dimmed and disabled pixmaps are constructed - * based on this one. However, don't use this function unless you - * are positive that you don't want to use @ref setIcon. - * - * @param pixmap The active pixmap - */ - virtual void setPixmap(const TQPixmap &pixmap); - - /** - * Set the pixmap directly for this button. This pixmap should be - * the active one.. however, the disabled and default pixmaps will - * only be constructed if @ref #generate is true. In any event, - * don't use this function unless you are positive that you don't - * want to use @ref setIcon. - * - * @param pixmap The active pixmap - * @param generate If true, then the other pixmaps will be - * automatically generated using configurable effects - */ - virtual void setPixmap(const TQPixmap &pixmap, bool generate); - - /** - * Force the button to use this pixmap as the default one rather - * then generating it using effects. - * - * @param pixmap The pixmap to use as the default (normal) one - */ - virtual void setDefaultPixmap(const TQPixmap& pixmap); - - /** - * Force the button to use this pixmap when disabled one rather then - * generating it using effects. - * - * @param pixmap The pixmap to use when disabled - */ - virtual void setDisabledPixmap(const TQPixmap& pixmap); - - /** - * Set the text for this button. The text will be either used as a - * tooltip (IconOnly) or will be along side the icon - * - * @param text The button (or tooltip) text - */ - virtual void setText(const TQString &text); - TQString text(); - - /** - * Set the icon for this button. This icon should be the active - * one... the dimmed and disabled icons are constructed based on - * this one. The actual pixmap will be loaded internally. This - * function is preferred over @ref setPixmap - * - * @param icon The name of the active pixmap - */ - virtual void setIcon(const TQString &icon); - - /** - * Force the button to use this icon as the default one rather - * then generating it using effects. - * - * @param icon The icon to use as the default (normal) one - */ - virtual void setDefaultIcon(const TQString& icon); - - /** - * Force the button to use this icon when disabled one rather then - * generating it using effects. - * - * @param icon The icon to use when disabled - */ - virtual void setDisabledIcon(const TQString& icon); - - /** - * Turn this button on or off - * - * @param flag true or false - */ - void on(bool flag = true); - - /** - * Toggle this button - */ - void toggle(); - - /** - * Turn this button into a toggle button or disable the toggle - * aspects of it. This does not toggle the button itself. Use @ref - * toggle for that. - * - * @param toggle true or false - */ - void setToggle(bool toggle = true); - - /** - * Return a pointer to this button's popup menu (if it exists) - */ - TQPopupMenu *popup(); - - /** - * Give this button a popup menu. There will not be a delay when - * you press the button. Use @ref setDelayedPopup if you want that - * behavior - * - * @param p The new popup menu - */ - void setPopup (TQPopupMenu *p); - - /** - * Gives this button a delayed popup menu. - * - * This function allows you to add a delayed popup menu to the button. - * The popup menu is then only displayed when the button is pressed and - * held down for about half a second. You can also make the poup-menu - * "sticky", i.e. visible until a selection is made or the mouse is - * clikced elsewhere, by simply setting the second argument to true. - * This "sticky" button feature allows you to make a selection without - * having to press and hold down the mouse while making a selection. - * - * @param p the new popup menu - * @param toggle if true, makes the button "sticky" (toggled) - */ - void setDelayedPopup(TQPopupMenu *p, bool toggle = false); - - TQPixmap getActivePixmap() const; - - virtual TQSize sizeHint() const; - virtual TQSize minimumSizeHint() const; - -signals: - void buttonClicked(); - void buttonPressed(); - void buttonReleased(); - void buttonToggled(); - -public slots: - void modeChange(); - -protected: - void paletteChange(const TQPalette &); - void leaveEvent(TQEvent *e); - void enterEvent(TQEvent *e); - void drawButton(TQPainter *p); - bool eventFilter (TQObject *o, TQEvent *e); - void showMenu(); - - void makeDefaultPixmap(); - void makeDisabledPixmap(); - bool arrowPressed( const TQPoint& pos ) { - int x = pos.x(); - int y = pos.y(); - return (x > width() - 12 && x <= width() && y > 0 && y < height()); - } - -private: - TQPixmap defaultPixmap; - TQPixmap activePixmap; - TQPixmap disabledPixmap; - virtual void setIcon(const TQPixmap &p) { TQButton::setIcon(p); } - class TTDEToolBarButtonPrivate; - TTDEToolBarButtonPrivate *d; - - -protected slots: - void slotClicked(); - void slotPressed(); - void slotReleased(); - void slotToggled(); - void slotDelayTimeout(); -}; - -#endif diff --git a/lib/kofficeui/ttdeaction.cpp b/lib/kofficeui/ttdeaction.cpp new file mode 100644 index 00000000..56c626f8 --- /dev/null +++ b/lib/kofficeui/ttdeaction.cpp @@ -0,0 +1,300 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000 theKompany.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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#include "tkaction.h" +#include "tktoolbarbutton.h" +#include "tkcombobox.h" + +#include +#include + +#include +#include + +#define SET_FOR_ALL_CONTAINER(WIDGET_TYPE,METHOD_NAME,VALUE) \ + for( int id = 0; id < containerCount(); ++id ) { \ + TQWidget* w = container(id); \ + if ( w->inherits("TDEToolBar") ) { \ + TQWidget* r = static_cast(w)->getWidget(itemId(id)); \ + if (qstrcmp(r->name(),"KTToolBarLayout")==0) \ + r = (TQWidget*)r->child("widget"); \ + if ( r && r->inherits(#WIDGET_TYPE) ) { \ + WIDGET_TYPE* b = static_cast(r); \ + b->METHOD_NAME(VALUE); \ + } \ + } \ + } + +TTDEAction::TTDEAction(TQObject* parent, const char* name) +: TDEAction( "", 0, parent, name ) +{ + m_imode = TK::IconOnly; +} + +TTDEAction::~TTDEAction() +{ +} + +int TTDEAction::plug(TQWidget* widget, int index) +{ + if ( widget->inherits("TDEToolBar") ) { + TDEToolBar* bar = static_cast(widget); + int id_ = TDEAction::getToolButtonID(); + TDEInstance *instance; + + if ( parentCollection() ) + instance = parentCollection()->instance(); + else + instance = TDEGlobal::instance(); + + TTDEToolBarButton* b = new TTDEToolBarButton(icon(),plainText(),bar,name(),instance); + // we don't need clicked() and buttonClicked(), do we? + // connect(b,TQT_SIGNAL(clicked()),TQT_SLOT(slotActivated())); + b->setIconMode(m_imode); + initToolBarButton(b); + + bar->insertWidget( id_, 100, b, index ); + addContainer(bar,id_); + connect( bar, TQT_SIGNAL(destroyed()), this, TQT_SLOT(slotDestroyed()) ); + + return containerCount() - 1; + } + return TDEAction::plug(widget,index); +} + +void TTDEAction::initToolBarButton(TTDEToolBarButton* button) +{ + connect(button,TQT_SIGNAL(buttonClicked()),TQT_SLOT(slotActivated())); +} + +TK::IconMode TTDEAction::iconMode() +{ + return m_imode; +} + +void TTDEAction::setIconMode(TK::IconMode mode) +{ + m_imode = mode; + SET_FOR_ALL_CONTAINER(TTDEToolBarButton,setIconMode,mode) +} + +void TTDEAction::setText(const TQString& text) +{ + TDEAction::setText(text); + updateLayout(); +} + +void TTDEAction::setIcon(const TQString& icon) +{ + TDEAction::setIcon(icon); + updateLayout(); +} + +void TTDEAction::updateLayout() +{ + int len = containerCount(); + for( int id = 0; id < len; ++id ) { + TQWidget* w = container( id ); + if (w->inherits("TDEToolBar")) { + TQWidget* r = static_cast(w)->getWidget(itemId(id)); + if (qstrcmp(r->name(),"KTToolBarLayout")==0) { + updateLayout(r); + } + } + } +} + +TQWidget* TTDEAction::createLayout(TQWidget* parent, TQWidget* children) +{ + TQWidget* base = new TQWidget(parent,"KTToolBarLayout"); + TQLabel* textLabel = new TQLabel(base,"text"); + textLabel->setMinimumHeight(1); + TQLabel* pixLabel = new TQLabel(base,"pixmap"); + children->reparent(base,TQPoint(0,0)); + children->setName("widget"); + TQHBoxLayout* layout = new TQHBoxLayout(base,0,3); + layout->setResizeMode(TQLayout::Minimum); + layout->addWidget(textLabel); + layout->addWidget(pixLabel); + layout->addWidget(children,1); + + updateLayout(base); + return base; +} + +void TTDEAction::updateLayout(TQWidget* base) +{ + TQLabel* textLabel = (TQLabel*)base->child("text"); + TQLabel* pixLabel = (TQLabel*)base->child("pixmap"); + TQWidget* w = (TQWidget*)base->child("widget"); + + if (!textLabel || !pixLabel || !w) + return; + + if (!text().isEmpty() && m_imode != TK::IconOnly ) { + textLabel->setText(text()); + textLabel->show(); + } else + textLabel->hide(); + + TQPixmap pix; + if (hasIcon()) + pix = iconSet(KIcon::Small).pixmap(); + + if (!icon().isEmpty()) + pix = BarIcon(icon()); + + if (!pix.isNull() && m_imode != TK::TextOnly) { + pixLabel->setPixmap(pix); + pixLabel->show(); + } else + pixLabel->hide(); + + base->setFixedWidth( w->sizeHint().width() + + (textLabel->isVisible() ? textLabel->sizeHint().width():0) + + (pixLabel->isVisible() ? pixLabel->sizeHint().width():0) ); +} +/******************************************************************************/ +TKBaseSelectAction::TKBaseSelectAction( TQObject* parent, const char* name ) +: TTDEAction(parent,name) +{ + m_current = 0; + m_editable = false; +} + +TKBaseSelectAction::~TKBaseSelectAction() +{ +} + +int TKBaseSelectAction::plug(TQWidget* widget, int index) +{ + if ( widget->inherits("TDEToolBar") ) + { + TDEToolBar* bar = static_cast( widget ); + int id_ = TDEAction::getToolButtonID(); + + TKComboBox* cb = new TKComboBox(m_editable,bar); + initComboBox(cb); + cb->setMinimumWidth( cb->sizeHint().width() ); + TQWidget* base = createLayout(bar,cb); + + bar->insertWidget( id_, 100, base, index ); + addContainer( bar, id_ ); + + connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) ); + + setCurrentItem(currentItem()); + + return containerCount() - 1; + } + return -1; +} + +int TKBaseSelectAction::currentItem() +{ + return m_current; +} + +void TKBaseSelectAction::initComboBox(TKComboBox* cb) +{ + connect(cb,TQT_SIGNAL(activated(int)),TQT_SLOT(slotActivated(int))); +} + +void TKBaseSelectAction::setEditable(bool editable) +{ + m_editable = editable; + SET_FOR_ALL_CONTAINER(TKComboBox,setEditable,editable) +} + +bool TKBaseSelectAction::isEditable() +{ + return m_editable; +} + +void TKBaseSelectAction::setCurrentItem(int index) +{ + m_current = index; + SET_FOR_ALL_CONTAINER(TKComboBox,setCurrentItem,index) +} + +void TKBaseSelectAction::slotActivated(int id) +{ + if ( m_current == id ) + return; + + m_current = id; + setCurrentItem(id); + activate(id); +} + +void TKBaseSelectAction::activate(int id) +{ + emit activated(id); +} +/******************************************************************************/ +TTDESelectAction::TTDESelectAction( TQObject* parent, const char* name ) +: TKBaseSelectAction(parent,name) +{ +} + +TTDESelectAction::~TTDESelectAction() +{ +} + +void TTDESelectAction::initComboBox(TKComboBox* cb) +{ + TKBaseSelectAction::initComboBox(cb); + connect(cb,TQT_SIGNAL(activated(const TQString&)),TQT_SLOT(slotActivated(const TQString&))); + cb->insertStringList(items()); +} + +void TTDESelectAction::slotActivated(const TQString& text) +{ + emit activated(text); +} + +void TTDESelectAction::setItems(const TQStringList& lst ) +{ + m_list = lst; + m_current = -1; + + SET_FOR_ALL_CONTAINER(TKComboBox,clear, ) + SET_FOR_ALL_CONTAINER(TKComboBox,insertStringList,lst) + + // Disable if empty and not editable + setEnabled ( lst.count() > 0 || m_editable ); +} + +TQStringList TTDESelectAction::items() const +{ + return m_list; +} + +void TTDESelectAction::clear() +{ + SET_FOR_ALL_CONTAINER(TKComboBox,clear, ) +} + +void TTDESelectAction::setEditText(const TQString& text) +{ + SET_FOR_ALL_CONTAINER(TKComboBox,setEditText,text) +} + +#undef SET_FOR_ALL_CONTAINER +#include "tkaction.moc" diff --git a/lib/kofficeui/ttdeaction.h b/lib/kofficeui/ttdeaction.h new file mode 100644 index 00000000..736bb141 --- /dev/null +++ b/lib/kofficeui/ttdeaction.h @@ -0,0 +1,126 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000 theKompany.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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#ifndef TKACTION_H +#define TKACTION_H + +#include +#include +#include +namespace TK { + enum IconMode { IconOnly, IconAndText, TextOnly }; +} + +class TTDEToolBarButton; +class TKComboBox; + +class KOFFICEUI_EXPORT TTDEAction : public TDEAction +{ Q_OBJECT + +public: + TTDEAction(TQObject* parent, const char* name); + ~TTDEAction(); + + virtual int plug(TQWidget* widget, int index = -1); + + TK::IconMode iconMode(); + +protected: + virtual void initToolBarButton(TTDEToolBarButton*); + + TQWidget* createLayout(TQWidget* parent, TQWidget* children); + void updateLayout(); + virtual void updateLayout(TQWidget*); + +public slots: + virtual void setIconMode(TK::IconMode); + void setText(const TQString&); + void setIcon(const TQString&); + +private: + TK::IconMode m_imode; + class TTDEActionPrivate; + TTDEActionPrivate *d; +}; +/******************************************************************************/ +class KOFFICEUI_EXPORT TKBaseSelectAction : public TTDEAction +{ Q_OBJECT + +friend class TTDESelectAction; +public: + TKBaseSelectAction(TQObject* parent, const char* name); + ~TKBaseSelectAction(); + + virtual int plug(TQWidget* widget, int index = -1); + + int currentItem(); + bool isEditable(); + + void activate(int); + +protected: + virtual void initComboBox(TKComboBox*); + +public slots: + virtual void setCurrentItem(int index); + virtual void setEditable(bool); + +protected slots: + virtual void slotActivated(int); + +signals: + void activated(int); + +private: + int m_current; + bool m_editable; + class TKBaseSelectActionPrivate; + TKBaseSelectActionPrivate *d; +}; +/******************************************************************************/ +class KOFFICEUI_EXPORT TTDESelectAction : public TKBaseSelectAction +{ Q_OBJECT + +public: + TTDESelectAction(TQObject* parent, const char* name); + ~TTDESelectAction(); + + TQStringList items() const; + +public slots: + virtual void setItems(const TQStringList& ); + virtual void setEditText(const TQString&); + virtual void clear(); + +protected: + virtual void initComboBox(TKComboBox*); + +protected slots: + void slotActivated(const TQString&); + +signals: + void activated(const TQString&); + +private: + TQStringList m_list; + class TTDESelectActionPrivate; + TTDESelectActionPrivate *d; +}; +/******************************************************************************/ +#endif diff --git a/lib/kofficeui/ttdetoolbarbutton.cpp b/lib/kofficeui/ttdetoolbarbutton.cpp new file mode 100644 index 00000000..c4c8e27b --- /dev/null +++ b/lib/kofficeui/ttdetoolbarbutton.cpp @@ -0,0 +1,532 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000 theKompany.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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +// Delay in ms before delayed popup pops up +#define POPUP_DELAY 500 + +class TTDEToolBarButton::TTDEToolBarButtonPrivate +{ +public: + TTDEToolBarButtonPrivate() + { + m_iconMode = TK::IconOnly; + m_isPopup = false; + m_isToggle = false; + m_isOn = false; + m_isRaised = false; + m_autoRaised = true; + ignoreNextMousePress = false; + + m_text = TQString(); + m_iconName = TQString(); + m_arrowPressed = false; + m_delayTimer = 0L; + m_popup = 0L; + + m_disabledIconName = TQString(); + m_defaultIconName = TQString(); + + m_instance = TDEGlobal::instance(); + } + + ~TTDEToolBarButtonPrivate() + { + delete m_delayTimer; + m_delayTimer = 0; + } + + bool m_isPopup; + bool m_isToggle; + bool m_isOn; + bool m_isRaised; + bool m_autoRaised; + bool m_arrowPressed; + bool ignoreNextMousePress; + + TQString m_text; + TQString m_iconName; + TQString m_disabledIconName; + TQString m_defaultIconName; + + TK::IconMode m_iconMode; + + TQTimer *m_delayTimer; + TQPopupMenu *m_popup; + + TDEInstance *m_instance; +}; + +TTDEToolBarButton::TTDEToolBarButton( const TQString& icon, const TQString& txt, + TQWidget* parent, const char* name, + TDEInstance *instance ) +: TQToolButton(parent,name) +{ + d = new TTDEToolBarButtonPrivate; + d->m_text = txt; + d->m_instance = instance; + + setFocusPolicy( TQ_NoFocus ); + + connect(this, TQT_SIGNAL(clicked()), TQT_SLOT(slotClicked()) ); + connect(this, TQT_SIGNAL(pressed()), TQT_SLOT(slotPressed()) ); + connect(this, TQT_SIGNAL(released()), TQT_SLOT(slotReleased()) ); + + installEventFilter(this); + + setIcon(icon); + modeChange(); +} + +TTDEToolBarButton::TTDEToolBarButton( const TQPixmap& pixmap, const TQString& txt, TQWidget* parent, const char* name ) +: TQToolButton(parent,name ) +{ + d = new TTDEToolBarButtonPrivate; + d->m_text = txt; + + setFocusPolicy( TQ_NoFocus ); + + connect(this, TQT_SIGNAL(clicked()), TQT_SLOT(slotClicked()) ); + connect(this, TQT_SIGNAL(pressed()), TQT_SLOT(slotPressed()) ); + connect(this, TQT_SIGNAL(released()), TQT_SLOT(slotReleased()) ); + + installEventFilter(this); + + setPixmap(pixmap); + modeChange(); +} + +TTDEToolBarButton::~TTDEToolBarButton() +{ + delete d; +} + +TQString TTDEToolBarButton::text() +{ + return d->m_text; +} + +void TTDEToolBarButton::modeChange() +{ + TQToolTip::add(this,d->m_text); + + int border = 3; + int w = 2*border; + int h = 2*border; + + if (pixmap()) { + w += pixmap()->width(); + h = TQMAX(h,pixmap()->height()+2*border); + if (d->m_iconMode == TK::IconAndText && !d->m_text.isEmpty()) + w += border; + } + + if ((d->m_iconMode==TK::IconAndText||d->m_iconMode==TK::TextOnly) && !d->m_text.isEmpty()) + { + TQFont tmp_font = TDEGlobalSettings::toolBarFont(); + TQFontMetrics fm(tmp_font); + + h = TQMAX(h,fm.lineSpacing()+2*border); + w += fm.width(d->m_text); + } + + if (d->m_popup && !d->m_isToggle) + w += 11; + + TQSize size(w,h); + setMinimumSize(size); + + updateGeometry(); +} + +void TTDEToolBarButton::setEnabled( bool enabled ) +{ + if (isEnabled()==enabled) + return; + + TQToolButton::setPixmap( (enabled ? defaultPixmap : disabledPixmap) ); + TQToolButton::setEnabled( enabled ); +} + +void TTDEToolBarButton::setText( const TQString& text) +{ + d->m_text = text; + repaint(false); +} + +void TTDEToolBarButton::setIcon( const TQString& icon ) +{ + d->m_iconName = icon; + int iconSize = 16; + + setPixmap( BarIcon(icon, iconSize, KIcon::ActiveState, d->m_instance), false ); + setDisabledPixmap( BarIcon(icon, iconSize, KIcon::DisabledState, d->m_instance) ); + setDefaultPixmap( BarIcon(icon, iconSize, KIcon::DefaultState, d->m_instance) ); +} + +void TTDEToolBarButton::setDisabledIcon( const TQString &icon ) +{ + d->m_disabledIconName = icon; + int iconSize = 16; + setDisabledPixmap( BarIcon(icon, iconSize, KIcon::DisabledState, d->m_instance) ); +} + +void TTDEToolBarButton::setDefaultIcon( const TQString &icon ) +{ + d->m_defaultIconName = icon; + int iconSize = 16; + setDefaultPixmap( BarIcon(icon, iconSize, KIcon::DefaultState, d->m_instance) ); +} + +TQPixmap TTDEToolBarButton::getActivePixmap() const +{ + return activePixmap; +} + +void TTDEToolBarButton::setPixmap( const TQPixmap &pixmap ) +{ + setPixmap( pixmap, true ); +} + +void TTDEToolBarButton::setPixmap( const TQPixmap &pixmap, bool generate ) +{ + activePixmap = pixmap; + + if ( generate ) + { + makeDefaultPixmap(); + makeDisabledPixmap(); + } + else + { + if (defaultPixmap.isNull()) + defaultPixmap = activePixmap; + if (disabledPixmap.isNull()) + disabledPixmap = activePixmap; + } + + TQToolButton::setPixmap( isEnabled() ? defaultPixmap : disabledPixmap ); +} + +void TTDEToolBarButton::setDefaultPixmap( const TQPixmap &pixmap ) +{ + defaultPixmap = pixmap; + TQToolButton::setPixmap( isEnabled() ? defaultPixmap : disabledPixmap ); +} + +void TTDEToolBarButton::setDisabledPixmap( const TQPixmap &pixmap ) +{ + disabledPixmap = pixmap; + TQToolButton::setPixmap( isEnabled() ? defaultPixmap : disabledPixmap ); +} + +void TTDEToolBarButton::setPopup(TQPopupMenu *p) +{ + d->m_popup = p; + d->m_popup->setFont(TDEGlobalSettings::toolBarFont()); + p->installEventFilter(this); + + modeChange(); +} + +TQPopupMenu *TTDEToolBarButton::popup() +{ + return d->m_popup; +} + +void TTDEToolBarButton::setDelayedPopup (TQPopupMenu *p, bool toggle ) +{ + d->m_isPopup = true; + setToggle(toggle); + + if (!d->m_delayTimer) { + d->m_delayTimer = new TQTimer(this); + connect(d->m_delayTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotDelayTimeout())); + } + + setPopup(p); +} + +void TTDEToolBarButton::setRaised(bool f) +{ + d->m_isRaised = f; + repaint(false); +} + +void TTDEToolBarButton::setAutoRaised(bool f) +{ + d->m_autoRaised = f; +} + +void TTDEToolBarButton::leaveEvent(TQEvent *) +{ + if (!d->m_isToggle && !(d->m_popup && d->m_popup->isVisible()) ) { + TQToolButton::setPixmap(isEnabled() ? defaultPixmap : disabledPixmap); + if (d->m_autoRaised) + setRaised(false); + } +} + +void TTDEToolBarButton::enterEvent(TQEvent *) +{ + if (!d->m_isToggle) { + if (isEnabled()) { + TQToolButton::setPixmap(activePixmap); + if (d->m_autoRaised) + setRaised(true); + } else { + TQToolButton::setPixmap(disabledPixmap); + } + repaint(false); + } +} + +bool TTDEToolBarButton::eventFilter(TQObject *o, TQEvent *ev) +{ + if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(this) ) + if (ev->type() == TQEvent::MouseButtonPress && d->m_popup && d->m_isPopup ) { + if (!d->m_isToggle) { + d->m_arrowPressed = arrowPressed( mapFromGlobal(TQCursor::pos()) ); + } else { + d->m_delayTimer->start(POPUP_DELAY); + } + } + + if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(d->m_popup)) { + switch (ev->type()) + { + case TQEvent::Show: + on(true); + return false; + case TQEvent::Hide: + on(false); + setDown(false); + if ( !geometry().contains(parentWidget()->mapFromGlobal(TQCursor::pos())) ) + leaveEvent(0L); + return false; + break; + case TQEvent::MouseButtonPress: { + d->m_arrowPressed = arrowPressed( mapFromGlobal(TQCursor::pos()) ); + d->ignoreNextMousePress = d->m_arrowPressed; + break; + } + default: + break; + } + } + return false; +} + +void TTDEToolBarButton::drawButton( TQPainter* p ) +{ +#define DRAW_PIXMAP_AND_TEXT \ + int x = 3;\ + if (pixmap()) {\ + style().drawItem( p, TQRect( x, 0, pixmap()->width(), height() ), AlignCenter, colorGroup(), isEnabled(), pixmap(), TQString() );\ + if (d->m_iconMode==TK::IconAndText && !d->m_text.isEmpty()) {\ + x += pixmap()->width() + 3;\ + }\ + }\ + if ((d->m_iconMode==TK::IconAndText||d->m_iconMode==TK::TextOnly) && !d->m_text.isEmpty()) {\ + TQFontMetrics fm(TDEGlobalSettings::toolBarFont());\ + style().drawItem( p, TQRect( x, 0, fm.width(d->m_text), height() ), AlignCenter, colorGroup(), isEnabled(), 0, d->m_text );\ + } + + const char* arrow[] = { + "7 4 2 1", + "# c Black", + ". c None", + "#######", + ".#####.", + "..###..", + "...#..."}; + TQPixmap arrow_pix(arrow); + bool f = d->m_isOn || isDown(); + + if (d->m_popup && !d->m_isToggle) + { + if (d->m_isPopup) + { + TQStyle::SFlags flags = TQStyle::Style_Default; + if (isEnabled()) flags |= TQStyle::Style_Enabled; + if (isOn()) flags |= TQStyle::Style_On; + if (d->m_isRaised) flags |= TQStyle::Style_Raised; + if (hasFocus()) flags |= TQStyle::Style_HasFocus; + + style().drawComplexControl( TQStyle::CC_ToolButton, p, this, TQRect( 0, 0, width()-12, height() ), colorGroup(), flags, TQStyle::SC_ToolButton ); + style().drawComplexControl( TQStyle::CC_ToolButton, p, this, TQRect( width()-13, 0, 13, height() ), colorGroup(), flags, TQStyle::SC_ToolButton ); + style().drawItem( p, TQRect( width()-13, 0, 13, height() ), AlignCenter, colorGroup(), isEnabled(), &arrow_pix, TQString() ); + if ( d->m_isRaised ) + qDrawShadeLine( p, width()-12, 0, width()-12, height(), colorGroup(), true ); + DRAW_PIXMAP_AND_TEXT + } else { + style().drawControl( TQStyle::CE_PushButton, p, this, TQRect( 0, 0, width(), height() ), isEnabled() ? colorGroup() : palette().disabled(), f ); + DRAW_PIXMAP_AND_TEXT + int z = f ? 1:0; + p->drawPixmap(width()-11+z,(height()-4)/2+z ,arrow_pix); + } + } else { + style().drawControl( TQStyle::CE_PushButton, p, this, TQRect( 0, 0, width(), height() ), isEnabled() ? colorGroup() : palette().disabled(), f ); + DRAW_PIXMAP_AND_TEXT + } +} + +void TTDEToolBarButton::paletteChange(const TQPalette &) +{ + makeDisabledPixmap(); + if ( !isEnabled() ) + TQToolButton::setPixmap( disabledPixmap ); + else + TQToolButton::setPixmap( defaultPixmap ); + repaint(false); +} + +void TTDEToolBarButton::makeDefaultPixmap() +{ + if (activePixmap.isNull()) + return; + + KIconEffect effect; + defaultPixmap = effect.apply(activePixmap, KIcon::Toolbar, KIcon::DefaultState); +} + +void TTDEToolBarButton::makeDisabledPixmap() +{ + if (activePixmap.isNull()) + return; + + KIconEffect effect; + disabledPixmap = effect.apply(activePixmap, KIcon::Toolbar, KIcon::DisabledState); +} + +TQSize TTDEToolBarButton::sizeHint() const +{ + return minimumSize(); +} + +TQSize TTDEToolBarButton::minimumSizeHint() const +{ + return minimumSize(); +} + +void TTDEToolBarButton::showMenu() +{ + TQPoint p ( mapToGlobal( TQPoint( 0, 0 ) ) ); + const int deskHeight = TDEGlobalSettings::desktopGeometry(this).height(); + if ( p.y() + height() + d->m_popup->height() > deskHeight ) + p.setY( p.y() - d->m_popup->height() ); + else + p.setY( p.y() + height( )); + + d->m_popup->popup(p); +} + +void TTDEToolBarButton::slotDelayTimeout() +{ + d->m_delayTimer->stop(); + showMenu(); +} + +void TTDEToolBarButton::slotClicked() +{ + if ( d->ignoreNextMousePress ) { + d->ignoreNextMousePress=false; + return; + } + + if (d->m_popup && !d->m_isPopup) + showMenu(); + else + emit buttonClicked(); +} + +void TTDEToolBarButton::slotPressed() +{ + if ( d->ignoreNextMousePress ) + return; + + if (d->m_popup) { + if (!d->m_isPopup || d->m_isPopup && d->m_arrowPressed) + showMenu(); + } + else + emit buttonPressed(); + + d->ignoreNextMousePress = false; +} + +void TTDEToolBarButton::slotReleased() +{ + if (d->m_popup && d->m_isPopup) + d->m_delayTimer->stop(); + + emit buttonReleased(); +} + +void TTDEToolBarButton::slotToggled() +{ + emit buttonToggled(); +} + +void TTDEToolBarButton::on(bool flag) +{ + d->m_isOn = flag; + repaint(); +} + +void TTDEToolBarButton::toggle() +{ + on(!d->m_isOn); +} + +void TTDEToolBarButton::setToggle(bool flag) +{ + d->m_isToggle = flag; + if (flag == true) + connect(this, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotToggled())); + else + disconnect(this, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotToggled())); + + modeChange(); + repaint(); +} + +void TTDEToolBarButton::setIconMode( TK::IconMode m ) +{ + d->m_iconMode = m; + modeChange(); + repaint(); +} + +#include diff --git a/lib/kofficeui/ttdetoolbarbutton.h b/lib/kofficeui/ttdetoolbarbutton.h new file mode 100644 index 00000000..14d3b285 --- /dev/null +++ b/lib/kofficeui/ttdetoolbarbutton.h @@ -0,0 +1,228 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000 theKompany.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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#ifndef TKTOOLBARBUTTON_H +#define TKTOOLBARBUTTON_H + +#include + +#include +#include +#include + +class TDEToolBar; +class TDEInstance; +class TQPopupMenu; +class TQPainter; + +class TTDEToolBarButton : public TQToolButton +{ Q_OBJECT + +public: + TTDEToolBarButton(const TQString& icon, const TQString& txt, + TQWidget* parent = 0, const char *name=0L, + TDEInstance *_instance = TDEGlobal::instance()); + + TTDEToolBarButton(const TQPixmap&, const TQString&, TQWidget* parent=0, const char* name=0); + ~TTDEToolBarButton(); + + void setIconMode(TK::IconMode); + void setRaised(bool); + void setAutoRaised(bool); + + /** + * Enable/Disable this button + * + * @param enable Defaults to true + */ + void setEnabled(bool enable = true); + + /** + * Set the pixmap directly for this button. This pixmap should be + * the active one... the dimmed and disabled pixmaps are constructed + * based on this one. However, don't use this function unless you + * are positive that you don't want to use @ref setIcon. + * + * @param pixmap The active pixmap + */ + virtual void setPixmap(const TQPixmap &pixmap); + + /** + * Set the pixmap directly for this button. This pixmap should be + * the active one.. however, the disabled and default pixmaps will + * only be constructed if @ref #generate is true. In any event, + * don't use this function unless you are positive that you don't + * want to use @ref setIcon. + * + * @param pixmap The active pixmap + * @param generate If true, then the other pixmaps will be + * automatically generated using configurable effects + */ + virtual void setPixmap(const TQPixmap &pixmap, bool generate); + + /** + * Force the button to use this pixmap as the default one rather + * then generating it using effects. + * + * @param pixmap The pixmap to use as the default (normal) one + */ + virtual void setDefaultPixmap(const TQPixmap& pixmap); + + /** + * Force the button to use this pixmap when disabled one rather then + * generating it using effects. + * + * @param pixmap The pixmap to use when disabled + */ + virtual void setDisabledPixmap(const TQPixmap& pixmap); + + /** + * Set the text for this button. The text will be either used as a + * tooltip (IconOnly) or will be along side the icon + * + * @param text The button (or tooltip) text + */ + virtual void setText(const TQString &text); + TQString text(); + + /** + * Set the icon for this button. This icon should be the active + * one... the dimmed and disabled icons are constructed based on + * this one. The actual pixmap will be loaded internally. This + * function is preferred over @ref setPixmap + * + * @param icon The name of the active pixmap + */ + virtual void setIcon(const TQString &icon); + + /** + * Force the button to use this icon as the default one rather + * then generating it using effects. + * + * @param icon The icon to use as the default (normal) one + */ + virtual void setDefaultIcon(const TQString& icon); + + /** + * Force the button to use this icon when disabled one rather then + * generating it using effects. + * + * @param icon The icon to use when disabled + */ + virtual void setDisabledIcon(const TQString& icon); + + /** + * Turn this button on or off + * + * @param flag true or false + */ + void on(bool flag = true); + + /** + * Toggle this button + */ + void toggle(); + + /** + * Turn this button into a toggle button or disable the toggle + * aspects of it. This does not toggle the button itself. Use @ref + * toggle for that. + * + * @param toggle true or false + */ + void setToggle(bool toggle = true); + + /** + * Return a pointer to this button's popup menu (if it exists) + */ + TQPopupMenu *popup(); + + /** + * Give this button a popup menu. There will not be a delay when + * you press the button. Use @ref setDelayedPopup if you want that + * behavior + * + * @param p The new popup menu + */ + void setPopup (TQPopupMenu *p); + + /** + * Gives this button a delayed popup menu. + * + * This function allows you to add a delayed popup menu to the button. + * The popup menu is then only displayed when the button is pressed and + * held down for about half a second. You can also make the poup-menu + * "sticky", i.e. visible until a selection is made or the mouse is + * clikced elsewhere, by simply setting the second argument to true. + * This "sticky" button feature allows you to make a selection without + * having to press and hold down the mouse while making a selection. + * + * @param p the new popup menu + * @param toggle if true, makes the button "sticky" (toggled) + */ + void setDelayedPopup(TQPopupMenu *p, bool toggle = false); + + TQPixmap getActivePixmap() const; + + virtual TQSize sizeHint() const; + virtual TQSize minimumSizeHint() const; + +signals: + void buttonClicked(); + void buttonPressed(); + void buttonReleased(); + void buttonToggled(); + +public slots: + void modeChange(); + +protected: + void paletteChange(const TQPalette &); + void leaveEvent(TQEvent *e); + void enterEvent(TQEvent *e); + void drawButton(TQPainter *p); + bool eventFilter (TQObject *o, TQEvent *e); + void showMenu(); + + void makeDefaultPixmap(); + void makeDisabledPixmap(); + bool arrowPressed( const TQPoint& pos ) { + int x = pos.x(); + int y = pos.y(); + return (x > width() - 12 && x <= width() && y > 0 && y < height()); + } + +private: + TQPixmap defaultPixmap; + TQPixmap activePixmap; + TQPixmap disabledPixmap; + virtual void setIcon(const TQPixmap &p) { TQButton::setIcon(p); } + class TTDEToolBarButtonPrivate; + TTDEToolBarButtonPrivate *d; + + +protected slots: + void slotClicked(); + void slotPressed(); + void slotReleased(); + void slotToggled(); + void slotDelayTimeout(); +}; + +#endif -- cgit v1.2.1