diff options
| author | 2011-05-02 22:49:07 +0000 | |
|---|---|---|
| committer | 2011-05-02 22:49:07 +0000 | |
| commit | 13385fafaa81a3c16a8a06a0c377ca1a43eac43e (patch) | |
| tree | f0ea90cd1ecbb08f170cd59971d5adf6a8458cc0 /src | |
| parent | Fixed diskspace function (diff) | |
| download | KVIrc-13385fafaa81a3c16a8a06a0c377ca1a43eac43e.tar.gz KVIrc-13385fafaa81a3c16a8a06a0c377ca1a43eac43e.tar.bz2 KVIrc-13385fafaa81a3c16a8a06a0c377ca1a43eac43e.zip | |
reworked toolbars and kviactions:
- use qactions intead of qtoolbuttons + ids
- drop ktoolbar, since it adds its own methods and context menu
- add button style (text/icon/both/etc..)
- default buttons icon size reverted to 22 :)
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5813 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src')
| -rw-r--r-- | src/kvilib/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/kvilib/tal/KviTalToolBar.cpp | 74 | ||||
| -rw-r--r-- | src/kvilib/tal/KviTalToolBar.h | 101 | ||||
| -rw-r--r-- | src/kvirc/kernel/KviAction.cpp | 78 | ||||
| -rw-r--r-- | src/kvirc/kernel/KviAction.h | 24 | ||||
| -rw-r--r-- | src/kvirc/kernel/KviCoreActions.cpp | 124 | ||||
| -rw-r--r-- | src/kvirc/kernel/KviCoreActions.h | 10 | ||||
| -rw-r--r-- | src/kvirc/kernel/KviCustomToolBarDescriptor.cpp | 11 | ||||
| -rw-r--r-- | src/kvirc/kernel/KviOptions.cpp | 14 | ||||
| -rw-r--r-- | src/kvirc/kernel/KviOptions.h | 3 | ||||
| -rw-r--r-- | src/kvirc/ui/KviCustomToolBar.cpp | 237 | ||||
| -rw-r--r-- | src/kvirc/ui/KviCustomToolBar.h | 10 | ||||
| -rw-r--r-- | src/kvirc/ui/KviIrcToolBar.cpp | 69 | ||||
| -rw-r--r-- | src/kvirc/ui/KviIrcToolBar.h | 3 | ||||
| -rw-r--r-- | src/kvirc/ui/KviMainWindow.cpp | 62 | ||||
| -rw-r--r-- | src/kvirc/ui/KviMainWindow.h | 4 | ||||
| -rw-r--r-- | src/kvirc/ui/KviToolBar.cpp | 150 | ||||
| -rw-r--r-- | src/kvirc/ui/KviToolBar.h | 35 | ||||
| -rw-r--r-- | src/modules/objects/KvsObject_toolBar.cpp | 13 |
19 files changed, 370 insertions, 654 deletions
diff --git a/src/kvilib/CMakeLists.txt b/src/kvilib/CMakeLists.txt index 013e2fc48..cca01c4da 100644 --- a/src/kvilib/CMakeLists.txt +++ b/src/kvilib/CMakeLists.txt @@ -36,7 +36,6 @@ SET( tal/KviTalPopupMenu.h tal/KviTalTabDialog.h tal/KviTalTableWidget.h - tal/KviTalToolBar.h tal/KviTalToolTip.h tal/KviTalVBox.h tal/KviTalWizard.h @@ -137,7 +136,6 @@ SET(kvilib_SRCS tal/KviTalSplitter.cpp tal/KviTalTabDialog.cpp tal/KviTalTableWidget.cpp - tal/KviTalToolBar.cpp tal/KviTalToolTip.cpp tal/KviTalVBox.cpp tal/KviTalWizard.cpp diff --git a/src/kvilib/tal/KviTalToolBar.cpp b/src/kvilib/tal/KviTalToolBar.cpp deleted file mode 100644 index 3fd20e07c..000000000 --- a/src/kvilib/tal/KviTalToolBar.cpp +++ /dev/null @@ -1,74 +0,0 @@ -//============================================================================= -// -// File : KviTalToolBar.cpp -// Creation date : Mon Aug 13 05:05:45 2001 GMT by Szymon Stefanek -// -// This file is part of the KVIrc irc client distribution -// Copyright (C) 2001-2010 Szymon Stefanek (pragma at kvirc dot net) -// -// 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 opinion) 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 "KviTalToolBar.h" - -#ifdef COMPILE_KDE_SUPPORT - KviTalToolBar::KviTalToolBar(const QString & szLabel, QMainWindow * pWnd, Qt::ToolBarArea type, bool bNewLine, const char * pcName) - : KToolBar(pcName,pWnd,type,bNewLine) - { - setWindowTitle(szLabel); - //toolbars are locked by default - setToolBarsLocked(false); - } -#else - KviTalToolBar::KviTalToolBar(const QString & szLabel, QMainWindow * pWnd, Qt::ToolBarArea type, bool bNewLine, const char * pcName) - : QToolBar(szLabel,pWnd) - { - //setFrameStyle(QFrame::NoFrame); - setObjectName(pcName); - if(!layout()) - this->setLayout(new QBoxLayout(QBoxLayout::LeftToRight)); - pWnd->addToolBar(type,this); - } - - KviTalToolBar::KviTalToolBar(QMainWindow * pWnd, const char * pcName) - : QToolBar(pWnd) - { - //setFrameStyle(QFrame::NoFrame); - setObjectName(pcName); - if(!layout()) - this->setLayout(new QBoxLayout(QBoxLayout::LeftToRight)); - pWnd->addToolBar(this); - } - - QBoxLayout * KviTalToolBar::boxLayout() - { - return (QBoxLayout*)this->layout(); - } - - void KviTalToolBar::setBoxLayout(QBoxLayout * pLayout) - { - this->setLayout(pLayout); - } -#endif // COMPILE_KDE_SUPPORT - - -KviTalToolBar::~KviTalToolBar() -{ -} - -#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES - #include "KviTalToolBar.moc" -#endif // COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/kvilib/tal/KviTalToolBar.h b/src/kvilib/tal/KviTalToolBar.h deleted file mode 100644 index 9f2461a87..000000000 --- a/src/kvilib/tal/KviTalToolBar.h +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef _KVI_TAL_TOOLBAR_H_ -#define _KVI_TAL_TOOLBAR_H_ -//============================================================================= -// -// File : KviTalToolBar.h -// Creation date : Mon Aug 13 05:05:44 2001 GMT by Szymon Stefanek -// -// This file is part of the KVIrc irc client distribution -// Copyright (C) 2001-2010 Szymon Stefanek (pragma at kvirc dot net) -// Copyright (C) 2008 Elvio Basello (hellvis69 at netsons dot org) -// -// 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 opinion) 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. -// -//============================================================================= - -/** -* \file KviTalToolBar.h -* \author Szymon Stefanek -* \brief Toolkit Abstraction Layer class -*/ - -#include "kvi_settings.h" - -/** -* \class KviTalToolBar -* \brief Toolkit Abstraction Layer: toolbar class -*/ - -#ifdef COMPILE_KDE_SUPPORT - -#include <ktoolbar.h> - -class KVILIB_API KviTalToolBar : public KToolBar - -#else // COMPILE_KDE_SUPPORT - -#include <QToolBar> -#include <QMainWindow> -#include <QBoxLayout> - -class KVILIB_API KviTalToolBar : public QToolBar - -#endif // COMPILE_KDE_SUPPORT - -{ - Q_OBJECT -public: - /** - * \brief Constructs a toolbar object - * \param szLabel The label of the toolbar - * \param pWnd The mainwindow where to attach the toolbar - * \param type The type of the toolbar - * \param bNewLine Whether to add a newline - * \param pcName The name of the toolbar - * \return KviTalToolBar - */ - KviTalToolBar(const QString & szLabel, QMainWindow * pWnd, Qt::ToolBarArea type = Qt::TopToolBarArea, bool bNewLine = false, const char * pcName = 0); - - /** - * \brief Destroys a toolbar object - */ - ~KviTalToolBar(); -#ifndef COMPILE_KDE_SUPPORT -public: - /** - * \brief Constructs a toolbar object - * \param pWnd The mainwindow where to attach the toolbar - * \param pcName The name of the toolbar - * \return KviTalToolBar - */ - KviTalToolBar(QMainWindow * pWnd, const char * pcName = 0); -public: - /** - * \brief Returns the box layout object - * \return QBoxLayout * - */ - QBoxLayout * boxLayout(); - - /** - * \brief Sets the box layout - * \param pLayout The box layout - * \return void - */ - void setBoxLayout(QBoxLayout * pLayout); -#endif // COMPILE_KDE_SUPPORT - -}; - -#endif //_KVI_TAL_TOOLBAR_H_ diff --git a/src/kvirc/kernel/KviAction.cpp b/src/kvirc/kernel/KviAction.cpp index 83241797a..0edeb5ee6 100644 --- a/src/kvirc/kernel/KviAction.cpp +++ b/src/kvirc/kernel/KviAction.cpp @@ -32,6 +32,7 @@ #include "KviQueryWindow.h" #include "KviTalPopupMenu.h" +#include <QAction> KviActionCategory::KviActionCategory(const QString & szName, const QString & szVisibleName, const QString & szDescription) : m_szName(szName), m_szVisibleName(szVisibleName), m_szDescription(szDescription) @@ -44,23 +45,23 @@ KviActionCategory::~KviActionCategory() KviAction::KviAction(QObject * pParent, const QString & szName, const QString & szVisibleName, const QString & szDescription, KviActionCategory * pCategory, const QString & szBigIconId, const QString & szSmallIconId, unsigned int uFlags, const QString & szKeySequence) -: QObject(pParent),m_szName(szName),m_szVisibleName(szVisibleName),m_szDescription(szDescription),m_pCategory(pCategory),m_szBigIconId(szBigIconId),m_szSmallIconId(szSmallIconId),m_pWidgetList(NULL),m_uInternalFlags(KviAction::Enabled),m_uFlags(uFlags),m_szKeySequence(szKeySequence),m_pAccel(NULL) +: QObject(pParent),m_szName(szName),m_szVisibleName(szVisibleName),m_szDescription(szDescription),m_pCategory(pCategory),m_szBigIconId(szBigIconId),m_szSmallIconId(szSmallIconId),m_pActionList(NULL),m_uInternalFlags(KviAction::Enabled),m_uFlags(uFlags),m_szKeySequence(szKeySequence),m_pAccel(NULL) { } KviAction::KviAction(QObject * pParent, const QString & szName, const QString & szVisibleName, const QString & szDescription, KviActionCategory * pCategory, const QString & szBigIconId, const KviIconManager::SmallIcon eIcon, unsigned int uFlags, const QString & szKeySequence) -: QObject(pParent),m_szName(szName),m_szVisibleName(szVisibleName),m_szDescription(szDescription),m_pCategory(pCategory),m_szBigIconId(szBigIconId),m_eIcon(eIcon),m_pWidgetList(NULL),m_uInternalFlags(KviAction::Enabled),m_uFlags(uFlags),m_szKeySequence(szKeySequence),m_pAccel(NULL) +: QObject(pParent),m_szName(szName),m_szVisibleName(szVisibleName),m_szDescription(szDescription),m_pCategory(pCategory),m_szBigIconId(szBigIconId),m_eIcon(eIcon),m_pActionList(NULL),m_uInternalFlags(KviAction::Enabled),m_uFlags(uFlags),m_szKeySequence(szKeySequence),m_pAccel(NULL) { } KviAction::~KviAction() { - if(m_pWidgetList) + if(m_pActionList) { - for(QWidget * pWidget = m_pWidgetList->first(); pWidget; pWidget = m_pWidgetList->next()) - disconnect(pWidget,SIGNAL(destroyed()),this,SLOT(widgetDestroyed())); - m_pWidgetList->setAutoDelete(true); - delete m_pWidgetList; + for(QAction * pAction = m_pActionList->first(); pAction; pAction = m_pActionList->next()) + disconnect(pAction,SIGNAL(destroyed()),this,SLOT(actionDestroyed())); + m_pActionList->setAutoDelete(true); + delete m_pActionList; } if(m_pAccel) @@ -115,20 +116,20 @@ void KviAction::setEnabled(bool bEnabled) else m_uInternalFlags &= ~KviAction::Enabled; - if(m_pWidgetList) + if(m_pActionList) { if(bEnabled) { - for(QWidget * pWidget = m_pWidgetList->first(); pWidget; pWidget = m_pWidgetList->next()) + for(QAction * pAction = m_pActionList->first(); pAction; pAction = m_pActionList->next()) { - if(!pWidget->isEnabled()) - pWidget->setEnabled(true); + if(!pAction->isEnabled()) + pAction->setEnabled(true); } } else { - for(QWidget * pWidget = m_pWidgetList->first(); pWidget; pWidget = m_pWidgetList->next()) + for(QAction * pAction = m_pActionList->first(); pAction; pAction = m_pActionList->next()) { - if(pWidget->isEnabled()) - pWidget->setEnabled(false); + if(pAction->isEnabled()) + pAction->setEnabled(false); } } } @@ -211,13 +212,12 @@ void KviAction::setup() void KviAction::reloadImages() { - if(!m_pWidgetList) + if(!m_pActionList) return; QPixmap * pPix = bigIcon(); - for(QWidget * pWidget = m_pWidgetList->first(); pWidget; pWidget = m_pWidgetList->next()) + for(QAction * pAction = m_pActionList->first(); pAction; pAction = m_pActionList->next()) { - if(pWidget->inherits("QToolButton")) - ((QToolButton *)pWidget)->setIcon(pPix ? *pPix : QPixmap()); + pAction->setIcon(pPix ? *pPix : QPixmap()); } } @@ -467,44 +467,44 @@ bool KviAction::addToPopupMenu(KviTalPopupMenu * pMenu) return true; } -void KviAction::widgetDestroyed() +void KviAction::actionDestroyed() { - if(!m_pWidgetList) + if(!m_pActionList) return; - QWidget * pWidget = (QWidget *)sender(); - m_pWidgetList->removeRef(pWidget); + QAction * pAction = (QAction *)sender(); + m_pActionList->removeRef(pAction); } -void KviAction::registerWidget(QWidget * pWidget) +void KviAction::registerAction(QAction * pAction) { - connect(pWidget,SIGNAL(destroyed()),this,SLOT(widgetDestroyed())); - if(!m_pWidgetList) + connect(pAction,SIGNAL(destroyed()),this,SLOT(actionDestroyed())); + if(!m_pActionList) { - m_pWidgetList = new KviPointerList<QWidget>; - m_pWidgetList->setAutoDelete(false); + m_pActionList = new KviPointerList<QAction>; + m_pActionList->setAutoDelete(false); } - m_pWidgetList->append(pWidget); + m_pActionList->append(pAction); } -QWidget * KviAction::addToCustomToolBar(KviCustomToolBar * pParentToolBar) +QAction * KviAction::addToCustomToolBar(KviCustomToolBar * pParentToolBar) { if(!setupDone()) setup(); + QPixmap * pPix = bigIcon(); - QToolButton * pTool = new QToolButton(pParentToolBar); + + QAction * pAction = new QAction(pPix ? *pPix : QPixmap(), visibleName(), pParentToolBar); + // important: when customizing the toolbar, we'll get the action name from QAction::objectName(); + pAction->setObjectName(m_szName); + pParentToolBar->addAction(pAction); - pTool->setIcon(pPix ? *pPix : QPixmap()); - pTool->setText(visibleName()); - pTool->setToolTip(visibleName()); - pTool->setObjectName(m_szName.toUtf8().data()); - connect(pTool,SIGNAL(clicked()),this,SLOT(activate())); + connect(pAction,SIGNAL(triggered()),this,SLOT(activate())); - QAction * pAction = pParentToolBar->addWidget(pTool); pAction->setVisible(true); if(!isEnabled()) - pTool->setEnabled(false); - registerWidget(pTool); - return pTool; + pAction->setEnabled(false); + registerAction(pAction); + return pAction; } void KviAction::activate() diff --git a/src/kvirc/kernel/KviAction.h b/src/kvirc/kernel/KviAction.h index 3b99f90dd..4a0998f84 100644 --- a/src/kvirc/kernel/KviAction.h +++ b/src/kvirc/kernel/KviAction.h @@ -177,7 +177,7 @@ protected: QString m_szBigIconId; QString m_szSmallIconId; QString m_eIcon; - KviPointerList<QWidget> * m_pWidgetList; + KviPointerList<QAction> * m_pActionList; unsigned short int m_uInternalFlags; unsigned int m_uFlags; QString m_szKeySequence; @@ -280,9 +280,9 @@ public: /** * \brief Adds the action to the given toolbar * \param pParentToolBar The toolbar where to add the action - * \return QWidget * + * \return QAction * */ - virtual QWidget * addToCustomToolBar(KviCustomToolBar * pParentToolBar); + virtual QAction * addToCustomToolBar(KviCustomToolBar * pParentToolBar); /** * \brief Destroys itself. Maybe the best function in the whole APIs :) @@ -304,10 +304,10 @@ protected: virtual void setup(); /** - * \brief Returns the list of widgets associated to the action - * \return KviPointerList<QWidget> * + * \brief Returns the list of actions associated to the action + * \return KviPointerList<QAction> * */ - KviPointerList<QWidget> * widgetList(){ return m_pWidgetList; }; + KviPointerList<QAction> * actionList(){ return m_pActionList; }; /** * \brief Registers the action shortcut in the application @@ -322,11 +322,11 @@ protected: void unregisterAccelerator(); /** - * \brief Adds the widget to the list - * \param pWidget The widget to add + * \brief Adds the action to the list + * \param pAction The action to add * \return void */ - void registerWidget(QWidget * pWidget); + void registerAction(QAction * pAction); public slots: /** * \brief Activates the action @@ -338,12 +338,12 @@ public slots: virtual void activate(); protected slots: /** - * \brief Removes the widget from the list + * \brief Removes the action from the list * - * Called when the widget is being destroyed + * Called when the action is being destroyed * \return void */ - virtual void widgetDestroyed(); + virtual void actionDestroyed(); /** * \brief Reloads the images diff --git a/src/kvirc/kernel/KviCoreActions.cpp b/src/kvirc/kernel/KviCoreActions.cpp index 7231f6549..32cb94fc1 100644 --- a/src/kvirc/kernel/KviCoreActions.cpp +++ b/src/kvirc/kernel/KviCoreActions.cpp @@ -455,30 +455,48 @@ bool KviIrcContextDisplayAction::addToPopupMenu(KviTalPopupMenu *) return true; } -QWidget * KviIrcContextDisplayAction::addToCustomToolBar(KviCustomToolBar *t) +QAction * KviIrcContextDisplayAction::addToCustomToolBar(KviCustomToolBar *t) { if(!setupDone()) setup(); - KviIrcContextDisplay * w = new KviIrcContextDisplay(t,"kvirc.irccontextdisplay"); - t->addWidget(w); - registerWidget(w); - return w; + KviIrcContextDisplay * w = new KviIrcContextDisplay(t,KVI_COREACTION_IRCCONTEXTDISPLAY); + QAction * pAction = t->addWidget(w); + // important: when customizing the toolbar, we'll get the action name from QAction::objectName(); + pAction->setObjectName(KVI_COREACTION_IRCCONTEXTDISPLAY); + registerAction(pAction); + return pAction; } void KviIrcContextDisplayAction::activeContextChanged() { - if(m_pWidgetList) + if(m_pActionList) { - for(QWidget * w = m_pWidgetList->first();w;w = m_pWidgetList->next()) - w->update(); + for(QAction * a = m_pActionList->first();a;a = m_pActionList->next()) + { + QToolBar *t = (QToolBar*) a->parentWidget(); + if(t) + { + KviIrcContextDisplay * w = (KviIrcContextDisplay *) t->widgetForAction(a); + if(w) + w->update(); + } + } } } void KviIrcContextDisplayAction::activeContextStateChanged() { - if(m_pWidgetList) + if(m_pActionList) { - for(QWidget * w = m_pWidgetList->first();w;w = m_pWidgetList->next()) - w->update(); + for(QAction * a = m_pActionList->first();a;a = m_pActionList->next()) + { + QToolBar *t = (QToolBar*) a->parentWidget(); + if(t) + { + KviIrcContextDisplay * w = (KviIrcContextDisplay *) t->widgetForAction(a); + if(w) + w->update(); + } + } } } @@ -510,13 +528,15 @@ bool KviSeparatorAction::addToPopupMenu(KviTalPopupMenu * p) return true; } -QWidget * KviSeparatorAction::addToCustomToolBar(KviCustomToolBar * t) +QAction * KviSeparatorAction::addToCustomToolBar(KviCustomToolBar * t) { if(!setupDone()) setup(); - QWidget * w = new KviCustomToolBarSeparator(t,"kvirc.separator"); - registerWidget(w); - t->addWidget(w); - return w; + QWidget * w = new KviCustomToolBarSeparator(t,KVI_COREACTION_SEPARATOR); + QAction * pAction = t->addWidget(w); + // important: when customizing the toolbar, we'll get the action name from QAction::objectName(); + pAction->setObjectName(KVI_COREACTION_SEPARATOR); + registerAction(pAction); + return pAction; } @@ -547,7 +567,7 @@ void KviConnectAction::activeContextChanged() void KviConnectAction::activeContextStateChanged() { - KviPointerList<QWidget> * bl = widgetList(); + KviPointerList<QAction> * bl = actionList(); if(!bl)return; QPixmap * p; @@ -580,14 +600,14 @@ void KviConnectAction::activeContextStateChanged() if(p) { - for(QToolButton * b = (QToolButton *)bl->first();b;b =(QToolButton *)bl->next()) + for(QAction * b = bl->first();b;b =bl->next()) { if(!b->isEnabled())b->setEnabled(true); b->setIcon(QIcon(*p)); b->setText(txt); } } else { - for(QToolButton * b = (QToolButton *)bl->first();b;b = (QToolButton *)bl->next()) + for(QAction * b = bl->first();b;b = bl->next()) { if(b->isEnabled())b->setEnabled(false); } @@ -653,19 +673,17 @@ bool KviConnectAction::addToPopupMenu(KviTalPopupMenu *p) return true; } -QWidget * KviConnectAction::addToCustomToolBar(KviCustomToolBar *t) +QAction * KviConnectAction::addToCustomToolBar(KviCustomToolBar *t) { if(!setupDone())setup(); - QToolButton * b = new QToolButton(t); - b->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_DISCONNECTED))); - b->setText(m_szConnectString); - b->setStatusTip(m_szConnectString); - b->setObjectName(name()); - connect(b, SIGNAL(clicked()), this, SLOT(activate())); - registerWidget(b); - t->addWidget(b); + QAction * pAction = new QAction(*(g_pIconManager->getBigIcon(KVI_BIGICON_DISCONNECTED)), m_szConnectString, t); + pAction->setStatusTip(m_szConnectString); + pAction->setObjectName(KVI_COREACTION_CONNECT); + t->addAction(pAction); + connect(pAction, SIGNAL(triggered()), this, SLOT(activate())); + registerAction(pAction); activeContextStateChanged(); - return b; + return pAction; } @@ -727,24 +745,20 @@ bool KviSubmenuAction::addToPopupMenu(KviTalPopupMenu *p) return true; } -QWidget * KviSubmenuAction::addToCustomToolBar(KviCustomToolBar *t) +QAction * KviSubmenuAction::addToCustomToolBar(KviCustomToolBar *t) { if(!setupDone()) setup(); - QToolButton * b = new QToolButton(t); QPixmap * p = bigIcon(); - b->setIcon(p ? *p : QPixmap()); - b->setText(visibleName()); - b->setStatusTip(visibleName()); - b->setObjectName(name()); - connect(b, SIGNAL(clicked()), this, SLOT(activate())); - - b->setMenu(m_pPopup); - b->setPopupMode( scriptCode().isEmpty() ? QToolButton::InstantPopup : QToolButton::MenuButtonPopup); - t->addWidget(b); - registerWidget(b); - if(!isEnabled()) b->setEnabled(false); - return b; + QAction * pAction = new QAction(p ? *p : QPixmap(), visibleName(), t); + pAction->setStatusTip(visibleName()); + pAction->setObjectName(name()); + t->addAction(pAction); + connect(pAction, SIGNAL(triggered()), this, SLOT(activate())); + pAction->setMenu(m_pPopup); + registerAction(pAction); + if(!isEnabled()) pAction->setEnabled(false); + return pAction; } @@ -1002,7 +1016,7 @@ void KviGoAwayAction::activeContextChanged() void KviGoAwayAction::activeContextStateChanged() { - KviPointerList<QWidget> * bl = widgetList(); + KviPointerList<QAction> * bl = actionList(); if(!bl)return; QPixmap * p; @@ -1029,7 +1043,7 @@ void KviGoAwayAction::activeContextStateChanged() if(p) { - for(QToolButton * b = (QToolButton *)bl->first();b;b =(QToolButton *)bl->next()) + for(QAction * b = bl->first();b;b =bl->next()) { if(!b->isEnabled())b->setEnabled(true); b->setIcon(QIcon(*p)); @@ -1038,7 +1052,7 @@ void KviGoAwayAction::activeContextStateChanged() m_uInternalFlags |= KviAction::Enabled; setEnabled(true); } else { - for(QToolButton * b = (QToolButton *)bl->first();b;b = (QToolButton *)bl->next()) + for(QAction * b = bl->first();b;b = bl->next()) { if(b->isEnabled())b->setEnabled(false); } @@ -1090,21 +1104,19 @@ bool KviGoAwayAction::addToPopupMenu(KviTalPopupMenu *p) return true; } -QWidget * KviGoAwayAction::addToCustomToolBar(KviCustomToolBar *t) +QAction * KviGoAwayAction::addToCustomToolBar(KviCustomToolBar *t) { if(!setupDone())setup(); - QToolButton * b = new QToolButton(t); - b->setIcon(*(g_pIconManager->getBigIcon("kvi_bigicon_nokeyboard.png"))); - b->setText(m_szAwayString); - b->setStatusTip(m_szAwayString); - b->setObjectName(name()); - connect(b, SIGNAL(clicked()), this, SLOT(activate())); + QAction * pAction = new QAction(*(g_pIconManager->getBigIcon("kvi_bigicon_nokeyboard.png")), m_szAwayString, t); + pAction->setStatusTip(m_szAwayString); + pAction->setObjectName(KVI_COREACTION_AWAYBACK); + t->addAction(pAction); + connect(pAction, SIGNAL(triggered()), this, SLOT(activate())); - registerWidget(b); - t->addWidget(b); + registerAction(pAction); activeContextStateChanged(); - return b; + return pAction; } diff --git a/src/kvirc/kernel/KviCoreActions.h b/src/kvirc/kernel/KviCoreActions.h index 978d7cb50..f62818261 100644 --- a/src/kvirc/kernel/KviCoreActions.h +++ b/src/kvirc/kernel/KviCoreActions.h @@ -40,7 +40,7 @@ protected: QString m_szDisconnectString; public: virtual bool addToPopupMenu(KviTalPopupMenu * pMenu); - virtual QWidget * addToCustomToolBar(KviCustomToolBar * pTool); + virtual QAction * addToCustomToolBar(KviCustomToolBar * pTool); protected: virtual void setup(); virtual void reloadImages(); @@ -56,7 +56,7 @@ public: KviSeparatorAction(QObject * pParent); public: virtual bool addToPopupMenu(KviTalPopupMenu * pMenu); - virtual QWidget * addToCustomToolBar(KviCustomToolBar * pTool); + virtual QAction * addToCustomToolBar(KviCustomToolBar * pTool); }; class KviTalPopupMenu; @@ -83,7 +83,7 @@ protected: virtual void setup(); public: virtual bool addToPopupMenu(KviTalPopupMenu * pMenu); - virtual QWidget * addToCustomToolBar(KviCustomToolBar * pTool); + virtual QAction * addToCustomToolBar(KviCustomToolBar * pTool); protected slots: virtual void popupAboutToShow(); virtual void popupActivated(int iId); @@ -159,7 +159,7 @@ public: KviIrcContextDisplayAction(QObject * pParent); public: virtual bool addToPopupMenu(KviTalPopupMenu * pMenu); - virtual QWidget * addToCustomToolBar(KviCustomToolBar * pTool); + virtual QAction * addToCustomToolBar(KviCustomToolBar * pTool); virtual void activeContextStateChanged(); virtual void activeContextChanged(); virtual void setEnabled(bool); @@ -177,7 +177,7 @@ protected: QString m_szBackString; public: virtual bool addToPopupMenu(KviTalPopupMenu * pMenu); - virtual QWidget * addToCustomToolBar(KviCustomToolBar * pTool); + virtual QAction * addToCustomToolBar(KviCustomToolBar * pTool); protected: virtual void setup(); virtual void reloadImages(); diff --git a/src/kvirc/kernel/KviCustomToolBarDescriptor.cpp b/src/kvirc/kernel/KviCustomToolBarDescriptor.cpp index c84e2b1eb..5a29d0c01 100644 --- a/src/kvirc/kernel/KviCustomToolBarDescriptor.cpp +++ b/src/kvirc/kernel/KviCustomToolBarDescriptor.cpp @@ -147,8 +147,7 @@ KviCustomToolBar * KviCustomToolBarDescriptor::createToolBar() { if(!m_pToolBar) { - QByteArray dd = id().toUtf8(); - m_pToolBar = new KviCustomToolBar(this,label(),Qt::TopToolBarArea,false,dd.data()); + m_pToolBar = new KviCustomToolBar(this,label(),Qt::TopToolBarArea,id().toUtf8().data()); fillToolBar(); } return m_pToolBar; @@ -196,8 +195,12 @@ bool KviCustomToolBarDescriptor::load(KviConfigurationFile * cfg) { tmp.setNum(i); QString * p = new QString(cfg->readEntry(tmp)); - if(p->isEmpty())delete p; - else m_pActions->append(p); + if(p->isEmpty()) + { + delete p; + } else { + m_pActions->append(p); + } } return true; } diff --git a/src/kvirc/kernel/KviOptions.cpp b/src/kvirc/kernel/KviOptions.cpp index 6d1ead5c4..04d9b1f4d 100644 --- a/src/kvirc/kernel/KviOptions.cpp +++ b/src/kvirc/kernel/KviOptions.cpp @@ -22,8 +22,6 @@ // //============================================================================= - - #define _KVI_OPTIONS_CPP_ #include "KviOptions.h" @@ -43,20 +41,11 @@ #include "KviInternalCommand.h" #include "KviTheme.h" #include "KviFileUtils.h" -//#include "kvi_textencoding.h" #include <QMessageBox> -#include <QRegExp> -#include <QTextCodec> #include <QDir> #include <QStringList> -//xml parser -//#include <qdom.h> -//!xml parser - -#include <zlib.h> - // KviApplication.cpp extern KVIRC_API int g_iIdentDaemonRunningUsers; @@ -671,7 +660,8 @@ KviUIntOption g_uintOptionsTable[KVI_NUM_UINT_OPTIONS]= UINT_OPTION("NotifierPixmapAlign",0,KviOption_sectFlagNotifier | KviOption_groupTheme), UINT_OPTION("OutputDatetimeFormat",0,KviOption_sectFlagIrcView), UINT_OPTION("OnJoinRequestsDelay",1,KviOption_sectFlagConnection), // FIXME: Wouldn't this be nicer in msecs defaulting to 100-200 ? - UINT_OPTION("ToolBarIconSize",32,KviOption_groupTheme | KviOption_resetReloadImages) + UINT_OPTION("ToolBarIconSize",22,KviOption_groupTheme | KviOption_resetReloadImages), + UINT_OPTION("ToolBarButtonStyle",0,KviOption_groupTheme ) // 0 = Qt::ToolButtonIconOnly }; #define FONT_OPTION(_name,_face,_size,_flags) \ diff --git a/src/kvirc/kernel/KviOptions.h b/src/kvirc/kernel/KviOptions.h index 2f242103e..e1aff80fc 100644 --- a/src/kvirc/kernel/KviOptions.h +++ b/src/kvirc/kernel/KviOptions.h @@ -609,8 +609,9 @@ DECLARE_OPTION_STRUCT(KviStringListOption,QStringList) #define KviOption_uintOutputDatetimeFormat 77 /* irc::verbosity */ #define KviOption_uintOnJoinRequestsDelay 78 #define KviOption_uintToolBarIconSize 79 +#define KviOption_uintToolBarButtonStyle 80 -#define KVI_NUM_UINT_OPTIONS 80 +#define KVI_NUM_UINT_OPTIONS 81 namespace KviIdentdOutputMode { enum Mode { diff --git a/src/kvirc/ui/KviCustomToolBar.cpp b/src/kvirc/ui/KviCustomToolBar.cpp index 322086300..d9ba719d1 100644 --- a/src/kvirc/ui/KviCustomToolBar.cpp +++ b/src/kvirc/ui/KviCustomToolBar.cpp @@ -48,18 +48,20 @@ * - we mix up handling widgets and their corrispective actions (when qt will support drag&drop editing, we'll be able to clean this) */ -KviCustomToolBar::KviCustomToolBar(KviCustomToolBarDescriptor * pDesc, const QString & szLabel, Qt::ToolBarArea type, bool bNewLine, const char * pcName) -: KviToolBar(szLabel,type,bNewLine,pcName) +KviCustomToolBar::KviCustomToolBar(KviCustomToolBarDescriptor * pDesc, const QString & szLabel, Qt::ToolBarArea type, const char * pcName) +: KviToolBar(szLabel,type,pcName) { m_pDescriptor = pDesc; m_pMovedChild = 0; - m_pMovedAction = 0; m_pDraggedChild = 0; m_pFilteredChildren = 0; setAcceptDrops(true); + // if the user removes all the items from this toolbar, keep a minimum size to permit dropping new item + setMinimumSize(16,16); + connect(KviActionManager::instance(),SIGNAL(beginCustomizeToolBars()),this,SLOT(beginCustomize())); connect(KviActionManager::instance(),SIGNAL(endCustomizeToolBars()),this,SLOT(endCustomize())); -// setMinimumSize(20,20); + pDesc->registerToolBar(this); if(KviActionManager::customizingToolBars()) beginCustomize(); // because we will not get the signal @@ -164,25 +166,21 @@ void KviCustomToolBar::syncDescriptor() { // store the item order in the descriptor // There was boxLayouts - QLayout * pLayout = layout(); m_pDescriptor->actions()->clear(); - for(int i=0; i < pLayout->count(); i++) + foreach(QAction *w, actions()) { - if(QWidget * w = pLayout->itemAt(i)->widget()) - { #ifdef COMPILE_ON_MAC - // on mac, we are not able to delete unused widgets from the toolbar while dragging; - // instead, we only hide them. now it's time to clean them'up. (ticket #803) - if(w->isVisible()) - { - m_pDescriptor->actions()->append(new QString(w->objectName())); - } else { - w->deleteLater(); - } -#else + // on mac, we are not able to delete unused widgets from the toolbar while dragging; + // instead, we only hide them. now it's time to clean them'up. (ticket #803) + if(w->isVisible()) + { m_pDescriptor->actions()->append(new QString(w->objectName())); -#endif + } else { + w->deleteLater(); } +#else + m_pDescriptor->actions()->append(new QString(w->objectName())); +#endif } } @@ -239,42 +237,25 @@ void KviCustomToolBar::dragMoveEvent(QDragMoveEvent *e) if(!m_pDraggedChild) return; - int iMe = -1; - int iIdx = dropIndexAt(e->pos(),m_pDraggedChild,&iMe); -// qDebug("DROP INDEX IS %d, ME IS %d",iIdx,iMe); - if(iIdx == iMe) return; // would move over itself - - QWidget * pWidgetToMove = widgetAt(iIdx > iMe ? iIdx+1 : iIdx); -// qDebug("SEARCHING FOR WIDGET TO MOVE AT %d AND FOUND %x (ME=%x)",iIdx > iMe ? iIdx+1 : iIdx,pWidgetToMove,pChild); - if(pWidgetToMove == m_pDraggedChild) + QAction * pActionToMove = actionAt(e->pos()); + if(pActionToMove == m_pDraggedChild) return; // hmmm - bool bDone = false; - QAction * pMyOwnAction = actionForWidget(m_pDraggedChild); + QAction * pMyOwnAction = m_pDraggedChild; if(!pMyOwnAction) return; - QAction * pAction=0; - bool bWasEnabled = m_pDraggedChild->isEnabled(); +// bool bWasEnabled = m_pDraggedChild->isEnabled(); removeAction(pMyOwnAction); - if(pWidgetToMove) + if(pActionToMove) { - pAction = actionForWidget(pWidgetToMove); - if(pAction) - { -// qDebug("AND GOT ACTION FOR THAT WIDGET\n"); - - bDone = true; - pAction = insertWidget(pAction,m_pDraggedChild); - } +// qDebug("AND GOT ACTION FOR THAT WIDGET\n"); + insertAction(pActionToMove,m_pDraggedChild); } else { - pAction = addWidget(m_pDraggedChild); + addAction(m_pDraggedChild); } - - if(!bDone) - pAction = addWidget(m_pDraggedChild); - pAction->setVisible(true); - pAction->setEnabled(bWasEnabled); +// m_pDraggedChild->setVisible(true); +// m_pDraggedChild->setEnabled(bWasEnabled); QEvent ev(QEvent::LayoutRequest); QApplication::sendEvent(this,&ev); @@ -286,10 +267,7 @@ void KviCustomToolBar::dragLeaveEvent(QDragLeaveEvent *) { if(m_pFilteredChildren) m_pFilteredChildren->remove(m_pDraggedChild); // just to be sure - //m_pDraggedChild->reparent(0); - QAction* widgetAction = actionForWidget(m_pDraggedChild); - if(widgetAction) - widgetAction->setVisible(false); + m_pDraggedChild->setVisible(false); /* * This is quite broken at least in qt4.6: @@ -317,152 +295,11 @@ void KviCustomToolBar::dropEvent(QDropEvent * e) // nuthin :) } -int KviCustomToolBar::dropIndexAt(const QPoint & pnt, QWidget * pExclude, int * piExcludeIdx) -{ - // find the widget at the current poisition - // treating exclude as if it was going to be removed - // find also the exclude index if needed - QLayout * pLayout = layout(); - if(piExcludeIdx) - *piExcludeIdx = -1; - int iIdx = 0; - - if(!pLayout) - return 0; -// QLayoutIterator it = l->iterator(); - - // find the children with minimum distance - int iMinDistIdx = -1; - QWidget * pMinDistW = 0; - unsigned int uMinDist = 0xffffffff; - int iExcludeIdx = -1; - QPoint pntExclude; - QWidget * pWidget = 0; - - for (int i=0; i < pLayout->count(); i++) - { - if((pWidget = pLayout->itemAt(i)->widget())) - { - if(uMinDist != 0) - { - int iRight = pWidget->x() + pWidget->width(); - int iBottom = pWidget->y() + pWidget->height(); - if((pnt.x() >= pWidget->x()) && (pnt.y() >= pWidget->y()) && (pnt.x() <= iRight) && (pnt.y() <= iBottom)) - { - // inside the widget - // distance 0 - pMinDistW = pWidget; - iMinDistIdx = iIdx; - uMinDist = 0; - } else { - // outside the widget - // compute the distance - unsigned int uXDist = (pnt.x() < pWidget->x()) ? (pWidget->x() - pnt.x()) : (pnt.x() > iRight ? (pnt.x() - iRight) : 0); - unsigned int uYDist = (pnt.y() < pWidget->y()) ? (pWidget->y() - pnt.y()) : (pnt.y() > iBottom ? (pnt.y() - iBottom) : 0); - if((uXDist < 8192) && (uYDist < 8192)) - { - // it is in reasonable rect - unsigned int uDist = (uXDist * uXDist) + (uYDist * uYDist); - if(uDist < uMinDist) - { - // min distance for now - uMinDist = uDist; - pMinDistW = pWidget; - iMinDistIdx = iIdx; - } - } // else the user has a really HUUUGE screen - } - } // else the minimum distance widget has already been found - if(pWidget == pExclude) - { - iExcludeIdx = iIdx; - pntExclude = pWidget->pos(); - } - } - iIdx++; - } - - if(!pMinDistW) - { - // ops.. not found at all (empty toolbar or really far from any button) - if(orientation() == Qt::Horizontal) - { - if(pnt.x() < (width() / 2)) - iMinDistIdx = 0; // insert at position 0 - else iMinDistIdx = iIdx; - // else insert at the last position found - } else { - if(pnt.y() < (height() / 2)) - iMinDistIdx = 0; // insert at position 0 - else iMinDistIdx = iIdx; - // else insert at the last position found - } - } else { - // got it, check for the exclude idx - if((iExcludeIdx == -1) || (iExcludeIdx != iMinDistIdx)) - { - // would not put it over exclude idx - // check if we have to stay on right or left of the widget found - if(orientation() == Qt::Horizontal) - { - if(pnt.x() > (pMinDistW->x() + (pMinDistW->width() / 2))) - iMinDistIdx++; // need to put it on the right - } else { - if(pnt.y() > (pMinDistW->y() + (pMinDistW->height() / 2))) - iMinDistIdx++; // need to put it below - } - } - - // ok, check again (we might have moved exactly over exclude idx now!) - if((iExcludeIdx != -1) && (iExcludeIdx != iMinDistIdx)) - { - // got the exclude idx by the way and wouldn't put exactly over it - // check if exclude idx is "before" the current possible insert position - // if it is, then lower down the index by one - if(orientation() == Qt::Horizontal) - { - if(pnt.x() > pntExclude.x()) - iMinDistIdx--; // removing exclude will move everything one step back - } else { - if(pnt.y() > pntExclude.y()) - iMinDistIdx--; // removing exclude will move everything one step back - } - } - } - - if(iMinDistIdx < 0) - iMinDistIdx = 0; - if(piExcludeIdx) - *piExcludeIdx = iExcludeIdx; - - return iMinDistIdx; -} - -QWidget * KviCustomToolBar::widgetAt(int iIndex) -{ - QLayout * pLayout = layout(); - if(!pLayout) - return NULL; - - QLayoutItem * it = pLayout->itemAt(iIndex); - if(!it) - return NULL; - - return it->widget(); -} - QAction * KviCustomToolBar::actionForWidget(QWidget * pWidget) { return actionAt(pWidget->x() + 1,pWidget->y() + 1); } -void KviCustomToolBar::mousePressEvent(QMouseEvent * e) -{ - if(KviActionManager::customizingToolBars()) - KviActionManager::instance()->setCurrentToolBar(this); - KviToolBar::mousePressEvent(e); -} - bool KviCustomToolBar::eventFilter(QObject * o,QEvent * e) { if(!KviActionManager::customizingToolBars()) @@ -496,18 +333,19 @@ bool KviCustomToolBar::eventFilter(QObject * o,QEvent * e) o->inherits("QToolBarExtensionWidget") )) { - m_pMovedChild = (QWidget *)o; + QWidget * pMovedWidget = (QWidget *)o; + m_pMovedChild = actionForWidget(pMovedWidget); // allow resizing of children - // FIXME: do it only if the child is really resizable - if(m_pMovedChild->width() > 20) // might be an applet + + if(o->inherits("KviToolBarGraphicalApplet") && + pMovedWidget->width() > 20) // might be an applet { - if(pEvent->pos().x() > (m_pMovedChild->width() - 4)) + if(pEvent->pos().x() > (pMovedWidget->width() - 4)) { - m_pMovedChild = 0; + pMovedWidget = 0; return KviToolBar::eventFilter(o,e); // let the applet handle the event it } } - m_pMovedAction=actionForWidget(m_pMovedChild); // drag out! QDrag * pDrag = new QDrag(this); @@ -525,24 +363,23 @@ bool KviCustomToolBar::eventFilter(QObject * o,QEvent * e) } } - m_pMovedAction->setVisible(false); + m_pMovedChild->setVisible(false); QEvent ev(QEvent::LayoutRequest); QApplication::sendEvent(this,&ev); if(pDrag->exec(Qt::MoveAction) == Qt::MoveAction) { - removeAction(m_pMovedAction); + removeAction(m_pMovedChild); } else { // the user has probably failed to remove the action from the toolbar // flash the trashcan in the customize toolbars dialog KviActionManager::instance()->emitRemoveActionsHintRequest(); - m_pMovedAction->setVisible(true); + m_pMovedChild->setVisible(true); QEvent ev(QEvent::LayoutRequest); QApplication::sendEvent(this,&ev); } m_pMovedChild=0; - m_pMovedAction=0; return true; } } diff --git a/src/kvirc/ui/KviCustomToolBar.h b/src/kvirc/ui/KviCustomToolBar.h index acf8343fb..1f693cdd6 100644 --- a/src/kvirc/ui/KviCustomToolBar.h +++ b/src/kvirc/ui/KviCustomToolBar.h @@ -39,27 +39,23 @@ class KVIRC_API KviCustomToolBar : public KviToolBar friend class KviCustomToolBarDescriptor; Q_OBJECT protected: - KviCustomToolBar(KviCustomToolBarDescriptor * d, const QString & szLabel, Qt::ToolBarArea type = Qt::TopToolBarArea, bool bNewLine = false, const char * pcName = 0); + KviCustomToolBar(KviCustomToolBarDescriptor * d, const QString & szLabel, Qt::ToolBarArea type = Qt::TopToolBarArea, const char * pcName = "unnamed_customtoolbar"); public: ~KviCustomToolBar(); protected: KviCustomToolBarDescriptor * m_pDescriptor; - QWidget * m_pMovedChild; - QAction * m_pMovedAction; - QWidget * m_pDraggedChild; + QAction * m_pMovedChild; + QAction * m_pDraggedChild; KviPointerHashTable<void *,bool> * m_pFilteredChildren; public: KviCustomToolBarDescriptor * descriptor(){ return m_pDescriptor; }; protected: - virtual void mousePressEvent(QMouseEvent * e); virtual void dragEnterEvent(QDragEnterEvent * e); virtual void dragMoveEvent(QDragMoveEvent * e); virtual void dragLeaveEvent(QDragLeaveEvent * e); virtual void dropEvent(QDropEvent * e); virtual void childEvent(QChildEvent * e); virtual bool eventFilter(QObject * o, QEvent * e); - int dropIndexAt(const QPoint & pnt, QWidget * pExclude, int * piExcludeIdx); - QWidget * widgetAt(int iIndex); QAction * actionForWidget(QWidget * pWidget); void drag(QWidget * pChild, const QPoint & pnt); void filterChild(QObject * o); diff --git a/src/kvirc/ui/KviIrcToolBar.cpp b/src/kvirc/ui/KviIrcToolBar.cpp index 99dc45ca1..0009efccb 100644 --- a/src/kvirc/ui/KviIrcToolBar.cpp +++ b/src/kvirc/ui/KviIrcToolBar.cpp @@ -54,7 +54,6 @@ extern QPixmap * g_pShadedChildGlobalDesktopBackground; #endif -static QPixmap * g_pIccMemBuffer = 0; static KviPointerList<KviToolBarGraphicalApplet> * g_pToolBarGraphicalAppletList = 0; KviToolBarGraphicalApplet::KviToolBarGraphicalApplet(QWidget * par,const char * name) @@ -65,7 +64,6 @@ KviToolBarGraphicalApplet::KviToolBarGraphicalApplet(QWidget * par,const char * { g_pToolBarGraphicalAppletList = new KviPointerList<KviToolBarGraphicalApplet>(); g_pToolBarGraphicalAppletList->setAutoDelete(false); - g_pIccMemBuffer = new QPixmap(1,1); } g_pToolBarGraphicalAppletList->append(this); @@ -104,20 +102,9 @@ QSize KviToolBarGraphicalApplet::sizeHint() const return m_sizeHint; } -/* -toolbar.define(default) -{ - applet(thisandthat); - applet(thisandthat); - applet(thisandthat); - applet(thisandthat); -} -*/ - - void KviToolBarGraphicalApplet::mouseMoveEvent(QMouseEvent * e) { - if(e->modifiers() & Qt::LeftButton) + if(e->buttons() & Qt::LeftButton) { if(m_bResizeMode) { @@ -126,7 +113,8 @@ void KviToolBarGraphicalApplet::mouseMoveEvent(QMouseEvent * e) if(w > 480)w = 480; m_sizeHint = QSize(w,22); resize(w,height()); - g_pApp->postEvent(parentWidget(),new QEvent(QEvent::LayoutRequest)); + QEvent ev(QEvent::LayoutRequest); + QApplication::sendEvent(parentWidget(),&ev); } } else { if(e->pos().x() > width() - 4) @@ -158,32 +146,14 @@ KviToolBarGraphicalApplet::~KviToolBarGraphicalApplet() { delete g_pToolBarGraphicalAppletList; g_pToolBarGraphicalAppletList = 0; - delete g_pIccMemBuffer; - g_pIccMemBuffer = 0; - } else { - // resize the mem buffer to match the maximum width / height of the applets - resizeMemBuffer(); } } -void KviToolBarGraphicalApplet::resizeMemBuffer() -{ - int uMaxW = 0; - int uMaxH = 0; - for(KviToolBarGraphicalApplet * a = g_pToolBarGraphicalAppletList->first();a;a = g_pToolBarGraphicalAppletList->next()) - { - if(uMaxW < a->width())uMaxW = a->width(); - if(uMaxH < a->height())uMaxH = a->height(); - } - delete g_pIccMemBuffer; - g_pIccMemBuffer=new QPixmap(uMaxW,uMaxH); -} - -void KviToolBarGraphicalApplet::paintEvent(QPaintEvent *e) +void KviToolBarGraphicalApplet::paintEvent(QPaintEvent *) { if(!isVisible())return; - QPainter pa(g_pIccMemBuffer); + QPainter pa(this); #ifdef COMPILE_PSEUDO_TRANSPARENCY if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing()) @@ -220,9 +190,6 @@ void KviToolBarGraphicalApplet::paintEvent(QPaintEvent *e) pa.setPen(palette().light().color()); pa.drawLine(1,height() - 1,width() - 1,height() - 1); pa.drawLine(width() - 1,1,width() - 1,height()); - - QPainter qt4SucksBecauseItNeedsAnAdditionalQPainter(this); - qt4SucksBecauseItNeedsAnAdditionalQPainter.drawPixmap(e->rect().left(),e->rect().top(),e->rect().width(),e->rect().height(),*g_pIccMemBuffer,e->rect().left(),e->rect().top(),e->rect().width(),e->rect().height()); } void KviToolBarGraphicalApplet::drawContents(QPainter *) @@ -230,24 +197,6 @@ void KviToolBarGraphicalApplet::drawContents(QPainter *) // nothing here } -void KviToolBarGraphicalApplet::resizeEvent(QResizeEvent *) -{ - unsigned int uBufferW = g_pIccMemBuffer->width(); - unsigned int uBufferH = g_pIccMemBuffer->height(); - unsigned int uW = width(); - unsigned int uH = height(); - if((uBufferW != uW) || (uBufferH != uH)) - { - if((uBufferW < uW) && (uBufferH < uH)){ - delete g_pIccMemBuffer; - g_pIccMemBuffer=new QPixmap(uW,uH); - // g_pIccMemBuffer->resize(uW,uH); - } - else resizeMemBuffer(); - } -} - - ////////////////////////////////////////////////////////////////////////////// // // KviIrcContextDisplay @@ -335,14 +284,6 @@ void KviIrcContextDisplay::tipRequest(KviDynamicToolTip * tip,const QPoint &) tip->tip(rect(),txt); } - -/* -QSize KviIrcContextDisplay::sizeHint() const -{ - return QSize(160,22); -} -*/ - #define KVI_APPLETIRCCONTEXTINDICATORWIDTH 12 void KviIrcContextDisplay::drawContents(QPainter * p) diff --git a/src/kvirc/ui/KviIrcToolBar.h b/src/kvirc/ui/KviIrcToolBar.h index ebf26b519..8d5a45846 100644 --- a/src/kvirc/ui/KviIrcToolBar.h +++ b/src/kvirc/ui/KviIrcToolBar.h @@ -55,8 +55,6 @@ private: bool m_bResizeMode; bool m_bSizeLoaded; QSize m_sizeHint; -private: - void resizeMemBuffer(); protected: void setupSizeHint(); @@ -69,7 +67,6 @@ protected: virtual void paintEvent(QPaintEvent *e); virtual void drawContents(QPainter * p); - virtual void resizeEvent(QResizeEvent *e); }; diff --git a/src/kvirc/ui/KviMainWindow.cpp b/src/kvirc/ui/KviMainWindow.cpp index cf8b2fca2..3d6d5ab9b 100644 --- a/src/kvirc/ui/KviMainWindow.cpp +++ b/src/kvirc/ui/KviMainWindow.cpp @@ -29,7 +29,6 @@ #include "KviApplication.h" #include "kvi_settings.h" #include "KviMainWindow.h" -#include "KviOptions.h" #include "KviMenuBar.h" #include "KviMdiManager.h" #include "KviMdiChild.h" @@ -63,6 +62,9 @@ #include "KviTextIconManager.h" #include "kvi_shortcuts.h" +#define _WANT_OPTION_FLAGS_ +#include "KviOptions.h" + #include <QSplitter> #include <QVariant> #include <QLineEdit> @@ -121,6 +123,7 @@ KviMainWindow::KviMainWindow() setCentralWidget(m_pSplitter); setIconSize(KVI_OPTION_UINT(KviOption_uintToolBarIconSize)); + setButtonStyle(KVI_OPTION_UINT(KviOption_uintToolBarButtonStyle)); m_pMdi = new KviMdiManager(m_pSplitter,this,"mdi_manager"); @@ -1030,7 +1033,32 @@ void KviMainWindow::toolbarsPopupSelected(int id) } } +void KviMainWindow::iconSizePopupSelected(QAction *pAction) +{ + if(!pAction) + return; + + bool bOk=false; + uint uSize=pAction->data().toUInt(&bOk); + if(!bOk) + return; + + setIconSize(uSize); + g_pApp->optionResetUpdate(KviOption_resetReloadImages); +} +void KviMainWindow::buttonStylePopupSelected(QAction *pAction) +{ + if(!pAction) + return; + + bool bOk=false; + uint uStyle=pAction->data().toUInt(&bOk); + if(!bOk) + return; + + setButtonStyle(uStyle); +} bool KviMainWindow::focusNextPrevChild(bool next) { @@ -1179,7 +1207,7 @@ void KviMainWindow::switchToNextWindowInContext(void) void KviMainWindow::setIconSize(unsigned int uSize) { if((uSize != 16) && (uSize != 22) && (uSize != 32) && (uSize != 48)) - uSize = 32; + uSize = 22; KVI_OPTION_UINT(KviOption_uintToolBarIconSize) = uSize; @@ -1213,6 +1241,36 @@ void KviMainWindow::setIconSize(unsigned int uSize) } } +void KviMainWindow::setButtonStyle(unsigned int uStyle) +{ + + KVI_OPTION_UINT(KviOption_uintToolBarButtonStyle) = uStyle; + + KviPointerListIterator<KviMexToolBar> it(*(m_pModuleExtensionToolBarList)); + if(it.current()) + { + while(KviMexToolBar * t = it.current()) + { + t->setToolButtonStyle((Qt::ToolButtonStyle) uStyle); + t->update(); + ++it; + } + } + + KviPointerHashTableIterator<QString,KviCustomToolBarDescriptor> it2(*(KviCustomToolBarManager::instance()->descriptors())); + if(it2.current()) + { + while(KviCustomToolBarDescriptor * d = it2.current()) + { + if(d->toolBar()) + { + d->toolBar()->setToolButtonStyle((Qt::ToolButtonStyle) uStyle); + d->toolBar()->update(); + } + ++it2; + } + } +} #ifndef COMPILE_USE_STANDALONE_MOC_SOURCES #include "KviMainWindow.moc" #endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/kvirc/ui/KviMainWindow.h b/src/kvirc/ui/KviMainWindow.h index 90b34a55a..74469d40e 100644 --- a/src/kvirc/ui/KviMainWindow.h +++ b/src/kvirc/ui/KviMainWindow.h @@ -145,9 +145,11 @@ public: // Helper to fill the toolbars popup // it is used by KviToolBar and KviMenuBar void fillToolBarsPopup(KviTalPopupMenu * p); + void fillIconSizePopup(KviTalPopupMenu * p); // Set the size of the icons used by the whole app // Allowed sizes are 16, 22, 32 and 48 void setIconSize(unsigned int uSize); + void setButtonStyle(unsigned int uStyle); public slots: void newConsole(); void executeInternalCommand(int index); @@ -200,6 +202,8 @@ protected slots: void accelActivated(); void toolbarsPopupSelected(int id); + void iconSizePopupSelected(QAction * pAction); + void buttonStylePopupSelected(QAction * pAction); signals: void activeWindowChanged(); // almost never 0.. but may be void activeContextChanged(); // may be 0! diff --git a/src/kvirc/ui/KviToolBar.cpp b/src/kvirc/ui/KviToolBar.cpp index 77f5282f3..e661c2a79 100644 --- a/src/kvirc/ui/KviToolBar.cpp +++ b/src/kvirc/ui/KviToolBar.cpp @@ -27,101 +27,135 @@ #include "KviLocale.h" #include "KviApplication.h" #include "KviTalPopupMenu.h" - -#define _WANT_OPTION_FLAGS_ #include "KviOptions.h" #include <QCursor> #include <QEvent> #include <QMouseEvent> -static KviTalPopupMenu * g_pToolBarContextPopup = 0; -static KviTalPopupMenu * g_pToolBarWindowsPopup = 0; -static KviTalPopupMenu * g_pToolBarIconSizesPopup = 0; -static KviTalPopupMenu * g_pToolBarPositionsPopup = 0; - +static KviTalPopupMenu * g_pToolBarContextPopup = 0; +static KviTalPopupMenu * g_pToolBarWindowsPopup = 0; +static KviTalPopupMenu * g_pToolBarIconSizesPopup = 0; +static KviTalPopupMenu * g_pToolBarButtonStylePopup = 0; +static uint uToolBarInstances = 0; -KviToolBar::KviToolBar(const QString & szLabel, Qt::ToolBarArea type, bool bNewLine, const char * pcName) -: KviTalToolBar(szLabel,g_pMainWindow,type,bNewLine,pcName) +KviToolBar::KviToolBar(const QString & szLabel, Qt::ToolBarArea type, const char * pcName) +: QToolBar(szLabel,g_pMainWindow) { + uToolBarInstances++; + unsigned int uIconSize = KVI_OPTION_UINT(KviOption_uintToolBarIconSize); setIconSize(QSize(uIconSize,uIconSize)); + setToolButtonStyle((Qt::ToolButtonStyle) KVI_OPTION_UINT(KviOption_uintToolBarButtonStyle)); + + setObjectName(pcName); + g_pMainWindow->addToolBar(type,this); } KviToolBar::~KviToolBar() { - if(g_pToolBarContextPopup) - delete g_pToolBarContextPopup; - if(g_pToolBarIconSizesPopup) - delete g_pToolBarIconSizesPopup; - if(g_pToolBarPositionsPopup) - delete g_pToolBarPositionsPopup; - if(g_pToolBarWindowsPopup) - delete g_pToolBarWindowsPopup; + uToolBarInstances--; - g_pToolBarContextPopup = 0; - g_pToolBarIconSizesPopup = 0; - g_pToolBarPositionsPopup = 0; - g_pToolBarWindowsPopup = 0; + // the last instance cleans up the cached popups + if(!uToolBarInstances) + { + if(g_pToolBarButtonStylePopup) + delete g_pToolBarButtonStylePopup; + if(g_pToolBarIconSizesPopup) + delete g_pToolBarIconSizesPopup; + if(g_pToolBarWindowsPopup) + delete g_pToolBarWindowsPopup; + if(g_pToolBarContextPopup) + delete g_pToolBarContextPopup; + + g_pToolBarButtonStylePopup = 0; + g_pToolBarIconSizesPopup = 0; + g_pToolBarWindowsPopup = 0; + g_pToolBarContextPopup = 0; + } } +#define VALID_ICONSIZES_NUM 4 +static KviToolBar::IconSizes valid_iconsizes[VALID_ICONSIZES_NUM] = +{ + { 16, "Small (16x16)" }, + { 22, "Medium (22x22)" }, + { 32, "Large (32x32)" }, + { 48, "Huge (48x48)" } +}; + +#define VALID_BUTTONSTYLES_NUM 5 +static KviToolBar::ButtonStyles valid_buttonstyles[VALID_BUTTONSTYLES_NUM] = +{ + { Qt::ToolButtonIconOnly , "Icon Only" }, + { Qt::ToolButtonTextOnly , "Text Only" }, + { Qt::ToolButtonTextBesideIcon , "Text Beside Icon" }, + { Qt::ToolButtonTextUnderIcon , "Text Under Icon" }, + { Qt::ToolButtonFollowStyle , "Use System Style" } +}; + void KviToolBar::mousePressEvent(QMouseEvent * e) { if(!(e->button() & Qt::RightButton)) { - KviTalToolBar::mousePressEvent(e); + QToolBar::mousePressEvent(e); return; } if(!g_pToolBarContextPopup) + { g_pToolBarContextPopup = new KviTalPopupMenu(); - if(!g_pToolBarIconSizesPopup) g_pToolBarIconSizesPopup = new KviTalPopupMenu(); - if(!g_pToolBarPositionsPopup) - g_pToolBarPositionsPopup = new KviTalPopupMenu(); - if(!g_pToolBarWindowsPopup) g_pToolBarWindowsPopup = new KviTalPopupMenu(); + g_pToolBarButtonStylePopup = new KviTalPopupMenu(); - g_pToolBarContextPopup->clear(); - g_pToolBarIconSizesPopup->clear(); - g_pToolBarPositionsPopup->clear(); - g_pToolBarWindowsPopup->clear(); + g_pToolBarContextPopup->insertItem(__tr2qs("Toolbars"),g_pToolBarWindowsPopup); + g_pToolBarContextPopup->insertItem(__tr2qs("Icon Size"),g_pToolBarIconSizesPopup); + g_pToolBarContextPopup->insertItem(__tr2qs("Button Style"),g_pToolBarButtonStylePopup); - g_pMainWindow->fillToolBarsPopup(g_pToolBarWindowsPopup); - g_pToolBarContextPopup->insertItem(__tr2qs("Toolbars"),g_pToolBarWindowsPopup); + // fill toolbars menu + g_pMainWindow->fillToolBarsPopup(g_pToolBarWindowsPopup); - g_pToolBarContextPopup->insertItem(__tr2qs("Icon Size"),g_pToolBarIconSizesPopup); + // fill icon size menu + QActionGroup * pIconSizeGroup = new QActionGroup(g_pToolBarIconSizesPopup); - g_pToolBarIconSizesPopup->insertItem(__tr2qs("Small (16x16)"),this,SLOT(setIconSize16())); - g_pToolBarIconSizesPopup->insertItem(__tr2qs("Medium (22x22)"),this,SLOT(setIconSize22())); - g_pToolBarIconSizesPopup->insertItem(__tr2qs("Large (32x32)"),this,SLOT(setIconSize32())); - g_pToolBarIconSizesPopup->insertItem(__tr2qs("Huge (48x48)"),this,SLOT(setIconSize48())); + QAction * pTmp = 0; + IconSizes iconSize; + for(uint i = 0; i < VALID_ICONSIZES_NUM; i++) + { + iconSize = valid_iconsizes[i]; - g_pToolBarContextPopup->popup(QCursor::pos()); -} + pTmp = pIconSizeGroup->addAction(g_pToolBarIconSizesPopup->addAction(__tr2qs(iconSize.pcName))); + pTmp->setData((uint)iconSize.uSize); + pTmp->setCheckable(true); + if(iconSize.uSize == KVI_OPTION_UINT(KviOption_uintToolBarIconSize)) + pTmp->setChecked(true); + } -void KviToolBar::setIconSize16() -{ - g_pMainWindow->setIconSize(16); - g_pApp->optionResetUpdate(KviOption_resetReloadImages); -} + connect(pIconSizeGroup,SIGNAL(triggered(QAction*)),g_pMainWindow,SLOT(iconSizePopupSelected(QAction*))); -void KviToolBar::setIconSize22() -{ - g_pMainWindow->setIconSize(22); - g_pApp->optionResetUpdate(KviOption_resetReloadImages); -} + // fill button style menu + QActionGroup * pButtonStyleGroup = new QActionGroup(g_pToolBarButtonStylePopup); -void KviToolBar::setIconSize32() -{ - g_pMainWindow->setIconSize(32); - g_pApp->optionResetUpdate(KviOption_resetReloadImages); -} + pTmp = 0; + ButtonStyles buttonStyle; + for(uint i = 0; i < VALID_BUTTONSTYLES_NUM; i++) + { + buttonStyle = valid_buttonstyles[i]; -void KviToolBar::setIconSize48() -{ - g_pMainWindow->setIconSize(48); - g_pApp->optionResetUpdate(KviOption_resetReloadImages); + pTmp = pButtonStyleGroup->addAction(g_pToolBarButtonStylePopup->addAction(__tr2qs(buttonStyle.pcName))); + pTmp->setData((uint)buttonStyle.uStyle); + pTmp->setCheckable(true); + if(buttonStyle.uStyle == KVI_OPTION_UINT(KviOption_uintToolBarButtonStyle)) + pTmp->setChecked(true); + } + + connect(pButtonStyleGroup,SIGNAL(triggered(QAction*)),g_pMainWindow,SLOT(buttonStylePopupSelected(QAction*))); + + + } + + g_pToolBarContextPopup->popup(QCursor::pos()); } #ifndef COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/kvirc/ui/KviToolBar.h b/src/kvirc/ui/KviToolBar.h index 4e8e21fc4..0d9a95d2d 100644 --- a/src/kvirc/ui/KviToolBar.h +++ b/src/kvirc/ui/KviToolBar.h @@ -24,21 +24,40 @@ // //============================================================================= -#include "KviTalToolBar.h" +#include "kvi_settings.h" -class KVIRC_API KviToolBar : public KviTalToolBar +#include <QToolBar> + +class KVIRC_API KviToolBar : public QToolBar { Q_OBJECT public: - KviToolBar(const QString & szLabel, Qt::ToolBarArea type = Qt::TopToolBarArea, bool bNewLine = false, const char * pcName = 0); + KviToolBar(const QString & szLabel, Qt::ToolBarArea type = Qt::TopToolBarArea, const char * pcName = "unnamed_toolbar"); ~KviToolBar(); + + /** + * \typedef IconSizes + * \struct _IconSizes + * \brief Enumerates the valid icon sizes + */ + typedef struct _IconSizes + { + uint uSize; /**< icon size */ + const char * pcName; /**< menu entry label */ + } IconSizes; + + /** + * \typedef ButtonStyles + * \struct _ButtonStyles + * \brief Enumerates the valid button styles + */ + typedef struct _ButtonStyles + { + uint uStyle; /**< button style */ + const char * pcName; /**< menu entry label */ + } ButtonStyles; protected: virtual void mousePressEvent(QMouseEvent * e); -public slots: - void setIconSize16(); - void setIconSize22(); - void setIconSize32(); - void setIconSize48(); }; #endif //_KVI_TOOLBAR_H_ diff --git a/src/modules/objects/KvsObject_toolBar.cpp b/src/modules/objects/KvsObject_toolBar.cpp index 4dbacc19b..9c799440e 100644 --- a/src/modules/objects/KvsObject_toolBar.cpp +++ b/src/modules/objects/KvsObject_toolBar.cpp @@ -26,12 +26,13 @@ #include "KvsObject_toolBar.h" #include "KviError.h" #include "kvi_debug.h" -#include "KviTalToolBar.h" #include "KviTalMainWindow.h" #include "KviLocale.h" #include "KviIconManager.h" #include "KvsObject_mainWindow.h" +#include <QToolBar> + /* @doc: toolbar @keyterms: @@ -85,7 +86,7 @@ bool KvsObject_toolBar::init(KviKvsRunTimeContext * pContext,KviKvsVariantList * } if(parentObject()->inheritsClass("mainwindow")) { - setObject(new KviTalToolBar(getName(), ((KviTalMainWindow *)parentScriptWidget())), true); + setObject(new QToolBar(getName(), ((KviTalMainWindow *)parentScriptWidget())), true); } else { @@ -98,7 +99,7 @@ bool KvsObject_toolBar::init(KviKvsRunTimeContext * pContext,KviKvsVariantList * KVSO_CLASS_FUNCTION(toolBar,addSeparator) { CHECK_INTERNAL_POINTER(widget()) - ((KviTalToolBar *)widget())->addSeparator(); + ((QToolBar *)widget())->addSeparator(); return true; } KVSO_CLASS_FUNCTION(toolBar,setLabel) @@ -108,19 +109,19 @@ KVSO_CLASS_FUNCTION(toolBar,setLabel) KVSO_PARAMETERS_BEGIN(c) KVSO_PARAMETER("label",KVS_PT_STRING,0,szLabel) KVSO_PARAMETERS_END(c) - ((KviTalToolBar *)widget())->setWindowTitle(szLabel); + ((QToolBar *)widget())->setWindowTitle(szLabel); return true; } KVSO_CLASS_FUNCTION(toolBar,label) { CHECK_INTERNAL_POINTER(widget()) - c->returnValue()->setString(((KviTalToolBar *)widget())->windowTitle()); + c->returnValue()->setString(((QToolBar *)widget())->windowTitle()); return true; } KVSO_CLASS_FUNCTION(toolBar,clear) { CHECK_INTERNAL_POINTER(widget()) - ((KviTalToolBar *)object())->clear(); + ((QToolBar *)object())->clear(); return true; } |
