aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/objects
diff options
context:
space:
mode:
authorGravatar Noldor2008-04-16 17:03:03 +0000
committerGravatar Noldor2008-04-16 17:03:03 +0000
commitcd5ad14c7981140abe0a3e2450eabe1790843def (patch)
tree78032441c9624139fe2e6791fe9f54e09439bf27 /src/modules/objects
parentmore QT4 Objects module port (wip) (diff)
downloadKVIrc-cd5ad14c7981140abe0a3e2450eabe1790843def.tar.gz
KVIrc-cd5ad14c7981140abe0a3e2450eabe1790843def.tar.bz2
KVIrc-cd5ad14c7981140abe0a3e2450eabe1790843def.zip
ported KVS progressbar (completed), popupmenu (wip)
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@1491 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules/objects')
-rw-r--r--src/modules/objects/class_popupmenu.cpp77
-rw-r--r--src/modules/objects/class_popupmenu.h11
-rw-r--r--src/modules/objects/class_progressbar.cpp65
-rw-r--r--src/modules/objects/class_progressbar.h2
4 files changed, 87 insertions, 68 deletions
diff --git a/src/modules/objects/class_popupmenu.cpp b/src/modules/objects/class_popupmenu.cpp
index 067da4822..e15cbdbac 100644
--- a/src/modules/objects/class_popupmenu.cpp
+++ b/src/modules/objects/class_popupmenu.cpp
@@ -30,6 +30,8 @@
#include "kvi_tal_popupmenu.h"
#include <QCursor>
+#include <QMenu>
+#include <QAction>
@@ -162,12 +164,11 @@
KVSO_BEGIN_REGISTERCLASS(KviKvsObject_popupmenu,"popupmenu","widget")
KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"insertItem", functioninsertItem)
- KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"insertWidget", functioninsertWidget)
- KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"insertHandle", functioninsertHandle)
+ //KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"insertWidget", functioninsertWidget)
+// KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"setTitle", functionsetTitle)
KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"exec", functionexec)
KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"insertSeparator", functioninsertSeparator)
KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"removeItem", functionremoveItem)
- KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"removeItemAt", functionremoveItemAt)
// events
KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"highlightedEvent", functionhighlightedEvent)
@@ -186,8 +187,9 @@ KVSO_END_CONSTRUCTOR(KviKvsObject_popupmenu)
bool KviKvsObject_popupmenu::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams)
{
- setObject(new KviTalPopupMenu(parentScriptWidget(), getName()), true);
- connect(widget(),SIGNAL(activated(int)),this,SLOT(slotactivated(int)));
+ identifier=0;
+ SET_OBJECT(QMenu)
+ connect(widget(),SIGNAL(triggered(QAction *)),this,SLOT(slottriggered(QAction *)));
connect(widget(),SIGNAL(highlighted(int)),this,SLOT(slothighlighted(int)));
return true;
}
@@ -202,18 +204,34 @@ bool KviKvsObject_popupmenu::functioninsertItem(KviKvsObjectFunctionCall *c)
if(!widget())return true;
QPixmap *pix = 0;
int id=0;
+ QAction * action;
if(!szIcon.isEmpty())
{
pix = g_pIconManager->getImage(szIcon);
- if (pix) id=((KviTalPopupMenu *)widget())->insertItem(*pix,szItem);
+ if (pix) action=((QMenu *)widget())->addAction(*pix,szItem);
else c->warning(__tr2qs("pix '%Q' doesn't exists"),&szIcon);
}
else
- id=((KviTalPopupMenu *)widget())->insertItem(szItem);
- c->returnValue()->setInteger(id);
+ action=((QMenu *)widget())->addAction(szItem);
+ actionsDict[identifier]=action;
+ c->returnValue()->setInteger(identifier);
+ identifier++;
return true;
}
+/*
+bool KviKvsObject_popupmenu::functionsetTitle(KviKvsObjectFunctionCall *c)
+{
+ QString szTitle;
+ KVSO_PARAMETERS_BEGIN(c)
+ KVSO_PARAMETER("title",KVS_PT_STRING,0,szTitle)
+ KVSO_PARAMETERS_END(c)
+ if(!widget())return true;
+ ((QMenu *)widget())->setTitle(szTitle);
+
+ return true;
+}
+/*
bool KviKvsObject_popupmenu::functioninsertWidget(KviKvsObjectFunctionCall *c)
{
KviKvsObject *pObject;
@@ -240,6 +258,8 @@ bool KviKvsObject_popupmenu::functioninsertWidget(KviKvsObjectFunctionCall *c)
if (widget()) ((KviTalPopupMenu *)widget())->insertItem(((KviTalPopupMenu *)(pObject->object())));
return true;
}
+
+
bool KviKvsObject_popupmenu::functioninsertHandle(KviKvsObjectFunctionCall *c)
{
KviKvsObject *ob;
@@ -271,11 +291,12 @@ bool KviKvsObject_popupmenu::functioninsertHandle(KviKvsObjectFunctionCall *c)
c->returnValue()->setInteger(id);
return true;
}
+*/
bool KviKvsObject_popupmenu::functionexec(KviKvsObjectFunctionCall *c)
{
if(!c->params()->count())
{
- ((KviTalPopupMenu *)widget())->exec(QCursor::pos());
+ ((QMenu *)widget())->exec(QCursor::pos());
return true;
}
@@ -305,7 +326,7 @@ bool KviKvsObject_popupmenu::functionexec(KviKvsObjectFunctionCall *c)
return true;
}
- ((KviTalPopupMenu *)widget())->exec(((QWidget *)(pObject->object()))->mapToGlobal(QPoint(iX,iY)) );
+ ((QMenu *)widget())->exec(((QWidget *)(pObject->object()))->mapToGlobal(QPoint(iX,iY)) );
return true;
}
@@ -315,26 +336,23 @@ bool KviKvsObject_popupmenu::functionremoveItem(KviKvsObjectFunctionCall *c)
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("item_id",KVS_PT_UNSIGNEDINTEGER,0,uItem)
KVSO_PARAMETERS_END(c)
- if(widget()) ((KviTalPopupMenu *)widget())->removeItem(uItem);
- return true;
-}
-bool KviKvsObject_popupmenu::functionremoveItemAt(KviKvsObjectFunctionCall *c)
-{
- kvs_uint_t uIndex;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex)
- KVSO_PARAMETERS_END(c)
- if(widget())((KviTalPopupMenu *)widget())->removeItemAt(uIndex);
+ QAction * action=actionsDict.value(uItem);
+ if(widget() && action){
+ ((QMenu *)widget())->removeAction(action);
+ identifier--;
+ }
return true;
}
+
bool KviKvsObject_popupmenu::functioninsertSeparator(KviKvsObjectFunctionCall *c)
{
- kvs_uint_t uIndex;
+ kvs_uint_t iIndex;
KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex)
+ KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,iIndex)
KVSO_PARAMETERS_END(c)
- if(widget())((KviTalPopupMenu *)widget())->insertSeparator(uIndex);
+ QAction * action=actionsDict.value(iIndex);
+ if(widget()&& action)((QMenu *)widget())->insertSeparator(action);
return true;
}
@@ -348,9 +366,18 @@ bool KviKvsObject_popupmenu::functionhighlightedEvent(KviKvsObjectFunctionCall *
emitSignal("highlighted",c,c->params());
return true;
}
-void KviKvsObject_popupmenu::slotactivated(int i)
+void KviKvsObject_popupmenu::slottriggered(QAction *a)
{
- KviKvsVariantList params(new KviKvsVariant((kvs_int_t)i));
+ QHashIterator<int, QAction *> i(actionsDict);
+ kvs_int_t count=0;
+ bool found=false;
+ while (i.hasNext())
+ {
+ i.next();
+ if (i.value()!= a) count++;
+ else break;
+ }
+ KviKvsVariantList params(new KviKvsVariant(count));
callFunction(this,"activatedEvent",&params);
}
bool KviKvsObject_popupmenu::functionactivatedEvent(KviKvsObjectFunctionCall *c)
diff --git a/src/modules/objects/class_popupmenu.h b/src/modules/objects/class_popupmenu.h
index 3ba2ca464..f47601986 100644
--- a/src/modules/objects/class_popupmenu.h
+++ b/src/modules/objects/class_popupmenu.h
@@ -26,7 +26,7 @@
#include "class_widget.h"
#include "object_macros.h"
-
+#include <QHash>
class KviKvsObject_popupmenu : public KviKvsObject_widget
{
Q_OBJECT
@@ -37,9 +37,12 @@ public:
protected:
virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams);
+ QHash<int,QAction *> actionsDict;
+ int identifier;
bool functioninsertItem(KviKvsObjectFunctionCall *c);
- bool functioninsertWidget(KviKvsObjectFunctionCall *c);
- bool functioninsertHandle(KviKvsObjectFunctionCall *c);
+ //bool functionsetTitle(KviKvsObjectFunctionCall *c);
+ //bool functioninsertWidget(KviKvsObjectFunctionCall *c);
+ //bool functioninsertHandle(KviKvsObjectFunctionCall *c);
bool functionexec(KviKvsObjectFunctionCall *c);
bool functionremoveItem(KviKvsObjectFunctionCall *c);
bool functionremoveItemAt(KviKvsObjectFunctionCall *c);
@@ -48,7 +51,7 @@ protected:
bool functionhighlightedEvent(KviKvsObjectFunctionCall *c);
protected slots:
- void slotactivated(int);
+ void slottriggered(QAction *);
void slothighlighted(int);
};
diff --git a/src/modules/objects/class_progressbar.cpp b/src/modules/objects/class_progressbar.cpp
index ee43e8dbe..068f90224 100644
--- a/src/modules/objects/class_progressbar.cpp
+++ b/src/modules/objects/class_progressbar.cpp
@@ -27,8 +27,10 @@
#include "kvi_locale.h"
#include "kvi_iconmanager.h"
-#include <q3progressbar.h>
-#define KVI_PROGRESS_BAR Q3ProgressBar
+#include <QProgressBar>
+
+
+
/*
@doc: progressbar
@@ -55,12 +57,6 @@
See also [classfnc]$setProgress[/classfnc]()
!fn: $reset()
Reset the progress bar.
- !fn: $setCenterIndicator(<bEnabled:boolean>)
- Sets whether the indicator string should be centered to on.
- See also [classfnc]$isCenterIndicator[/classfnc]()
- !fn: <boolean> $isCenterIndicator()
- This property holds whether the indicator string should be centered.
- See also [classfnc]$setCenterIndicator[/classfnc]()
!fn: $setPercentageVisible(<bVisible,boolean>)
Sets whether the current progress value is displayed.
See also [classfnc]$isPercentageVisible[/classfnc]()
@@ -73,9 +69,7 @@ KVSO_BEGIN_REGISTERCLASS(KviKvsObject_progressbar,"progressbar","widget")
KVSO_REGISTER_HANDLER(KviKvsObject_progressbar,"setProgress", functionSetProgress)
KVSO_REGISTER_HANDLER(KviKvsObject_progressbar,"setTotalSteps", functionSetTotalSteps)
KVSO_REGISTER_HANDLER(KviKvsObject_progressbar,"reset", functionReset)
- KVSO_REGISTER_HANDLER(KviKvsObject_progressbar,"setCenterIndicator", functionSetCenterIndicator)
KVSO_REGISTER_HANDLER(KviKvsObject_progressbar,"setPercentageVisible", functionSetPercentageVisible)
- KVSO_REGISTER_HANDLER(KviKvsObject_progressbar,"isCenterIndicator", functionCenterIndicator)
KVSO_REGISTER_HANDLER(KviKvsObject_progressbar,"isPercentageVisible", functionPercentageVisible)
KVSO_END_REGISTERCLASS(KviKvsObject_progressbar)
@@ -90,52 +84,46 @@ KVSO_END_CONSTRUCTOR(KviKvsObject_progressbar)
bool KviKvsObject_progressbar::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams)
{
- Q3ProgressBar *pbar=new Q3ProgressBar(parentScriptWidget());
- pbar->setObjectName(getName());
- setObject(pbar,true);
+ SET_OBJECT (QProgressBar)
return true;
}
-
bool KviKvsObject_progressbar::functionSetProgress(KviKvsObjectFunctionCall *c)
{
- kvs_uint_t iProgress;
+ kvs_uint_t iValue;
KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("step_value",KVS_PT_UNSIGNEDINTEGER,0,iProgress)
+ KVSO_PARAMETER("step_value",KVS_PT_UNSIGNEDINTEGER,0,iValue)
KVSO_PARAMETERS_END(c)
- if (widget()) ((KVI_PROGRESS_BAR *)widget())->setProgress(iProgress);
+ if (widget()) ((QProgressBar *)widget())->setValue(iValue);
return true;
}
-bool KviKvsObject_progressbar::functionSetTotalSteps(KviKvsObjectFunctionCall *c)
+/*
+bool KviKvsObject_progressbar::functionSetProgress(KviKvsObjectFunctionCall *c)
{
- kvs_uint_t iSteps;
+ kvs_uint_t iValue;
KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("total_steps",KVS_PT_UNSIGNEDINTEGER,0,iSteps)
+ KVSO_PARAMETER("step_value",KVS_PT_UNSIGNEDINTEGER,0,iValue)
KVSO_PARAMETERS_END(c)
- if (widget()) ((KVI_PROGRESS_BAR *)widget())->setTotalSteps(iSteps);
+ if (widget()) ((QProgressBar *)widget())->setValue(iValue);
return true;
}
-
-bool KviKvsObject_progressbar::functionReset(KviKvsObjectFunctionCall *c)
-{
- if (widget()) ((KVI_PROGRESS_BAR *)widget())->reset();
- return true;
-}
-
-bool KviKvsObject_progressbar::functionSetCenterIndicator(KviKvsObjectFunctionCall *c)
+*/
+bool KviKvsObject_progressbar::functionSetTotalSteps(KviKvsObjectFunctionCall *c)
{
- bool bFlag;
+ kvs_uint_t iMax;
KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bFlag)
+ KVSO_PARAMETER("total_steps",KVS_PT_UNSIGNEDINTEGER,0,iMax)
KVSO_PARAMETERS_END(c)
- if(widget()) ((KVI_PROGRESS_BAR *)widget())->setCenterIndicator(bFlag);
- return true;
+ if (widget()) ((QProgressBar *)widget())->setMaximum(iMax);
+ return true;
}
-bool KviKvsObject_progressbar::functionCenterIndicator(KviKvsObjectFunctionCall *c)
+
+bool KviKvsObject_progressbar::functionReset(KviKvsObjectFunctionCall *c)
{
- if (widget()) c->returnValue()->setBoolean(((KVI_PROGRESS_BAR *)widget())->centerIndicator());
+ if (widget()) ((QProgressBar *)widget())->reset();
return true;
}
+
bool KviKvsObject_progressbar::functionSetPercentageVisible(KviKvsObjectFunctionCall *c)
{
bool bEnabled;
@@ -143,11 +131,14 @@ bool KviKvsObject_progressbar::functionSetPercentageVisible(KviKvsObjectFunction
KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled)
KVSO_PARAMETERS_END(c)
if(widget())
- ((KVI_PROGRESS_BAR *)widget())->setPercentageVisible(bEnabled);
+ ((QProgressBar *)widget())->setTextVisible(bEnabled);
return true;
}
+
bool KviKvsObject_progressbar::functionPercentageVisible(KviKvsObjectFunctionCall *c)
{
- if (widget()) c->returnValue()->setBoolean(((KVI_PROGRESS_BAR *)widget())->percentageVisible());
+ if (widget()) c->returnValue()->setBoolean(((QProgressBar *)widget())->isTextVisible());
return true;
}
+
+
diff --git a/src/modules/objects/class_progressbar.h b/src/modules/objects/class_progressbar.h
index f717c19ea..b55b8f4e2 100644
--- a/src/modules/objects/class_progressbar.h
+++ b/src/modules/objects/class_progressbar.h
@@ -41,8 +41,6 @@ protected:
bool functionSetTotalSteps(KviKvsObjectFunctionCall *c);
bool functionReset(KviKvsObjectFunctionCall *c);
bool functionSetPercentageVisible(KviKvsObjectFunctionCall *c);
- bool functionSetCenterIndicator(KviKvsObjectFunctionCall *c);
- bool functionCenterIndicator(KviKvsObjectFunctionCall *c);
bool functionPercentageVisible(KviKvsObjectFunctionCall *c);
};