From a6d58bb6052ac8cb01805a48c4ad2f129126116f Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 24 Feb 2010 02:13:59 +0000 Subject: Added KDE3 version of kvirc git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kvirc@1095341 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/modules/objects/Makefile.am | 143 +++ src/modules/objects/class_button.cpp | 178 +++ src/modules/objects/class_button.h | 58 + src/modules/objects/class_buttongroup.cpp | 87 ++ src/modules/objects/class_buttongroup.h | 44 + src/modules/objects/class_checkbox.cpp | 128 ++ src/modules/objects/class_checkbox.h | 48 + src/modules/objects/class_combobox.cpp | 368 ++++++ src/modules/objects/class_combobox.h | 71 ++ src/modules/objects/class_dialog.cpp | 89 ++ src/modules/objects/class_dialog.h | 44 + src/modules/objects/class_dockwindow.cpp | 276 +++++ src/modules/objects/class_dockwindow.h | 49 + src/modules/objects/class_file.cpp | 488 ++++++++ src/modules/objects/class_file.h | 113 ++ src/modules/objects/class_groupbox.cpp | 376 ++++++ src/modules/objects/class_groupbox.h | 64 + src/modules/objects/class_hbox.cpp | 128 ++ src/modules/objects/class_hbox.h | 47 + src/modules/objects/class_label.cpp | 409 +++++++ src/modules/objects/class_label.h | 54 + src/modules/objects/class_layout.cpp | 274 +++++ src/modules/objects/class_layout.h | 52 + src/modules/objects/class_lcd.cpp | 180 +++ src/modules/objects/class_lcd.h | 51 + src/modules/objects/class_lineedit.cpp | 461 +++++++ src/modules/objects/class_lineedit.h | 81 ++ src/modules/objects/class_list.cpp | 392 ++++++ src/modules/objects/class_list.h | 64 + src/modules/objects/class_listbox.cpp | 390 ++++++ src/modules/objects/class_listbox.h | 70 ++ src/modules/objects/class_listview.cpp | 557 +++++++++ src/modules/objects/class_listview.h | 102 ++ src/modules/objects/class_listviewitem.cpp | 421 +++++++ src/modules/objects/class_listviewitem.h | 88 ++ src/modules/objects/class_mainwindow.cpp | 158 +++ src/modules/objects/class_mainwindow.h | 47 + src/modules/objects/class_menubar.cpp | 76 ++ src/modules/objects/class_menubar.h | 40 + src/modules/objects/class_multilineedit.cpp | 1217 +++++++++++++++++++ src/modules/objects/class_multilineedit.h | 110 ++ src/modules/objects/class_painter.cpp | 1007 ++++++++++++++++ src/modules/objects/class_painter.h | 96 ++ src/modules/objects/class_pixmap.cpp | 317 +++++ src/modules/objects/class_pixmap.h | 72 ++ src/modules/objects/class_popupmenu.cpp | 361 ++++++ src/modules/objects/class_popupmenu.h | 58 + src/modules/objects/class_process.cpp | 317 +++++ src/modules/objects/class_process.h | 74 ++ src/modules/objects/class_progressbar.cpp | 162 +++ src/modules/objects/class_progressbar.h | 51 + src/modules/objects/class_radiobutton.cpp | 138 +++ src/modules/objects/class_radiobutton.h | 51 + src/modules/objects/class_slider.cpp | 287 +++++ src/modules/objects/class_slider.h | 64 + src/modules/objects/class_socket.cpp | 1331 ++++++++++++++++++++ src/modules/objects/class_socket.h | 185 +++ src/modules/objects/class_spinbox.cpp | 265 ++++ src/modules/objects/class_spinbox.h | 64 + src/modules/objects/class_tabwidget.cpp | 541 +++++++++ src/modules/objects/class_tabwidget.h | 61 + src/modules/objects/class_tbrowser.cpp | 143 +++ src/modules/objects/class_tbrowser.h | 52 + src/modules/objects/class_toolbar.cpp | 156 +++ src/modules/objects/class_toolbar.h | 50 + src/modules/objects/class_toolbutton.cpp | 341 ++++++ src/modules/objects/class_toolbutton.h | 69 ++ src/modules/objects/class_urllabel.cpp | 330 +++++ src/modules/objects/class_urllabel.h | 64 + src/modules/objects/class_vbox.cpp | 128 ++ src/modules/objects/class_vbox.h | 45 + src/modules/objects/class_widget.cpp | 1745 +++++++++++++++++++++++++++ src/modules/objects/class_widget.h | 113 ++ src/modules/objects/class_window.cpp | 158 +++ src/modules/objects/class_window.h | 64 + src/modules/objects/class_wizard.cpp | 371 ++++++ src/modules/objects/class_wizard.h | 79 ++ src/modules/objects/class_workspace.cpp | 262 ++++ src/modules/objects/class_workspace.h | 53 + src/modules/objects/class_wrapper.cpp | 269 +++++ src/modules/objects/class_wrapper.h | 53 + src/modules/objects/class_xmlreader.cpp | 343 ++++++ src/modules/objects/class_xmlreader.h | 46 + src/modules/objects/libkviobjects.cpp | 1066 ++++++++++++++++ src/modules/objects/object_macros.h | 90 ++ 85 files changed, 19685 insertions(+) create mode 100644 src/modules/objects/Makefile.am create mode 100644 src/modules/objects/class_button.cpp create mode 100644 src/modules/objects/class_button.h create mode 100644 src/modules/objects/class_buttongroup.cpp create mode 100644 src/modules/objects/class_buttongroup.h create mode 100644 src/modules/objects/class_checkbox.cpp create mode 100644 src/modules/objects/class_checkbox.h create mode 100644 src/modules/objects/class_combobox.cpp create mode 100644 src/modules/objects/class_combobox.h create mode 100644 src/modules/objects/class_dialog.cpp create mode 100644 src/modules/objects/class_dialog.h create mode 100644 src/modules/objects/class_dockwindow.cpp create mode 100644 src/modules/objects/class_dockwindow.h create mode 100644 src/modules/objects/class_file.cpp create mode 100644 src/modules/objects/class_file.h create mode 100644 src/modules/objects/class_groupbox.cpp create mode 100644 src/modules/objects/class_groupbox.h create mode 100644 src/modules/objects/class_hbox.cpp create mode 100644 src/modules/objects/class_hbox.h create mode 100644 src/modules/objects/class_label.cpp create mode 100644 src/modules/objects/class_label.h create mode 100644 src/modules/objects/class_layout.cpp create mode 100644 src/modules/objects/class_layout.h create mode 100644 src/modules/objects/class_lcd.cpp create mode 100644 src/modules/objects/class_lcd.h create mode 100644 src/modules/objects/class_lineedit.cpp create mode 100644 src/modules/objects/class_lineedit.h create mode 100644 src/modules/objects/class_list.cpp create mode 100644 src/modules/objects/class_list.h create mode 100644 src/modules/objects/class_listbox.cpp create mode 100644 src/modules/objects/class_listbox.h create mode 100644 src/modules/objects/class_listview.cpp create mode 100644 src/modules/objects/class_listview.h create mode 100644 src/modules/objects/class_listviewitem.cpp create mode 100644 src/modules/objects/class_listviewitem.h create mode 100644 src/modules/objects/class_mainwindow.cpp create mode 100644 src/modules/objects/class_mainwindow.h create mode 100644 src/modules/objects/class_menubar.cpp create mode 100644 src/modules/objects/class_menubar.h create mode 100644 src/modules/objects/class_multilineedit.cpp create mode 100644 src/modules/objects/class_multilineedit.h create mode 100644 src/modules/objects/class_painter.cpp create mode 100644 src/modules/objects/class_painter.h create mode 100644 src/modules/objects/class_pixmap.cpp create mode 100644 src/modules/objects/class_pixmap.h create mode 100644 src/modules/objects/class_popupmenu.cpp create mode 100644 src/modules/objects/class_popupmenu.h create mode 100644 src/modules/objects/class_process.cpp create mode 100644 src/modules/objects/class_process.h create mode 100644 src/modules/objects/class_progressbar.cpp create mode 100644 src/modules/objects/class_progressbar.h create mode 100644 src/modules/objects/class_radiobutton.cpp create mode 100644 src/modules/objects/class_radiobutton.h create mode 100644 src/modules/objects/class_slider.cpp create mode 100644 src/modules/objects/class_slider.h create mode 100644 src/modules/objects/class_socket.cpp create mode 100644 src/modules/objects/class_socket.h create mode 100644 src/modules/objects/class_spinbox.cpp create mode 100644 src/modules/objects/class_spinbox.h create mode 100644 src/modules/objects/class_tabwidget.cpp create mode 100644 src/modules/objects/class_tabwidget.h create mode 100644 src/modules/objects/class_tbrowser.cpp create mode 100644 src/modules/objects/class_tbrowser.h create mode 100644 src/modules/objects/class_toolbar.cpp create mode 100644 src/modules/objects/class_toolbar.h create mode 100644 src/modules/objects/class_toolbutton.cpp create mode 100644 src/modules/objects/class_toolbutton.h create mode 100644 src/modules/objects/class_urllabel.cpp create mode 100644 src/modules/objects/class_urllabel.h create mode 100644 src/modules/objects/class_vbox.cpp create mode 100644 src/modules/objects/class_vbox.h create mode 100644 src/modules/objects/class_widget.cpp create mode 100644 src/modules/objects/class_widget.h create mode 100644 src/modules/objects/class_window.cpp create mode 100644 src/modules/objects/class_window.h create mode 100644 src/modules/objects/class_wizard.cpp create mode 100644 src/modules/objects/class_wizard.h create mode 100644 src/modules/objects/class_workspace.cpp create mode 100644 src/modules/objects/class_workspace.h create mode 100644 src/modules/objects/class_wrapper.cpp create mode 100644 src/modules/objects/class_wrapper.h create mode 100644 src/modules/objects/class_xmlreader.cpp create mode 100644 src/modules/objects/class_xmlreader.h create mode 100644 src/modules/objects/libkviobjects.cpp create mode 100644 src/modules/objects/object_macros.h (limited to 'src/modules/objects') diff --git a/src/modules/objects/Makefile.am b/src/modules/objects/Makefile.am new file mode 100644 index 00000000..c4574582 --- /dev/null +++ b/src/modules/objects/Makefile.am @@ -0,0 +1,143 @@ +############################################################################### +# KVirc IRC client Makefile - 10.03.2000 Szymon Stefanek +############################################################################### + +AM_CPPFLAGS = -I$(SS_TOPSRCDIR)/src/kvilib/include/ -I$(SS_TOPSRCDIR)/src/kvirc/include/ \ +$(SS_INCDIRS) $(SS_CPPFLAGS) -DGLOBAL_KVIRC_DIR=\"$(globalkvircdir)\" + +pluglib_LTLIBRARIES = libkviobjects.la + +libkviobjects_la_LDFLAGS = -module -avoid-version $(SS_LDFLAGS) $(SS_LIBDIRS) + +libkviobjects_la_SOURCES = libkviobjects.cpp \ + class_button.cpp \ + class_buttongroup.cpp \ + class_checkbox.cpp \ + class_combobox.cpp \ + class_dialog.cpp \ + class_dockwindow.cpp \ + class_file.cpp \ + class_groupbox.cpp \ + class_label.cpp \ + class_layout.cpp \ + class_lcd.cpp \ + class_lineedit.cpp \ + class_list.cpp \ + class_listbox.cpp \ + class_listview.cpp \ + class_listviewitem.cpp \ + class_mainwindow.cpp \ + class_menubar.cpp \ + class_multilineedit.cpp \ + class_popupmenu.cpp \ + class_process.cpp \ + class_progressbar.cpp \ + class_radiobutton.cpp \ + class_slider.cpp \ + class_socket.cpp \ + class_spinbox.cpp \ + class_tabwidget.cpp \ + class_toolbar.cpp \ + class_toolbutton.cpp \ + class_painter.cpp \ + class_pixmap.cpp \ + class_tbrowser.cpp \ + class_widget.cpp \ + class_window.cpp \ + class_wizard.cpp \ + class_workspace.cpp \ + class_wrapper.cpp \ + class_urllabel.cpp \ + class_xmlreader.cpp \ + class_vbox.cpp \ + class_hbox.cpp + + +libkviobjects_la_LIBADD = $(SS_LIBLINK) ../../kvilib/build/libkvilib.la + +noinst_HEADERS= class_button.h \ + class_buttongroup.h \ + class_checkbox.h \ + class_combobox.h \ + class_dialog.h \ + class_dockwindow.h \ + class_file.h \ + class_groupbox.h \ + class_label.h \ + class_layout.h \ + class_lcd.h \ + class_lineedit.h \ + class_list.h \ + class_listbox.h \ + class_listview.h \ + class_listviewitem.h \ + class_mainwindow.h \ + class_menubar.h \ + class_multilineedit.h \ + class_painter.h \ + class_pixmap.h \ + class_popupmenu.h \ + class_process.h \ + class_progressbar.h \ + class_radiobutton.h \ + class_slider.h \ + class_socket.h \ + class_spinbox.h \ + class_tabwidget.h \ + class_tbrowser.h \ + class_toolbar.h \ + class_toolbutton.h \ + class_urllabel.h \ + class_widget.h \ + class_window.h \ + class_wizard.h \ + class_workspace.h \ + class_wrapper.h \ + class_xmlreader.h \ + class_vbox.h \ + class_hbox.h \ + object_macros.h + +m_%.moc: %.h + $(SS_QT_MOC) $< -o $@ + +class_checkbox.cpp: m_class_checkbox.moc +class_combobox.cpp: m_class_combobox.moc +class_button.cpp: m_class_button.moc +class_dialog.cpp: m_class_dialog.moc +class_dockwindow.cpp: m_class_dockwindow.moc +class_file.cpp: m_class_file.moc +class_groupbox.cpp: m_class_groupbox.moc +class_label.cpp: m_class_label.moc +class_layout.cpp: m_class_layout.moc +class_lcd.cpp: m_class_lcd.moc +class_lineedit.cpp: m_class_lineedit.moc +class_list.cpp: m_class_list.moc +class_listbox.cpp: m_class_listbox.moc +class_listview.cpp: m_class_listview.moc +class_listviewitem.cpp: m_class_listviewitem.moc +class_listbox.cpp: m_class_listbox.moc +class_mainwindow.cpp: m_class_mainwindow.moc +class_menubar.cpp: m_class_menubar.moc +class_multilineedit.cpp: m_class_multilineedit.moc +class_painter.cpp: m_class_painter.moc +class_pixmap.cpp: m_class_pixmap.moc +class_popupmenu.cpp: m_class_popupmenu.moc +class_process.cpp: m_class_process.moc +class_progressbar.cpp: m_class_progressbar.moc +class_radiobutton.cpp: m_class_radiobutton.moc +class_slider.cpp: m_class_slider.moc +class_socket.cpp: m_class_socket.moc +class_spinbox.cpp: m_class_spinbox.moc +class_tabwidget.cpp: m_class_tabwidget.moc +class_tbrowser.cpp: m_class_tbrowser.moc +class_toolbar.cpp: m_class_toolbar.moc +class_toolbutton.cpp: m_class_toolbutton.moc +class_urllabel.cpp: m_class_urllabel.moc +class_widget.cpp: m_class_widget.moc +class_window.cpp: m_class_window.moc +class_wizard.cpp: m_class_wizard.moc +class_workspace.cpp: m_class_workspace.moc +class_wrapper.cpp: m_class_wrapper.moc +class_xmlreader.cpp: m_class_xmlreader.moc + diff --git a/src/modules/objects/class_button.cpp b/src/modules/objects/class_button.cpp new file mode 100644 index 00000000..54d1525a --- /dev/null +++ b/src/modules/objects/class_button.cpp @@ -0,0 +1,178 @@ +// +// File : class_button.cpp +// Creation date : Wed 13 Sep 2000 02:42:05 CEST by Krzysztof Godlewski +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 "kvi_debug.h" + + +#include "kvi_error.h" +#include +#include "kvi_iconmanager.h" + +#include "class_button.h" + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_button,"button","widget") + + KVSO_REGISTER_HANDLER(KviKvsObject_button,"setText", functionSetText) + KVSO_REGISTER_HANDLER(KviKvsObject_button,"text", functionText) + KVSO_REGISTER_HANDLER(KviKvsObject_button,"setAutoDefault", functionSetAutoDefault) + KVSO_REGISTER_HANDLER(KviKvsObject_button,"setToggleButton", functionSetToggleButton) + KVSO_REGISTER_HANDLER(KviKvsObject_button,"setOn", functionSetOn) + KVSO_REGISTER_HANDLER(KviKvsObject_button,"isOn", functionIsOn) + KVSO_REGISTER_HANDLER(KviKvsObject_button,"toggle", functionToggle) + KVSO_REGISTER_HANDLER(KviKvsObject_button,"setIsMenuButton", functionSetIsMenuButton) + KVSO_REGISTER_HANDLER(KviKvsObject_button,"isMenuButton", functionIsMenuButton) + KVSO_REGISTER_HANDLER(KviKvsObject_button,"clickEvent", functionclickEvent) + KVSO_REGISTER_HANDLER(KviKvsObject_button,"setImage", functionSetImage) + + +KVSO_END_REGISTERCLASS(KviKvsObject_button) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_button,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_button) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_button) + +KVSO_END_CONSTRUCTOR(KviKvsObject_button) + +bool KviKvsObject_button::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + setObject(new QPushButton(parentScriptWidget(),name()),true); + connect(widget(),SIGNAL(clicked()),this,SLOT(slotClicked())); + return true; +} + +bool KviKvsObject_button::functionText(KviKvsObjectFunctionCall *c) +{ + if(widget()) c->returnValue()->setString(((QPushButton *)widget())->text()); + return true; +} + +bool KviKvsObject_button::functionSetText(KviKvsObjectFunctionCall *c) +{ + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QPushButton *)widget())->setText(szText); + return true; +} +bool KviKvsObject_button::functionSetAutoDefault(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QPushButton *)widget())->setAutoDefault(bEnabled); + return true; +} +bool KviKvsObject_button::functionSetToggleButton(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QPushButton *)widget())->setToggleButton(bEnabled); + return true; +} +bool KviKvsObject_button::functionSetOn(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QPushButton *)widget())->setOn(bEnabled); + return true; +} +// FIX ME +bool KviKvsObject_button::functionSetIsMenuButton(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + /*if(widget()) + ((QPushButton *)widget())->setIsMenuButton(bEnabled); + */ + + return true; +} +bool KviKvsObject_button::functionIsMenuButton(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setBoolean(((QPushButton *)widget())->isMenuButton()); + return true; +} +// +bool KviKvsObject_button::functionIsOn(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setBoolean(((QPushButton *)widget())->isOn()); + return true; +} +bool KviKvsObject_button::functionToggle(KviKvsObjectFunctionCall *c) +{ + if(widget()) ((QPushButton *)widget())->toggle(); + return true; +} +// FIX ME +bool KviKvsObject_button::functionSetImage(KviKvsObjectFunctionCall *c) +{ + QString icon; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("icon",KVS_PT_STRING,0,icon) + KVSO_PARAMETERS_END(c) + if (!widget()) return true; + QPixmap * pix = g_pIconManager->getImage(icon); + if(pix){ + #ifdef COMPILE_USE_QT4 + ((QPushButton *)widget())->setIconSet(*pix); + #else + ((QPushButton *)widget())->setIconSet(QIconSet(*pix,QIconSet::Small)); + #endif + } + else{ + #ifdef COMPILE_USE_QT4 + ((QPushButton *)widget())->setIcon(QIconSet()); + #else + ((QPushButton *)widget())->setIconSet(QIconSet()); + #endif + } + return true; +} +bool KviKvsObject_button::functionclickEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("clicked",c); + return true; +} + +void KviKvsObject_button::slotClicked() +{ + KviKvsVariantList *params=0; + callFunction(this,"clickEvent",params); +} + + +#include "m_class_button.moc" diff --git a/src/modules/objects/class_button.h b/src/modules/objects/class_button.h new file mode 100644 index 00000000..5c752e48 --- /dev/null +++ b/src/modules/objects/class_button.h @@ -0,0 +1,58 @@ +#ifndef _CLASS_BUTTON_H_ +#define _CLASS_BUTTON_H_ +// +// File : class_button.h +// Creation date : Wed 13 Sep 2000 02:42:05 CEST by Krzysztof Godlewski +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 +#include "class_widget.h" +#include "object_macros.h" + +class KviKvsObject_button : public KviKvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_button) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool functionSetText(KviKvsObjectFunctionCall *c); + bool functionIsChecked(KviKvsObjectFunctionCall *c); + bool functionText(KviKvsObjectFunctionCall *c); + bool functionSetAutoDefault(KviKvsObjectFunctionCall *c); + bool functionSetToggleButton(KviKvsObjectFunctionCall *c); + bool functionSetOn(KviKvsObjectFunctionCall *c); + bool functionIsOn(KviKvsObjectFunctionCall *c); + bool functionToggle(KviKvsObjectFunctionCall *c); + bool functionSetIsMenuButton(KviKvsObjectFunctionCall *c); + bool functionIsMenuButton(KviKvsObjectFunctionCall *c); + bool functionSetImage(KviKvsObjectFunctionCall *c); + bool functionclickEvent(KviKvsObjectFunctionCall *c); + +protected slots: + void slotClicked(); +}; + +#endif // !_CLASS_BUTTON_H_ diff --git a/src/modules/objects/class_buttongroup.cpp b/src/modules/objects/class_buttongroup.cpp new file mode 100644 index 00000000..5f9f1756 --- /dev/null +++ b/src/modules/objects/class_buttongroup.cpp @@ -0,0 +1,87 @@ +// +// File : class_buttongroup.cpp +// Creation date : Fri Jan 28 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 +#include "class_buttongroup.h" +#include +#include "kvi_error.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_iconmanager.h" + + +/* + @doc: buttongroup + @keyterms: + buttongroup object class, + @title: + buttongroup class + @type: + class + @short: + Provides a buttongroup bar. + @inherits: + [class]groupbox[/class] + [class]object[/class] + [class]widget[/class] + @description: + This widget organizes buttons in a group. + It will be usually a parent for other child controls. + You can either use a child layout to manage the children geometries + or use $setColumnLayout function to manage the layout automatically. + The class ineriths groupbox. + + @functions: + +*/ + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_buttongroup,"buttongroup","groupbox") + +KVSO_END_REGISTERCLASS(KviKvsObject_buttongroup) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_buttongroup,KviKvsObject_groupbox) + +KVSO_END_CONSTRUCTOR(KviKvsObject_buttongroup) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_buttongroup) + +KVSO_END_CONSTRUCTOR(KviKvsObject_buttongroup) + +// CHECK ME +bool KviKvsObject_buttongroup::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + #ifdef COMPILE_USE_QT4 + QButtonGroup *group=new QButtonGroup(parentScriptWidget()); + group->setObjectName(name()); + setObject(group,true); + #else + setObject(new QButtonGroup(name(),parentScriptWidget()), true); + #endif + + + return true; +} + + diff --git a/src/modules/objects/class_buttongroup.h b/src/modules/objects/class_buttongroup.h new file mode 100644 index 00000000..472051ec --- /dev/null +++ b/src/modules/objects/class_buttongroup.h @@ -0,0 +1,44 @@ +#ifndef _CLASS_BUTTONGROUP_H_ +#define _CLASS_BUTTONGROUP_H_ +// +// File : class_buttongroup.h +// Creation date : Jan 23 CEST 2007 +// by Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 +#include "class_groupbox.h" +#include "object_macros.h" + +class KviKvsObject_buttongroup : public KviKvsObject_groupbox +{ +public: + KVSO_DECLARE_OBJECT(KviKvsObject_buttongroup) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + +}; +#endif //!_CLASS_GROUPBOX_H_ + diff --git a/src/modules/objects/class_checkbox.cpp b/src/modules/objects/class_checkbox.cpp new file mode 100644 index 00000000..a651adb8 --- /dev/null +++ b/src/modules/objects/class_checkbox.cpp @@ -0,0 +1,128 @@ +//vim: ts=8 +// File : class_checkbox.cpp +// Creation date : Wed Sep 20 23:01:47 CEST 2000 by Krzysztof Godlewski +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 "kvi_error.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_styled_controls.h" + +#include "class_checkbox.h" + +/* + @doc: checkbox + @title: + checkbox class + @type: + class + @short: + Check box with a text description + @inherits: + [class]object[/class] + [class]button[/class] + @description: + This widget provides a check box - it is a kind of a toggle + button. It can have two states: on (checked) and off + (unchecked). + @functions: + !fn: $isChecked() + Returns '1' if the check box is checked, '0' otherwise.[br] + See also [classfnc]$setChecked[/classfnc](). + !fn: $setChecked([]) + Sets the check box 'checked state' to . + !fn: $setText([]) + Sets the check box 'checked state' to .[br] + See also [classfnc]$isChecked[/classfnc](). + !fn: $toggleEvent() + Called by KVIrc when the checkbox state is toggled. + The default implementation emits the toggled() signal. +*/ + +//--------------------------------------------------------------------------------- + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_checkbox,"checkbox","button") + // appearance + KVSO_REGISTER_HANDLER(KviKvsObject_checkbox,"setChecked",function_setChecked) + KVSO_REGISTER_HANDLER(KviKvsObject_checkbox,"isChecked",function_isChecked) + KVSO_REGISTER_HANDLER(KviKvsObject_checkbox,"toggleEvent",function_toggleEvent) + KVSO_REGISTER_HANDLER(KviKvsObject_checkbox,"setText",function_setText) +KVSO_END_REGISTERCLASS(KviKvsObject_checkbox) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_checkbox,KviKvsObject_button) + +KVSO_END_CONSTRUCTOR(KviKvsObject_checkbox) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_checkbox) + +KVSO_END_CONSTRUCTOR(KviKvsObject_checkbox) + +bool KviKvsObject_checkbox::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + KviStyledCheckBox * cb = new KviStyledCheckBox(parentScriptWidget(), name()); + setObject(cb, true); + connect(cb,SIGNAL(toggled(bool)),this,SLOT(toggled(bool))); + connect(widget(),SIGNAL(clicked()),this,SLOT(slotClicked())); + return true; +} + +bool KviKvsObject_checkbox::function_isChecked(KviKvsObjectFunctionCall *c) +{ + if(widget()) c->returnValue()->setBoolean(((KviStyledCheckBox *)widget())->isChecked()); + return true; +} + +bool KviKvsObject_checkbox::function_setChecked(KviKvsObjectFunctionCall *c) +{ + bool bChecked; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bChecked",KVS_PT_BOOL,KVS_PF_OPTIONAL,bChecked) + KVSO_PARAMETERS_END(c) + if(widget()) ((KviStyledCheckBox *)widget())->setChecked(bChecked); + return true; +} + +bool KviKvsObject_checkbox::function_setText(KviKvsObjectFunctionCall *c) +{ + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if(widget()) ((KviStyledCheckBox *)widget())->setText(szText); + return true; +} + +bool KviKvsObject_checkbox::function_toggleEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("toggled",c,c->params()); + return true; +} + +void KviKvsObject_checkbox::toggled(bool b) +{ + KviKvsVariantList params(new KviKvsVariant(b)); + callFunction(this,"toggleEvent",¶ms); +} + + +#include "m_class_checkbox.moc" diff --git a/src/modules/objects/class_checkbox.h b/src/modules/objects/class_checkbox.h new file mode 100644 index 00000000..1d19a432 --- /dev/null +++ b/src/modules/objects/class_checkbox.h @@ -0,0 +1,48 @@ +#ifndef _CLASS_CHECKBOX_H_ +#define _CLASS_CHECKBOX_H_ + +//vim: ts=8 +// File : class_checkbox.h +// Creation date : Wed Sep 20 23:02:11 CEST 2000 by Krzysztof Godlewski +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 +#include "class_button.h" +#include "object_macros.h" + +class KviKvsObject_checkbox : public KviKvsObject_button +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_checkbox) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + bool function_setChecked(KviKvsObjectFunctionCall *c); + bool function_isChecked(KviKvsObjectFunctionCall *c); + bool function_toggleEvent(KviKvsObjectFunctionCall *c); + bool function_setText(KviKvsObjectFunctionCall *c); +protected slots: + void toggled(bool b); +}; +#endif // !_CLASS_CHECKBOX_H_ diff --git a/src/modules/objects/class_combobox.cpp b/src/modules/objects/class_combobox.cpp new file mode 100644 index 00000000..9c8ffadf --- /dev/null +++ b/src/modules/objects/class_combobox.cpp @@ -0,0 +1,368 @@ +//vim: ts=8 +// File : class_combobox.cpp +// Creation date : Thu Mar 22 20:57:45 CET 2001 by Krzysztof Godlewski +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 "kvi_error.h" +#include "kvi_locale.h" +#include "kvi_debug.h" + + +#include "class_list.h" +#include "class_combobox.h" +#include +#include + +/* + @doc: combobox + @keyterms: + combobox object class, selection + @title: + combobox class + @type: + class + @short: + Combined button and popup list + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + @functions: + !fn: $insertItem(, ) + Inserts a text item at position . If index is negative or + not specified the item is appended. + !fn: $changeItem(, ) + Changes text of item at to . + !fn: $removeItem() + Removes item at given index. + !fn: $setMaxCount() + Sets the maximum number of items the combo box can hold to + . If is smaller than the current number of items, + the list is truncated at the end. There is no limit by default. + !fn: $maxCount() + Returns the current maximum number of items in the combo box. + !fn: $count() + Returns number of items in the widget. + !fn: $current() + Returns currently selected item. + !fn: $currentItem() + Returns index of currently selected item. + !fn: $setEditable() + Make the input field editable, if . Otherwise the + user may only choose one of the items in the combo box.[br] + If the parameter is ommited, it is assumed to be false. + !fn: $editable() + Returns whether the combobox is editable or not. + !fn: $setEditText(,[]) + Sets the text in the embedded line edit to newText without + changing the combo's contents. Does nothing if the combo + isn't editable. If the optional quiet parameter is true no warning will be print if text will be empty. + !fn: $clear() + Removes all the items from the combo box + !fn: $textAt() + Returns item at given index. + !fn: $setCurrentItem() + Sets the current combobox item. This is the item to be + displayed on the combobox button. + !fn: $activatedEvent() + This function is called by the framework when a new item has activated. The index value is the position of the new item.[br] + The default implementation emits the [classfnc]$activated[/classfnc]() signal, + !fn: $textChangedEvent() + This function is called when the text in an editable combobox has changed.[br] + The function return the new text in its argument.[br] + The default implementation emits the [classfnc]$textChanged[/classfnc]() signal. + @signals: + !sg: $textChanged() + This signal is emitted by the default implementation of [classfnc]$textChangedEvent[/classfnc](). + !sg: $activated() + This signal is emitted by the default implementation of [classfnc]$activatedEvent[/classfnc](). + +*/ +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_combobox,"combobox","widget") + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"insertItem", functioninsertItem) + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"changeItem", functionchangeItem) + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"removeItem", functionremoveItem) + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"clear", functionclear) + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"setMaxCount", functionsetMaxCount) + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"maxCount", functionmaxCount) + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"count", functioncount) + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"current", functioncurrent) + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"currentItem", functioncurrentItem) + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"setEditable", functionsetEditable); + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"editable", functioneditable) + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"setEditText", functionsetEditText) + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"textAt", functiontextAt) + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"textLineEdit", functiontextLineEdit) + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"setTextLineEdit", functionsetTextLineEdit) + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"setCurrentItem", functionsetCurrentItem) + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"popup", functionpopup) + + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"setInsertionPolicy", functionsetInsertionPolicy) + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"textChangedEvent", functiontextChangedEvent) + KVSO_REGISTER_HANDLER(KviKvsObject_combobox,"activatedEvent", functionactivatedEvent) + +KVSO_END_REGISTERCLASS(KviKvsObject_combobox) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_combobox,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_combobox) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_combobox) + +KVSO_END_CONSTRUCTOR(KviKvsObject_combobox) + +bool KviKvsObject_combobox::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + setObject(new QComboBox(parentScriptWidget(), name()), true); + connect (((QComboBox *)widget()),SIGNAL(activated( int )),this,SLOT(slotActivated( int ))); + return true; +} + +bool KviKvsObject_combobox::functioninsertItem(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iIndex; + QString szItem; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("item",KVS_PT_STRING,0,szItem) + KVSO_PARAMETER("index",KVS_PT_INT,KVS_PF_OPTIONAL,iIndex) + KVSO_PARAMETERS_END(c) + if(widget()) + if(c->paramCount()==1) + ((QComboBox *)widget())->insertItem(szItem); + else + ((QComboBox *)widget())->insertItem(szItem, iIndex); + return true; +} +bool KviKvsObject_combobox::functionclear(KviKvsObjectFunctionCall *c) +{ + if (widget()) ((QComboBox *)widget())->clear(); + return true; +} +bool KviKvsObject_combobox::functionchangeItem(KviKvsObjectFunctionCall *c) +{ + + kvs_uint_t uIndex,cnt; + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + if(!widget()) return true; + if (szText.isEmpty()) c->warning(__tr2qs("No string parameter given - using empty string")); + if(uIndex >= (cnt = ((QComboBox *)widget())->count())) + { + c->warning(__tr2qs("Item index [%d] is too big - defaulting to " \ + "$count() - 1 [%d]"), uIndex, cnt); + uIndex = cnt - 1; + } + + ((QComboBox *)widget())->changeItem(szText, uIndex); + + return true; + +} +bool KviKvsObject_combobox::functionremoveItem(KviKvsObjectFunctionCall *c) +{ + + kvs_uint_t uIndex,cnt; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + if(!widget()) return true; + if(uIndex >= (cnt = ((QComboBox *)widget())->count())) + { + c->warning(__tr2qs("Item index [%d] is too big - defaulting to " \ + "$count() - 1 [%d]"), uIndex, cnt); + uIndex = cnt - 1; + } + + ((QComboBox *)widget())->removeItem(uIndex); + + return true; + +} +bool KviKvsObject_combobox::functionsetMaxCount(KviKvsObjectFunctionCall *c) +{ + + kvs_uint_t iMax; + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("count",KVS_PT_UNSIGNEDINTEGER,0,iMax) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QComboBox *)widget())->setMaxCount(iMax); + return true; +} +bool KviKvsObject_combobox::functionmaxCount(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setInteger(((QComboBox *)widget())->maxCount()); + return true; +} +bool KviKvsObject_combobox::functioncount(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setInteger(((QComboBox *)widget())->count()); + return true; +} +bool KviKvsObject_combobox::functioncurrent(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setString(((QComboBox *)widget())->currentText().local8Bit().data()); + return true; +} +bool KviKvsObject_combobox::functioncurrentItem(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setInteger(((QComboBox *)widget())->currentItem()); + return true; +} +bool KviKvsObject_combobox::functiontextLineEdit(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setString(((QComboBox *)widget())->lineEdit()->text()); + return true; +} + +bool KviKvsObject_combobox::functionsetEditable(KviKvsObjectFunctionCall *c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bflag",KVS_PT_BOOLEAN,0,bFlag) + KVSO_PARAMETERS_END(c) + if(widget()) + { + ((QComboBox *)widget())->setEditable(bFlag); + if (bFlag) connect (((QComboBox *)widget())->lineEdit(),SIGNAL(textChanged(const QString & )),this,SLOT(slottextChanged(const QString & ))); + else + disconnect (((QComboBox *)widget())->lineEdit(),SIGNAL(textChanged(const QString & )),this,SLOT(slottextChanged(const QString & ))); + } + + return true; +} +bool KviKvsObject_combobox::functionsetTextLineEdit(KviKvsObjectFunctionCall *c) +{ + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QComboBox *)widget())->lineEdit()->setText(szText); + return true; +} + +bool KviKvsObject_combobox::functioneditable(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setBoolean(((QComboBox *)widget())->editable()); + return true; +} +bool KviKvsObject_combobox::functionsetEditText(KviKvsObjectFunctionCall *c) +{ + QString szText; + bool bQuiet=false; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETER("quiet",KVS_PT_BOOLEAN,KVS_PF_OPTIONAL,bQuiet) + KVSO_PARAMETERS_END(c) + if(!widget()) return true; + if (szText.isEmpty() && !bQuiet) c->warning("No string parameter given - using empty string"); + ((QComboBox *)widget())->setEditText(szText); + return true; +} +bool KviKvsObject_combobox::functiontextAt(KviKvsObjectFunctionCall *c) +{ + + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + if(widget()) + c->returnValue()->setString(((QComboBox *)widget())->text(uIndex)); + return true; +} +bool KviKvsObject_combobox::functionsetCurrentItem(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QComboBox *)widget())->setCurrentItem(uIndex); + return true; +} +bool KviKvsObject_combobox::functionpopup(KviKvsObjectFunctionCall *c) +{ + if(widget()) + ((QComboBox *)widget())->popup(); + return true; +} +bool KviKvsObject_combobox::functionsetInsertionPolicy(KviKvsObjectFunctionCall *c) +{ + QString szPolicy; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("policy",KVS_PT_STRING,0,szPolicy) + KVSO_PARAMETERS_END(c) + if(!widget()) return true; + if(KviQString::equalCI(szPolicy,"NoInsertion")) + ((QComboBox *)widget())->setInsertionPolicy(QComboBox::NoInsertion); + else if(KviQString::equalCI(szPolicy,"AtTop")) + ((QComboBox *)widget())->setInsertionPolicy(QComboBox::AtTop); + else if(KviQString::equalCI(szPolicy,"AtBotton")) + ((QComboBox *)widget())->setInsertionPolicy(QComboBox::AtBottom); + else if(KviQString::equalCI(szPolicy,"AtCurrent")) + ((QComboBox *)widget())->setInsertionPolicy(QComboBox::AtCurrent); + else if(KviQString::equalCI(szPolicy,"AfterCurrent")) + ((QComboBox *)widget())->setInsertionPolicy(QComboBox::AfterCurrent); + else if(KviQString::equalCI(szPolicy,"BeforeCurrent")) + ((QComboBox *)widget())->setInsertionPolicy(QComboBox::BeforeCurrent); + else c->warning(__tr2qs("Invalid insertion Policy %Q"),&szPolicy); + return true; +} + + + +bool KviKvsObject_combobox::functiontextChangedEvent(KviKvsObjectFunctionCall *c) +{ + + emitSignal("textChanged",c,c->params()); + return true; + +} + +void KviKvsObject_combobox::slottextChanged(const QString &text) +{ + KviKvsVariantList params(new KviKvsVariant(text)); + callFunction(this,"textChangedEvent",¶ms); +} + +bool KviKvsObject_combobox::functionactivatedEvent(KviKvsObjectFunctionCall *c) +{ + + emitSignal("activated",c,c->params()); + return true; + +} + +void KviKvsObject_combobox::slotActivated(int i) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)i)); + callFunction(this,"activatedEvent",¶ms); +} + + +#include "m_class_combobox.moc" diff --git a/src/modules/objects/class_combobox.h b/src/modules/objects/class_combobox.h new file mode 100644 index 00000000..d4da7c6b --- /dev/null +++ b/src/modules/objects/class_combobox.h @@ -0,0 +1,71 @@ +#ifndef _CLASS_COMBOBOX_H_ +#define _CLASS_COMBOBOX_H_ + +//vim: ts=8 +// File : class_combobox.h +// Creation date : Thu Mar 22 20:57:28 CET 2001 by Krzysztof Godlewski +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 +#include "class_widget.h" +#include "object_macros.h" + +class KviKvsObject_combobox : public KviKvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_combobox) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool functioninsertItem(KviKvsObjectFunctionCall *c); + bool functionchangeItem(KviKvsObjectFunctionCall *c); + bool functionremoveItem(KviKvsObjectFunctionCall *c); + bool functionclear(KviKvsObjectFunctionCall *c); +//#warning "$insertPixItem" +//#warning "$changePixItem" + + bool functioncount(KviKvsObjectFunctionCall *c); + bool functionsetMaxCount(KviKvsObjectFunctionCall *c); + bool functionmaxCount(KviKvsObjectFunctionCall *c); + bool functioncurrent(KviKvsObjectFunctionCall *c); + bool functioncurrentItem(KviKvsObjectFunctionCall *c); + bool functionsetEditable(KviKvsObjectFunctionCall *c); + bool functioneditable(KviKvsObjectFunctionCall *c); + bool functionsetEditText(KviKvsObjectFunctionCall *c); + bool functiontextAt(KviKvsObjectFunctionCall *c); + bool functiontextLineEdit(KviKvsObjectFunctionCall *c); + bool functionsetTextLineEdit(KviKvsObjectFunctionCall *c); + + bool functionsetInsertionPolicy(KviKvsObjectFunctionCall *c); + + bool functionsetCurrentItem(KviKvsObjectFunctionCall *c); + bool functionpopup(KviKvsObjectFunctionCall *c); + bool functiontextChangedEvent(KviKvsObjectFunctionCall *c); + bool functionactivatedEvent(KviKvsObjectFunctionCall *c); +protected slots: + void slottextChanged(const QString &); + void slotActivated(int); +}; + +#endif // !_CLASS_COMBOBOX_H_ diff --git a/src/modules/objects/class_dialog.cpp b/src/modules/objects/class_dialog.cpp new file mode 100644 index 00000000..f062f004 --- /dev/null +++ b/src/modules/objects/class_dialog.cpp @@ -0,0 +1,89 @@ +// +// File : class_dialog.cpp +// Creation date : Sun Apr 10 22:51:48 CEST 2002 by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2005 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 "class_dialog.h" + +#include "kvi_error.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_frame.h" +#include "kvi_app.h" + +#include + + +/* + @doc: dialog + @title: + dialog class + @type: + class + @short: + A toplevel dialog object + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + Rappresents a dialog object. The class is really + similar to the widget class, it has only a couple of minor differences. + A dialog is always a top-level widget, but if it has a parent, its default + location is centered on top of the parent. It will also share the parent's taskbar entry. + If you call $setModal(1) then the dialog will have non-blocking modal behaviour: + it will appear above its parent widget and block its input until it's closed. + @functions: +*/ + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_dialog,"dialog","widget") + KVSO_REGISTER_HANDLER(KviKvsObject_dialog,"setModal",functionSetModal) +KVSO_END_REGISTERCLASS(KviKvsObject_dialog) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_dialog,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_dialog) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_dialog) + +KVSO_END_CONSTRUCTOR(KviKvsObject_dialog) + +bool KviKvsObject_dialog::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + QWidget * w = g_pApp->activeModalWidget(); + if(!w)w = g_pFrame; + QDialog * d = new QDialog(parentScriptWidget() ? parentScriptWidget() : w,name()); + //d->setModal(true); + setObject(d); + return true; +} +bool KviKvsObject_dialog::functionSetModal(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QDialog *)widget())->setModal(bEnabled); + return true; +} + + diff --git a/src/modules/objects/class_dialog.h b/src/modules/objects/class_dialog.h new file mode 100644 index 00000000..b284baf3 --- /dev/null +++ b/src/modules/objects/class_dialog.h @@ -0,0 +1,44 @@ +#ifndef _CLASS_DIALOG_H_ +#define _CLASS_DIALOG_H_ +// +// File : class_dialog.h +// Creation date : Sun Apr 10 22:51:48 CEST 2002 by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2005 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 "class_widget.h" + +class QDialog; + +#include "object_macros.h" + +class KviKvsObject_dialog : public KviKvsObject_widget +{ + +public: + KVSO_DECLARE_OBJECT(KviKvsObject_dialog) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + bool functionSetModal(KviKvsObjectFunctionCall *c); +}; + +#endif // !_CLASS_DIALOG_H_ + diff --git a/src/modules/objects/class_dockwindow.cpp b/src/modules/objects/class_dockwindow.cpp new file mode 100644 index 00000000..fc439b23 --- /dev/null +++ b/src/modules/objects/class_dockwindow.cpp @@ -0,0 +1,276 @@ +//============================================================================= +// +// File : class_dockwindow.cpp +// Created on Thu 29 Dec 2005 23:45:11 by Szymon Stefanek +// +// This file is part of the KVIrc IRC Client distribution +// Copyright (C) 2005 Szymon Stefanek +// +// 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 "class_dockwindow.h" + +#include "kvi_frame.h" +#include "kvi_locale.h" +#include "kvi_qstring.h" +#ifdef COMPILE_USE_QT4 + #include + #define QT_DOCK_WINDOW QDockWidget +#else + #include + #define QT_DOCK_WINDOW QDockWindow +#endif +#include + +/* + @doc: dockwindow + @title: + dockwindow class + @type: + class + @short: + A window dockable to the KVIrc main frame + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + A window dockable to the KVIrc main frame borders (like a toolbar). + The window has an implicit layout that will automatically manage + the children depending on the dock window's orientation. + @functions: + !fn: $addWidget() + Adds to the internal layout of this dock window.[br] + The widget must be a child of this dock window (otherwise strange things may happen). + !fn: $orientation() + Returns the string "vertical" or "horizontal" depending on the orientation of this dock window. + !fn: $setOrientation() + Forces the orentation of this dock window. must be either "horizontal" or "vertical".[br] + Please note that KVIrc sets the orientation automatically when it is moved between the main frame docks by the user. + !fn: $resizeEnabled() + Returns $true if resizing of this window is enabled and false otherwise. + !fn: $setResizeEnabled() + Enabled or disabled resizing of this window. + !fn: $setAllowedDockAreas() + Sets the allowed main window dock areas for this dock window.[br] + must be a combination of "l","r","t","b","f" and "m".[br] + "l" stands for left dock area, "r" stands for right dock area, "t" stands for the top dock areas, "b" stands for the bottom dock area, "f" stands for "floating" and "m" for "minimized".[br] + If a flag is present then the related block area is enabled,otherwise it is disabled. + !fn: $dock() + Docks this dock window to the specified dockarea of the main KVIrc window which can be one of "l" (left dock area), "t" (top dock area), "r" (right dock area), "b" (bottom dock area), "f" (floating) and "m" (minimized). +*/ + + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_dockwindow,"dockwindow","widget") + KVSO_REGISTER_HANDLER(KviKvsObject_dockwindow,"addWidget",function_addWidget) + KVSO_REGISTER_HANDLER(KviKvsObject_dockwindow,"orientation",function_orientation) + KVSO_REGISTER_HANDLER(KviKvsObject_dockwindow,"setOrientation",function_setOrientation) + KVSO_REGISTER_HANDLER(KviKvsObject_dockwindow,"resizeEnabled",function_resizeEnabled) + KVSO_REGISTER_HANDLER(KviKvsObject_dockwindow,"setResizeEnabled",function_setResizeEnabled) + KVSO_REGISTER_HANDLER(KviKvsObject_dockwindow,"setAllowedDockAreas",function_setAllowedDockAreas) + KVSO_REGISTER_HANDLER(KviKvsObject_dockwindow,"dock",function_dock) +KVSO_END_REGISTERCLASS(KviKvsObject_dockwindow) + + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_dockwindow,KviKvsObject_widget) +KVSO_END_CONSTRUCTOR(KviKvsObject_dockwindow) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_dockwindow) +KVSO_END_DESTRUCTOR(KviKvsObject_dockwindow) + +#define _pDockWindow ((QT_DOCK_WINDOW *)widget()) + +bool KviKvsObject_dockwindow::init(KviKvsRunTimeContext * pContext,KviKvsVariantList * pParams) +{ +#ifdef COMPILE_USE_QT4 + QDockWidget * pWidget = new QDockWidget(g_pFrame); + pWidget->setObjectName(getName()); + setObject(pWidget); +#else //!COMPILE_USE_QT4 + setObject(new QT_DOCK_WINDOW(g_pFrame,getName()),true); +#endif //!COMPILE_USE_QT4 + return true; +} + +bool KviKvsObject_dockwindow::function_addWidget(KviKvsObjectFunctionCall *c) +{ + kvs_hobject_t hWidget; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hWidget) + KVSO_PARAMETERS_END(c) + + if(!widget())return true; // hum ? dead ? + + if(hWidget == (kvs_hobject_t)0) + { + // null widget ? + c->warning(__tr2qs("Can't add a null object")); + return true; + } + + KviKvsObject * pWidget = KviKvsKernel::instance()->objectController()->lookupObject(hWidget); + if(!pWidget) + { + c->warning(__tr2qs("Invalid object handle passed as parameter (the object is no longer existing ?)")); + return true; + } + + if(!pWidget->object()) + { + c->warning(__tr2qs("Object in invalid state")); + return true; + } + + if(!pWidget->object()->isWidgetType()) + { + c->warning(__tr2qs("Can't set a non-widget object to be the main widget of a dock window")); + return true; + } + + if(((QWidget *)(pWidget->object()))->parent() != (QObject *)_pDockWindow) + { + c->warning(__tr2qs("The added widget is not a child of this dock window")); + } + +#ifdef COMPILE_USE_QT4 + _pDockWindow->setWidget((QWidget *)(pWidget->object())); +#else //!COMPILE_USE_QT4 + _pDockWindow->boxLayout()->addWidget((QWidget *)(pWidget->object())); + ((QWidget *)(pWidget->object()))->show(); +#endif //!COMPILE_USE_QT4 + return true; +} + +bool KviKvsObject_dockwindow::function_orientation(KviKvsObjectFunctionCall * c) +{ + if(!widget())return true; // hum ? dead ? +#ifdef COMPILE_USE_QT4 + c->returnValue()->setString(QString("horizontal")); +#else //!COMPILE_USE_QT4 + c->returnValue()->setString(_pDockWindow->orientation() == Qt::Horizontal ? QString("horizontal") : QString("vertical")); +#endif //!COMPILE_USE_QT4 + return true; +} + +bool KviKvsObject_dockwindow::function_setOrientation(KviKvsObjectFunctionCall * c) +{ + QString szOrientation; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("orientation",KVS_PT_NONEMPTYSTRING,0,szOrientation) + KVSO_PARAMETERS_END(c) + + if(!widget())return true; // hum ? dead ? +#ifndef COMPILE_USE_QT4 + _pDockWindow->setOrientation(KviQString::equalCI(szOrientation,"vertical") ? Qt::Vertical : Qt::Horizontal); +#endif //!COMPILE_USE_QT4 + return true; +} + +bool KviKvsObject_dockwindow::function_resizeEnabled(KviKvsObjectFunctionCall * c) +{ + if(!widget())return true; // hum ? dead ? +#ifdef COMPILE_USE_QT4 + c->returnValue()->setBoolean(false); +#else //!COMPILE_USE_QT4 + c->returnValue()->setBoolean(_pDockWindow->isResizeEnabled()); +#endif //!COMPILE_USE_QT4 + return true; +} + +bool KviKvsObject_dockwindow::function_setResizeEnabled(KviKvsObjectFunctionCall * c) +{ + bool bResizeEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bResizeEnabled) + KVSO_PARAMETERS_END(c) + + if(!widget())return true; // hum ? dead ? + +#ifndef COMPILE_USE_QT4 + _pDockWindow->setResizeEnabled(bResizeEnabled); +#endif //!COMPILE_USE_QT4 + return true; +} + +bool KviKvsObject_dockwindow::function_setAllowedDockAreas(KviKvsObjectFunctionCall * c) +{ + QString szFlags; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("docks",KVS_PT_STRING,0,szFlags) + KVSO_PARAMETERS_END(c) + + if(!widget())return true; // hum ? dead ? + +#ifdef COMPILE_USE_QT4 + Qt::DockWidgetAreas fAreas = Qt::NoDockWidgetArea; + if(szFlags.find('t',false))fAreas |= Qt::TopDockWidgetArea; + if(szFlags.find('l',false))fAreas |= Qt::LeftDockWidgetArea; + if(szFlags.find('r',false))fAreas |= Qt::RightDockWidgetArea; + if(szFlags.find('b',false))fAreas |= Qt::BottomDockWidgetArea; + _pDockWindow->setAllowedAreas(fAreas); + QDockWidget::DockWidgetFeatures fFeatures = _pDockWindow->features(); + if(szFlags.find('f',false)) + fFeatures |= QDockWidget::DockWidgetFloatable; + else + fFeatures &= ~QDockWidget::DockWidgetFloatable; + // no support for minimized dock widgets + _pDockWindow->setFeatures(fFeatures); +#else //!COMPILE_USE_QT4 + g_pFrame->setDockEnabled(_pDockWindow,Qt::DockTop,szFlags.find('t',false) != -1); + g_pFrame->setDockEnabled(_pDockWindow,Qt::DockLeft,szFlags.find('l',false) != -1); + g_pFrame->setDockEnabled(_pDockWindow,Qt::DockRight,szFlags.find('r',false) != -1); + g_pFrame->setDockEnabled(_pDockWindow,Qt::DockBottom,szFlags.find('b',false) != -1); + g_pFrame->setDockEnabled(_pDockWindow,Qt::DockTornOff,szFlags.find('f',false) != -1); + g_pFrame->setDockEnabled(_pDockWindow,Qt::DockMinimized,szFlags.find('m',false) != -1); +#endif //!COMPILE_USE_QT4 + + return true; +} + + +bool KviKvsObject_dockwindow::function_dock(KviKvsObjectFunctionCall * c) +{ + QString szDock; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("dock",KVS_PT_STRING,0,szDock) + KVSO_PARAMETERS_END(c) + + if(!widget())return true; // hum ? dead ? +#ifdef COMPILE_USE_QT4 + g_pFrame->removeDockWidget(_pDockWindow); + if(szDock.find('m',false) == -1)_pDockWindow->setFloating(false); + if(szDock.find('t',false) != -1)g_pFrame->addDockWidget(Qt::TopDockWidgetArea,_pDockWindow); + else if(szDock.find('l',false) != -1)g_pFrame->addDockWidget(Qt::LeftDockWidgetArea,_pDockWindow); + else if(szDock.find('r',false) != -1)g_pFrame->addDockWidget(Qt::RightDockWidgetArea,_pDockWindow); + else if(szDock.find('b',false) != -1)g_pFrame->addDockWidget(Qt::BottomDockWidgetArea,_pDockWindow); + else if(szDock.find('f',false) != -1)_pDockWindow->setFloating(true); + else if(szDock.find('m',false) != -1)qDebug("Sorry: no support for minimized dock widgets in Qt4"); + else c->warning(__tr2qs("Invalid dock area specified")); + +#else //!COMPILE_USE_QT4 + if(szDock.find('t',false) != -1)g_pFrame->moveDockWindow(_pDockWindow,Qt::DockTop,false,100); + else if(szDock.find('l',false) != -1)g_pFrame->moveDockWindow(_pDockWindow,Qt::DockLeft,false,100); + else if(szDock.find('r',false) != -1)g_pFrame->moveDockWindow(_pDockWindow,Qt::DockRight,false,100); + else if(szDock.find('b',false) != -1)g_pFrame->moveDockWindow(_pDockWindow,Qt::DockBottom,false,100); + else if(szDock.find('f',false) != -1)g_pFrame->moveDockWindow(_pDockWindow,Qt::DockTornOff,false,100); + else if(szDock.find('m',false) != -1)g_pFrame->moveDockWindow(_pDockWindow,Qt::DockMinimized,false,100); + else c->warning(__tr2qs("Invalid dock area specified")); +#endif //!COMPILE_USE_QT4 + return true; +} + +#include "m_class_dockwindow.moc" diff --git a/src/modules/objects/class_dockwindow.h b/src/modules/objects/class_dockwindow.h new file mode 100644 index 00000000..4576a43d --- /dev/null +++ b/src/modules/objects/class_dockwindow.h @@ -0,0 +1,49 @@ +#ifndef _CLASS_DOCKWINDOW_H_ +#define _CLASS_DOCKWINDOW_H_ +//============================================================================= +// +// File : class_dockwindow.h +// Created on Thu 29 Dec 2005 23:45:11 by Szymon Stefanek +// +// This file is part of the KVIrc IRC Client distribution +// Copyright (C) 2005 Szymon Stefanek +// +// 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 "kvi_settings.h" +#include "object_macros.h" + +#include "class_widget.h" + +class KviKvsObject_dockwindow : public KviKvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_dockwindow) +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool function_addWidget(KviKvsObjectFunctionCall *c); + bool function_orientation(KviKvsObjectFunctionCall *c); + bool function_setOrientation(KviKvsObjectFunctionCall *c); + bool function_resizeEnabled(KviKvsObjectFunctionCall *c); + bool function_setResizeEnabled(KviKvsObjectFunctionCall * c); + bool function_setAllowedDockAreas(KviKvsObjectFunctionCall * c); + bool function_dock(KviKvsObjectFunctionCall * c); +}; + +#endif //!_CLASS_DOCKWINDOW_H_ diff --git a/src/modules/objects/class_file.cpp b/src/modules/objects/class_file.cpp new file mode 100644 index 00000000..3429278e --- /dev/null +++ b/src/modules/objects/class_file.cpp @@ -0,0 +1,488 @@ +//vim: ts=8 +// File : class_file.cpp +// Creation date : Thu Sep 21 04:42:16 CEST 2000 by Krzysztof Godlewski +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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. +// + +//#warning "Add QFILEINFO to this stuff ?" + +#include "class_file.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_error.h" +#include "kvi_fileutils.h" +#include + + +// needed for $open() +const char * const mod_tbl[] = { + "Raw", + "ReadOnly", + "WriteOnly", + "ReadWrite", + "Append", + "Truncate" + }; +#ifdef COMPILE_USE_QT4 +#define IO_RAW QIODevice::Unbuffered +#define IO_READONLY QIODevice::ReadOnly +#define IO_WRITEONLY QIODevice::WriteOnly +#define IO_READWRITE QIODevice::ReadWrite +#define IO_APPEND QIODevice::Append +#define IO_TRUNCATE QIODevice::Truncate +//#define IO_TRANSLATE QIODevice::Text +#else +#define IO_RAW IO_Raw +#define IO_READONLY IO_ReadOnly +#define IO_WRITEONLY IO_WriteOnly +#define IO_READWRITE IO_ReadWrite +#define IO_APPEND IO_Append +#define IO_TRUNCATE IO_Truncate +#endif +#ifdef COMPILE_USE_QT4 +const QIODevice::OpenMode mod_cod[] = { +#else +const int mod_cod[] = { +#endif + IO_RAW, + IO_READONLY, + IO_WRITEONLY, + IO_READWRITE, + IO_APPEND, + IO_TRUNCATE + }; + +#define mod_num (sizeof(mod_tbl) / sizeof(mod_tbl[0])) + +/* + @doc: file + @keyterms: + file object class, creating files + @title: + file class + @type: + class + @short: + I/O device that operates on files + @inherits: + [class]object[/class] + @description: + This object class provides access to files - basic I/O + operations, copying, removing etc... + @functions: + !fn: $setName() + Sets the file name to . It does [b]not move[/b] the file, + it just changes the file the object is "pointing to". You can + not change names of already open files.[br] + See also: [classfnc]$open[/classfnc](), + [classfnc]$name[/classfnc](). + !fn: $name() + Returns name set by [classfnc]$setName[/classfnc]().[br] + See also: [classfnc]$setName[/classfnc](). + !fn: $open(, ) + Attempts to open the file in specified mode or modes "sum". + Valid modes are:[br] + [pre] + Raw - raw, non-buffered access[br] + ReadOnly - opens the file read-only[br] + WriteOnly - opens the file write-only[br] + ReadWrite - opens the file in read-write mode[br] + Append - opens the file in append mode. The file index is set to the end of the file.[br] + Truncate - truncates the file[br] + [/pre] + If you call this function without any parameters, the file is + opened in ReadOnly mode.[br] + When working with buffered files, data is not written directly + to the file at once. You must call [classfnc]$flush[/classfnc]() to force it.[br] + See also: [classfnc]$close[/classfnc](), + [classfnc]$flush[/classfnc](). + !fn: $isOpen() + Returns '1' if the file is open, '0' otherwise. + !fn: $close() + Closes the file, flushing the buffers first.[br] + See also: [classfnc]$flush[/classfnc](). + !fn: $flush() + Flushes the file buffer to disk. Calling this after opening the + file in 'Raw' mode doesn't make much sense.[br] + See also: [classfnc]$open[/classfnc](), + [classfnc]$close[/classfnc](). + !fn: $size() + Returns current file size. + !fn: $atEnd() + Returns '1' if you have reached end of the file, '0' otherwise. + [br]See also: [classfnc]$seek[/classfnc](), + [classfnc]$where[/classfnc](). + !fn: $where() + Returns current position in the file (file index).[br] + See also: [classfnc]$seek[/classfnc](). + !fn: $seek() + Sets the file index to .[br] + See also: [classfnc]$where[/classfnc](), + [classfnc]$atEnd[/classfnc](). + !fn: $putch() + Writes character to the file and increments file + index.[br] + See also: [classfnc]$getch[/classfnc](), + [classfnc]$ungetch[/classfnc](). + !fn: $getch() + Reads a character from the file and increments file index.[br] + See also: [classfnc]$putch[/classfnc](), + [classfnc]$ungetch[/classfnc](). + !fn: $ungetch() + Puts the character back to the file and + decrements the file index. This is usually called to undo a + $getch() call.[br] + See also: [classfnc]$getch[/classfnc], + [classfnc]$putch[/classfnc](). + !fn: $readLine() + Reads a line of text from the file and increments file index. + !fn: $writeLine() + Appends a line of text to the end of the file. + $readBlock() + $writeBlock() + $writeHex() + $readHex() +*/ + + +//--------------------------------------------------------------------------------- + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_file,"file","object") + KVSO_REGISTER_HANDLER(KviKvsObject_file,"setName", functionsetName) + KVSO_REGISTER_HANDLER(KviKvsObject_file,"name", functionname) + KVSO_REGISTER_HANDLER(KviKvsObject_file,"open", functionopen) + KVSO_REGISTER_HANDLER(KviKvsObject_file,"isOpen", functionisOpen) + KVSO_REGISTER_HANDLER(KviKvsObject_file,"close", functionclose) + KVSO_REGISTER_HANDLER(KviKvsObject_file,"flush", functionflush) + KVSO_REGISTER_HANDLER(KviKvsObject_file,"size", functionsize) + KVSO_REGISTER_HANDLER(KviKvsObject_file,"atEnd", functionatEnd) + KVSO_REGISTER_HANDLER(KviKvsObject_file,"where", functionwhere) + + KVSO_REGISTER_HANDLER(KviKvsObject_file,"seek", functionseek) + KVSO_REGISTER_HANDLER(KviKvsObject_file,"putch", functionputch) + KVSO_REGISTER_HANDLER(KviKvsObject_file,"getch", functiongetch) + KVSO_REGISTER_HANDLER(KviKvsObject_file,"ungetch", functionunGetch) + KVSO_REGISTER_HANDLER(KviKvsObject_file,"readBlock", functionreadBlock) + KVSO_REGISTER_HANDLER(KviKvsObject_file,"writeBlock", functionwriteBlock) + KVSO_REGISTER_HANDLER(KviKvsObject_file,"readLine", functionreadLine) + KVSO_REGISTER_HANDLER(KviKvsObject_file,"writeLine", functionwriteLine) +/* KVSO_REGISTER_HANDLER(KviKvsObject_file,"hexWrite", functionHexWrite) + KVSO_REGISTER_HANDLER(KviKvsObject_file,"hexRead", functionHexRead) +*/ + KVSO_END_REGISTERCLASS(KviKvsObject_file) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_file,KviKvsObject) + m_pFile = new QFile(); +KVSO_END_CONSTRUCTOR(KviKvsObject_file) + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_file) +if (m_pFile) delete m_pFile; +m_pFile=0; + +KVSO_END_CONSTRUCTOR(KviKvsObject_file) + + +bool KviKvsObject_file::functionsetName(KviKvsObjectFunctionCall *c) +{ + QString szName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("file_name",KVS_PT_STRING,0,szName) + KVSO_PARAMETERS_END(c) + if (m_pFile) m_pFile->setName(szName); + return true; +} +bool KviKvsObject_file::functionname(KviKvsObjectFunctionCall *c) +{ + if (m_pFile) c->returnValue()->setString(m_pFile->name()); + return true; +} + +bool KviKvsObject_file::functionopen(KviKvsObjectFunctionCall *c) +{ + QStringList modes; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("file_mode",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,modes) + KVSO_PARAMETERS_END(c) + if (!m_pFile) return true; + if(m_pFile->name().isEmpty()) + { + c->warning(__tr2qs("Empty filename string")); + return true; + } + #ifdef COMPILE_USE_QT4 + QIODevice::OpenMode mod,sum; + if (modes.empty()) sum = IO_READONLY; // if no parameters given, default to ReadWrite | Append + else + { + for ( int idx=0;idxwarning(__tr2qs("No such open mode: '%Q'"),&modes.at(idx)); + } + } +#else + int mod,sum=0; +if (!modes.first()) sum = IO_READONLY; // if no parameters given, default to ReadWrite | Append + else + { + for ( QStringList::Iterator it = modes.begin(); it != modes.end(); ++it ) + { + + mod = 0; + for(unsigned int j = 0; j < mod_num; j++) + { + if(KviQString::equalCI((*it), mod_tbl[j])) + { + mod=mod_cod[j]; + break; + } + } + if(mod) + sum = sum | mod; + else + c->warning(__tr2qs("No such open mode: '%Q'"),&(*it)); + } + } +#endif + m_pFile->open(sum); + return true; +} + +bool KviKvsObject_file::functionisOpen(KviKvsObjectFunctionCall *c) +{ + if (m_pFile) c->returnValue()->setBoolean(m_pFile->isOpen()); + return true; +} + +bool KviKvsObject_file::functionclose(KviKvsObjectFunctionCall *c) +{ + if (!m_pFile->isOpen()) c->warning(__tr2qs("File is not open!")); + else m_pFile->close(); + return true; +} +bool KviKvsObject_file::functionflush(KviKvsObjectFunctionCall *c) +{ + if (!m_pFile->isOpen()) c->warning(__tr2qs("File is not open!")); + else m_pFile->flush(); + return true; +} + +bool KviKvsObject_file::functionsize(KviKvsObjectFunctionCall *c) +{ + if (m_pFile) c->returnValue()->setInteger((kvs_int_t)(m_pFile->size())); + return true; +} +bool KviKvsObject_file::functionatEnd(KviKvsObjectFunctionCall *c) +{ + if (m_pFile) c->returnValue()->setInteger((kvs_int_t)(m_pFile->size())); + return true; +} + + +bool KviKvsObject_file::functionwhere(KviKvsObjectFunctionCall *c) +{ + if (!m_pFile->isOpen()) c->warning(__tr2qs("File is not open!")); + else c->returnValue()->setInteger((kvs_int_t)(m_pFile->at())); + return true; +} +bool KviKvsObject_file::functionseek(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + if (!m_pFile) return true; + if(!m_pFile->isOpen()) + c->warning(__tr("File is not open !")); + else m_pFile->at(uIndex); + return true; +} + +bool KviKvsObject_file::functionputch(KviKvsObjectFunctionCall *c) +{ + QString szChar; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("char",KVS_PT_STRING,KVS_PF_OPTIONAL,szChar) + KVSO_PARAMETERS_END(c) + if (m_pFile) + { + if (szChar.length()>1)c->warning(__tr2qs("Argument to long, using only first char")); + const char *ch=szChar; + if (m_pFile->putch(ch[0])<0) c->warning(__tr2qs("Write error occured !")); + } + + return true; +} +bool KviKvsObject_file::functiongetch(KviKvsObjectFunctionCall *c) +{ + if (!m_pFile) return true; + if(!m_pFile->isOpen()) + c->warning(__tr("File is not open !")); + else + { + int chInt=m_pFile->getch(); + if (chInt<0) c->warning(__tr("Read error occured !")); // c->error ? + QString szChar = QChar(chInt); + c->returnValue()->setString(szChar); + } + return true; +} +bool KviKvsObject_file::functionunGetch(KviKvsObjectFunctionCall *c) +{ + QString szChar; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("char",KVS_PT_STRING,0,szChar) + KVSO_PARAMETERS_END(c) + if (!m_pFile) return true; + if(!m_pFile->isOpen()) + c->warning(__tr("File is not open !")); + else + { + if (szChar.length()>1) c->warning(__tr2qs("Argument to long, using only first char")); + const char *ch=szChar; + if (m_pFile->ungetch(ch[0])<0) c->warning(__tr2qs("An error occured !"));// c->error ? + } + return true; +} +bool KviKvsObject_file::functionreadBlock(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uLen; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("lenght",KVS_PT_UNSIGNEDINTEGER,0,uLen) + KVSO_PARAMETERS_END(c) + if (!m_pFile) return true; + if(!m_pFile->isOpen()) + c->warning(__tr("File is not open !")); + else + { + char * buff = new char[uLen + 1]; + m_pFile->flush(); // advice from QFile man page (to avoid trash) + int rlen = m_pFile->readBlock(buff, uLen); + buff[rlen] = '\0'; + QString szBlock(buff); + c->returnValue()->setString(szBlock); + } + return true; +} + +bool KviKvsObject_file::functionwriteBlock(KviKvsObjectFunctionCall *c) +{ + QString szBlock; + kvs_uint_t uLen; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("lenght",KVS_PT_UNSIGNEDINTEGER,0,uLen) + KVSO_PARAMETER("text_block",KVS_PT_STRING,0,szBlock) + KVSO_PARAMETERS_END(c) + if (!m_pFile) return true; + if(!m_pFile->isOpen()) + c->warning(__tr("File is not open !")); + const char *block=szBlock; + int rlen = m_pFile->writeBlock(block, uLen); + c->returnValue()->setInteger(rlen); + m_pFile->flush(); + return true; +} +bool KviKvsObject_file::functionreadLine(KviKvsObjectFunctionCall *c) +{ + if (!m_pFile) return true; + if(!m_pFile->isOpen()) + c->warning(__tr("File is not open !")); + else + { + QString buffer; + KviFileUtils::readLine(m_pFile,buffer); + c->returnValue()->setString(buffer); + } + return true; +} +bool KviKvsObject_file::functionwriteLine(KviKvsObjectFunctionCall *c) +{ + QString szLine; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text_line",KVS_PT_STRING,0,szLine) + KVSO_PARAMETERS_END(c) + if (!m_pFile) return true; + if(!m_pFile->isOpen()) + c->warning(__tr("File is not open !")); + else + { + QTextStream ts(m_pFile); + ts << szLine; + } + return true; +} +// fixme +/* + +bool KviScriptFileObject::functionHexWrite(KviCommand * c, KviParameterList * p, + KviStr & b) +{ + ENTER_STACK_FRAME(c, "file::hexWrite"); + if(!p->count()) + return c->error(KviError_notEnoughParameters); + + char * val = 0; + int len = p->first()->hexToBuffer(&val,false); + + if(len < 1) + { + c->warning(__tr("Nothing to write")); + return c->leaveStackFrame(); + } + + if(!m_pFile->isOpen()) + c->warning(__tr("File is not open !")); + + if(m_pFile->putch(*val) < 0) + c->warning(__tr("Write error occured !")); // c->error ? + + KviStr::freeBuffer(val); + + return c->leaveStackFrame(); +} + +bool KviScriptFileObject::functionHexRead(KviCommand * c, KviParameterList * p, + KviStr & b) +{ + if(!m_pFile->isOpen()) + c->warning(__tr("File is not open !")); + + char ch = m_pFile->getch(); + + KviStr tmp; + tmp.bufferToHex(&ch, 1); + b.append(tmp); + + return true; +} + +*/ +#include "m_class_file.moc" diff --git a/src/modules/objects/class_file.h b/src/modules/objects/class_file.h new file mode 100644 index 00000000..01a54d19 --- /dev/null +++ b/src/modules/objects/class_file.h @@ -0,0 +1,113 @@ +#ifndef _CLASS_FILE_H_ +#define _CLASS_FILE_H_ +//vim: ts=8 +// File : class_file.h +// Creation date : Thu Sep 21 04:43:01 CEST 2000 by Krzysztof Godlewski +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 +#include +#include "kvi_string.h" + + +/* +//class KviCommand; +class KviParameterList; + +class KviScriptFileObject : public KviScriptObject +{ + Q_OBJECT +public: + KviScriptFileObject(KviScriptObjectClass *, KviScriptObject *, const char *); + virtual ~KviScriptFileObject(); + + static void registerSelf(); + static void unregisterSelf(); + +protected: + bool functionSetName(KviCommand *, KviParameterList *, KviStr &); + bool functionName(KviCommand *, KviParameterList *, KviStr &); + bool functionOpen(KviCommand *, KviParameterList *, KviStr &); + bool functionIsOpen(KviCommand *, KviParameterList *, KviStr &); + bool functionClose(KviCommand *, KviParameterList *, KviStr &); + bool functionFlush(KviCommand *, KviParameterList *, KviStr &); + bool functionSize(KviCommand *, KviParameterList *, KviStr &); + + bool functionAtEnd(KviCommand *, KviParameterList *, KviStr &); + // int QFile at() const + bool functionWhere(KviCommand *, KviParameterList *, KviStr &); + // void QFile at(int) + bool functionSeek(KviCommand *, KviParameterList *, KviStr &); + bool functionPutch(KviCommand *, KviParameterList *, KviStr &); + bool functionGetch(KviCommand *, KviParameterList *, KviStr &); + bool functionUngetch(KviCommand *, KviParameterList *, KviStr &); + + bool functionReadBlock(KviCommand *, KviParameterList *, KviStr &); + bool functionWriteBlock(KviCommand *, KviParameterList *, KviStr &); + + bool functionReadLine(KviCommand *, KviParameterList *, KviStr &); + bool functionWriteLine(KviCommand *, KviParameterList *, KviStr &); + bool functionHexWrite(KviCommand *, KviParameterList *, KviStr &); + bool functionHexRead(KviCommand *, KviParameterList *, KviStr &); + +protected: + QFile * m_pFile; +}; + +*/ + +#include "object_macros.h" + +class KviKvsObject_file : public KviKvsObject +{ +public: + KVSO_DECLARE_OBJECT(KviKvsObject_file) +protected: + bool functionsetName(KviKvsObjectFunctionCall *c); + bool functionname(KviKvsObjectFunctionCall *c); + bool functionopen(KviKvsObjectFunctionCall *c); + bool functionisOpen(KviKvsObjectFunctionCall *c); + bool functionclose(KviKvsObjectFunctionCall *c); + bool functionflush(KviKvsObjectFunctionCall *c); + bool functionsize(KviKvsObjectFunctionCall *c); + + bool functionatEnd(KviKvsObjectFunctionCall *c); + // int QFile at() const + bool functionwhere(KviKvsObjectFunctionCall *c); + // void QFile at(int) + bool functionseek(KviKvsObjectFunctionCall *c); + bool functionputch(KviKvsObjectFunctionCall *c); + bool functiongetch(KviKvsObjectFunctionCall *c); + bool functionunGetch(KviKvsObjectFunctionCall *c); + + bool functionreadBlock(KviKvsObjectFunctionCall *c); + bool functionwriteBlock(KviKvsObjectFunctionCall *c); + + bool functionreadLine(KviKvsObjectFunctionCall *c); + bool functionwriteLine(KviKvsObjectFunctionCall *c); +/* bool functionHexWrite(KviKvsObjectFunctionCall *c); + bool functionHexRead(KviKvsObjectFunctionCall *c); +*/ +protected: + QFile * m_pFile; +}; +#endif // !_CLASS_FILE_H_ diff --git a/src/modules/objects/class_groupbox.cpp b/src/modules/objects/class_groupbox.cpp new file mode 100644 index 00000000..14e640d1 --- /dev/null +++ b/src/modules/objects/class_groupbox.cpp @@ -0,0 +1,376 @@ +// +// File : class_groupbox.cpp +// Creation date : Fri Jan 28 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 +#include "class_groupbox.h" +#include "kvi_error.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_iconmanager.h" + +// Tables used in $setAlignment , $alignment and in $setOrientation & $orientation + +const char * const align_tbl[] = { + "Left", + "Right", + "HCenter" + }; +const int align_cod[] = { + Qt::AlignLeft, + Qt::AlignRight, + Qt::AlignHCenter + }; +#define align_num (sizeof(align_tbl) / sizeof(align_tbl[0])) + + +/* + @doc: groupbox + @keyterms: + groupbox object class, + @title: + groupbox class + @type: + class + @short: + Provides a groupbox bar. + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + This widget can be used to display a groupbox. + It will be usually a parent for other child controls. + You can either use a child layout to manage the children geometries + or use $setColumnLayout to manage the layout automatically. + @functions: + !fn: $setTitle() + Sets the group box title to . + !fn: $title() + Returns the group box title text. + !fn: $setFlat() + Sets whether the group box is painted flat. Valid Values are 1 or 0. + !fn: $isFlat() + Returns 1 (TRUE) if the group box is painted flat; otherwise returns 0 (FALSE). + !fn: $isCheckable() + Returns 1 (TRUE) if the group box has a checkbox in its title; otherwise returns 0 (FALSE). + !fn: $setCheckable() + Sets whether the group box has a checkbox in its title: Valid values are 1 or 0. + !fn: $setInsideMargin() + Sets the the width of the inside margin to m pixels. + !fn: $insideMargin() + Returns the width of the empty space between the items in the group and margin of groupbox. + !fn: $setInsideSpacing() + Sets the width of the empty space between each of the items in the group to m pixels. + !fn: $insideSpacing() + Returns the width of the empty space between each of the items in the group. + !fn: $setColumns() + Sets the number of columns or rows (depending of the orientation) in the group box. + !fn: $columns() + Returns the number of columns or rows in the groupbox. + !fn: $addSpace() + Adds an empty cell at the next free position. + !fn: $alignment() + Returns the alignment of the group box title. + !fn: $setAlignment() + Set the alignment of the groupbox; Valid values are Left,Right,HCenter. + !fn: $setOrientation + Sets the group box's orientation. Valid values are: Horizontal, Vertical. + !fn: $setColumnLayout(,) + Enables the automatic layout management. The children are arranged in n columns with the specified orientation.[br] + Valid values for are: Horizontal, Vertical. + @examples: + [example] + |-Start:[br] + #Let's start.[br] + #first we'll create the main widget.[br] + %widget=$new(widget)[br] + [br] + #then the groupbox [br] + %gb=$new(groupbox,%widget)[br] + %gb->$setTitle(Login)[br] + %gb->$setAlignment("Left")[br] + [br] + #now we create the labels and lineedits.[br] + %labeluser=$new(label,%gb)[br] + %labeluser->$settext(User: )[br] + %labelpass=$new(label,%gb)[br] + %labelpass->$settext(Pass: )[br] + %inputuser=$new(lineedit,%gb)[br] + %inputpass=$new(lineedit,%gb)[br] + %inputpass->$setechomode("password")[br] + [br] + #now lets' layouting the groupbox's element's.[br] + %layoutgb=$new(layout,%gb)[br] + %layoutgb->$setmargin(20)[br] + %layoutgb->$addwidget(%labeluser,0,0)[br] + %layoutgb->$addwidget(%labelpass,1,0)[br] + %layoutgb->$addwidget(%inputuser,0,1)[br] + %layoutgb->$addwidget(%inputpass,1,1)[br] + [br] + # now we create a fake widget and managing the two buttons layout.[br] + %fakewidget=$new(widget,%widget)[br] + %layoutbtn=$new(layout,%fakewidget)[br] + %btnok=$new(button,%fakewidget)[br] + %btnok->$settext("OK")[br] + %btncancel=$new(button,%fakewidget)[br] + %btncancel->$settext("Cancel")[br] + %layoutbtn->$addwidget(%btnok,0,0)[br] + %layoutbtn->$addwidget(%btncancel,0,1)[br] + [br] + #And finally we create a main layout with the groupbox (and its "children")[br] + #and fakewiget (with its buttons children). + %mainlayout=$new(layout,%widget)[br] + %mainlayout->$setspacing(10)[br] + %mainlayout->$setmargin(10)[br] + %mainlayout->$addwidget(%gb,0,0)[br] + %mainlayout->$addwidget(%fakewidget,1,0)[br] + [br] + #Let's show our nice login request =D ! [br] + %widget->$show()[br] + [/example] + +*/ + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_groupbox,"groupbox","widget") + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setTitle", functionSetTitle) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"title", functionTitle) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setFlat", functionSetFlat) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"isFlat", functionIsFlat) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setCheckable", functionSetCheckable) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"isCheckable", functionIsCheckable) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setInsideMargin", functionSetInsideMargin) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"insideMargin", functionInsideMargin) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setInsideSpacing", functionSetInsideSpacing) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"insideSpacing", functionInsideSpacing) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setColumns", functionSetColumns) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"columns", functionColumns) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"addSpace", functionAddSpace) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"alignment", functionAlignment) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setAlignment", functionSetAlignment) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setOrientation", functionSetOrientation) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"isChecked", functionIsChecked) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setChecked", functionSetChecked) + KVSO_REGISTER_HANDLER(KviKvsObject_groupbox,"setColumnLayout",functionSetColumnLayout) +KVSO_END_REGISTERCLASS(KviKvsObject_groupbox) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_groupbox,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_groupbox) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_groupbox) + +KVSO_END_CONSTRUCTOR(KviKvsObject_groupbox) + +bool KviKvsObject_groupbox::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ +#ifdef COMPILE_USE_QT4 + KviTalGroupBox *groupbox=new KviTalGroupBox(name(),parentScriptWidget()); + groupbox->setObjectName(name()); + setObject(groupbox,true); +#else + setObject(new KviTalGroupBox(name(),parentScriptWidget()), true); +#endif + return true; +} + +bool KviKvsObject_groupbox::functionSetTitle(KviKvsObjectFunctionCall *c) +{ + QString szTitle; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("title",KVS_PT_STRING,0,szTitle) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalGroupBox *)widget())->setTitle(szTitle); + return true; +} +bool KviKvsObject_groupbox::functionTitle(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setString(((KviTalGroupBox *)widget())->title()); + return true; +} +bool KviKvsObject_groupbox::functionSetFlat(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bFlag",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((KviTalGroupBox *)widget())->setFlat(bEnabled); + return true; +} +bool KviKvsObject_groupbox::functionIsFlat(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setBoolean(((KviTalGroupBox *)widget())->isFlat()); + return true; +} +bool KviKvsObject_groupbox::functionSetCheckable(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bFlag",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((KviTalGroupBox *)widget())->setCheckable(bEnabled); + return true; +} +bool KviKvsObject_groupbox::functionIsCheckable(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setBoolean(((KviTalGroupBox *)widget())->isCheckable()); + return true; +} +bool KviKvsObject_groupbox::functionSetChecked(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bFlag",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((KviTalGroupBox *)widget())->setChecked(bEnabled); + return true; +} +bool KviKvsObject_groupbox::functionIsChecked(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setBoolean(((KviTalGroupBox *)widget())->isChecked()); + return true; +} +bool KviKvsObject_groupbox::functionSetInsideMargin(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uMargin; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("margin",KVS_PT_UNSIGNEDINTEGER,0,uMargin) + KVSO_PARAMETERS_END(c) + if (widget()) ((KviTalGroupBox *)widget())->setInsideMargin(uMargin); + return true; +} +bool KviKvsObject_groupbox::functionInsideMargin(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setInteger(((KviTalGroupBox *)widget())->insideMargin()); + return true; +} +bool KviKvsObject_groupbox::functionSetInsideSpacing(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uSpacing; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("spacing",KVS_PT_UNSIGNEDINTEGER,0,uSpacing) + KVSO_PARAMETERS_END(c) + if (widget()) ((KviTalGroupBox *)widget())->setInsideSpacing(uSpacing); + return true; +} +bool KviKvsObject_groupbox::functionInsideSpacing(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setInteger(((KviTalGroupBox *)widget())->insideSpacing()); + return true; +} +bool KviKvsObject_groupbox::functionSetColumns(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uColums; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("colums",KVS_PT_UNSIGNEDINTEGER,0,uColums) + KVSO_PARAMETERS_END(c) + if (widget()) ((KviTalGroupBox *)widget())->setColumns(uColums); + return true; +} +bool KviKvsObject_groupbox::functionColumns(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setInteger(((KviTalGroupBox *)widget())->columns()); + return true; +} +bool KviKvsObject_groupbox::functionAddSpace(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t iSpace; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("colums",KVS_PT_UNSIGNEDINTEGER,0,iSpace) + KVSO_PARAMETERS_END(c) + if (widget()) (((KviTalGroupBox *)widget())->addSpace(iSpace)); + return true; +} + +bool KviKvsObject_groupbox::functionSetAlignment(KviKvsObjectFunctionCall *c) +{ + QString szAlign; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("alignment",KVS_PT_STRING,0,szAlign) + KVSO_PARAMETERS_END(c) + if (!widget()) return true; + for(unsigned int i = 0; i < align_num; i++) + { + if(KviQString::equalCI(szAlign, align_tbl[i])) + { + ((KviTalGroupBox *)widget())->setAlignment(align_cod[i]); + return true; + } + } + c->warning(__tr2qs("Unknown alignment")); + return true; +} +bool KviKvsObject_groupbox::functionAlignment(KviKvsObjectFunctionCall *c) +{ + int mode = ((KviTalGroupBox *)widget())->alignment(); + QString szAlignment=""; + for(unsigned int i = 0; i < align_num; i++) + { + if(mode == align_cod[i]) + { + szAlignment=align_tbl[i]; + break; + } + } + c->returnValue()->setString(szAlignment); + return true; +} + +bool KviKvsObject_groupbox::functionSetOrientation(KviKvsObjectFunctionCall *c) +{ + QString szMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("orientation",KVS_PT_STRING,0,szMode) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + if(KviQString::equalCI(szMode, "Horizontal")) + ((KviTalGroupBox *)widget())->setOrientation(Qt::Horizontal); + else + if(KviQString::equalCI(szMode, "Vertical")) + ((KviTalGroupBox *)widget())->setOrientation(Qt::Vertical); + else c->warning( __tr2qs("Unknown orientation: ")); + return true; +} + +bool KviKvsObject_groupbox::functionSetColumnLayout(KviKvsObjectFunctionCall *c) +{ + QString szMode; + kvs_uint_t uCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("columns",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("orientation",KVS_PT_STRING,0,szMode) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + if(szMode=="Horizontal") + ((KviTalGroupBox *)widget())->setColumnLayout(uCol,Qt::Horizontal); + else + if(szMode=="Vertical") + ((KviTalGroupBox *)widget())->setColumnLayout(uCol,Qt::Vertical); + else c->warning( __tr2qs("Unknown orientation: ")); + return true; +} + diff --git a/src/modules/objects/class_groupbox.h b/src/modules/objects/class_groupbox.h new file mode 100644 index 00000000..c63bb46b --- /dev/null +++ b/src/modules/objects/class_groupbox.h @@ -0,0 +1,64 @@ +#ifndef _CLASS_GROUPBOX_H_ +#define _CLASS_GROUPBOX_H_ +// +// File : class_groupbox.h +// Creation date : Fri Jan 28 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 +#include "class_widget.h" +#include "object_macros.h" + +class KviKvsObject_groupbox : public KviKvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KviKvsObject_groupbox) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + + bool functionSetTitle(KviKvsObjectFunctionCall *c); + bool functionTitle(KviKvsObjectFunctionCall *c); + bool functionSetFlat(KviKvsObjectFunctionCall *c); + bool functionIsFlat(KviKvsObjectFunctionCall *c); + bool functionSetCheckable(KviKvsObjectFunctionCall *c); + bool functionIsCheckable(KviKvsObjectFunctionCall *c); + bool functionSetInsideMargin(KviKvsObjectFunctionCall *c); + bool functionInsideMargin(KviKvsObjectFunctionCall *c); + bool functionSetInsideSpacing(KviKvsObjectFunctionCall *c); + bool functionInsideSpacing(KviKvsObjectFunctionCall *c); + bool functionSetColumns(KviKvsObjectFunctionCall *c); + bool functionColumns(KviKvsObjectFunctionCall *c); + bool functionAddSpace(KviKvsObjectFunctionCall *c); + bool functionAlignment(KviKvsObjectFunctionCall *c); + bool functionSetAlignment(KviKvsObjectFunctionCall *c); + bool functionSetOrientation(KviKvsObjectFunctionCall *c); + bool functionIsChecked(KviKvsObjectFunctionCall *c); + bool functionSetChecked(KviKvsObjectFunctionCall *c); + bool functionSetColumnLayout(KviKvsObjectFunctionCall *c); + +}; +#endif //!_CLASS_GROUPBOX_H_ + diff --git a/src/modules/objects/class_hbox.cpp b/src/modules/objects/class_hbox.cpp new file mode 100644 index 00000000..48174312 --- /dev/null +++ b/src/modules/objects/class_hbox.cpp @@ -0,0 +1,128 @@ +// +// File : class_hbox.cpp +// Creation date : Wed Mar 01 2005 23:00:01 by Alessandro Carbone & Tonino Imbesi +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2002-2006 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. +// +#define _KVI_DEBUG_CHECK_RANGE_ +#include "kvi_debug.h" + +#include "kvi_locale.h" + +#include "class_hbox.h" + +/* + @doc: hbox + @keyterms: + hbox object class, child widgets + @title: + hbox class + @type: + class + @short: + Manages child widget horizontal geometry + @inherits: + [class]object[/class] + @description: + The hbox class widget provides horizontal geometry management for its child widgets. + @functions: + !fn: $setSpacing() + Sets the default spacing of the widgets in pixels + !fn: $setMargin() + Sets the dimension of the layout margin : the distance from the border to the outermost child widget edges. + !fn: $setStretchFactor(,) + Sets the stretch factor of widget to stretch. +*/ + + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_hbox,"hbox","widget") + KVSO_REGISTER_HANDLER(KviKvsObject_hbox,"setMargin", functionsetMargin) + KVSO_REGISTER_HANDLER(KviKvsObject_hbox,"setSpacing", functionsetSpacing) + KVSO_REGISTER_HANDLER(KviKvsObject_hbox,"setStretchFactor", functionsetStretchFactor ) +KVSO_END_REGISTERCLASS(KviKvsObject_hbox) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_hbox,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_hbox) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_hbox) + +KVSO_END_CONSTRUCTOR(KviKvsObject_hbox) + +bool KviKvsObject_hbox::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + + setObject(new KviTalHBox(parentScriptWidget()), true); + return true; +} +bool KviKvsObject_hbox::functionsetMargin(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uMargin; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("margin",KVS_PT_UNSIGNEDINTEGER,0,uMargin) + KVSO_PARAMETERS_END(c) + if (widget()) ((KviTalHBox *)widget())->setMargin(uMargin); + return true; +} + +bool KviKvsObject_hbox::functionsetSpacing(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uSpacing; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("spacing",KVS_PT_UNSIGNEDINTEGER,0,uSpacing) + KVSO_PARAMETERS_END(c) + if (widget()) ((KviTalHBox *)widget())->setSpacing(uSpacing); + return true; +} +bool KviKvsObject_hbox::functionsetStretchFactor(KviKvsObjectFunctionCall *c) +{ + KviKvsObject * pObject; + kvs_hobject_t hObject; + kvs_uint_t uStretch; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("stretch",KVS_PT_UNSIGNEDINTEGER,0,uStretch) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if(!widget())return true; + if (!pObject) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!pObject->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!pObject->object()->isWidgetType()) + { + c->warning(__tr2qs("Can't add a non-widget object")); + return true; + } + if(((KviKvsObject_widget *)pObject)->widget()->parentWidget() != widget()) + { + c->warning(__tr2qs("The widget must be a child of this hbox")); + return true; + } + ((KviTalHBox *)widget())->setStretchFactor(((QWidget *)(pObject->object())),uStretch); + return true; +} + + diff --git a/src/modules/objects/class_hbox.h b/src/modules/objects/class_hbox.h new file mode 100644 index 00000000..c0489f28 --- /dev/null +++ b/src/modules/objects/class_hbox.h @@ -0,0 +1,47 @@ +#ifndef _CLASS_HBOX_H_ +#define _CLASS_HBOX_H_ +// +// File : class_hbox.h +// Creation date : Wed Mar 01 2005 23:00:01 by Alessandro Carbone & Tonino Imbesi +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2002-2006 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 "kvi_string.h" + +#include "kvi_tal_hbox.h" +#include "object_macros.h" +#include "class_widget.h" + +class KviKvsObject_hbox : public KviKvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KviKvsObject_hbox) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool functionsetMargin(KviKvsObjectFunctionCall *c); + bool functionsetSpacing(KviKvsObjectFunctionCall *c); + bool functionsetStretchFactor(KviKvsObjectFunctionCall *c); + + +}; + + +#endif //_CLASS_HBOX_H_ diff --git a/src/modules/objects/class_label.cpp b/src/modules/objects/class_label.cpp new file mode 100644 index 00000000..9c629818 --- /dev/null +++ b/src/modules/objects/class_label.cpp @@ -0,0 +1,409 @@ +//vim: ts=8 +// File : class_label.cpp +// Creation date : Mon Sep 18 14:21:48 CEST 2000 by Krzysztof Godlewski +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 Krzysztof Godlewski +// Copyright (C) 1999-2000 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 +#include +#include +#include "class_label.h" +//#include "kvi_fileutils.h" +#include "kvi_error.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_iconmanager.h" + + + +// Tables used in $setAlignment & $alignment +const char * const align_tbl[] = { + "Left", + "Right", + "HCenter", + "VCenter", + "Center", + "Top", + "Bottom", + "WordBreak" + }; +#ifdef COMPILE_USE_QT4 + #define QT_LABEL_ALIGNLEFT Qt::AlignLeft + #define QT_LABEL_ALIGNRIGHT Qt::AlignRight + #define QT_LABEL_ALIGNHCENTER Qt::AlignHCenter + #define QT_LABEL_ALIGNVCENTER Qt::AlignVCenter + #define QT_LABEL_ALIGNCENTER Qt::AlignCenter + #define QT_LABEL_ALIGNTOP Qt::AlignTop + #define QT_LABEL_ALIGNBOTTOM Qt::AlignBottom + #define QT_LABEL_JUSTIFY Qt::AlignJustify +#else + #define QT_LABEL_ALIGNLEFT QLabel::AlignLeft + #define QT_LABEL_ALIGNRIGHT QLabel::AlignRight + #define QT_LABEL_ALIGNHCENTER QLabel::AlignHCenter + #define QT_LABEL_ALIGNVCENTER QLabel::AlignVCenter + #define QT_LABEL_ALIGNCENTER QLabel::AlignCenter + #define QT_LABEL_ALIGNTOP QLabel::AlignTop + #define QT_LABEL_ALIGNBOTTOM QLabel::AlignBottom + #define QT_LABEL_JUSTIFY QLabel::WordBreak +#endif + +const int align_cod[] = { + QT_LABEL_ALIGNLEFT, + QT_LABEL_ALIGNRIGHT, + QT_LABEL_ALIGNHCENTER, + QT_LABEL_ALIGNVCENTER, + QT_LABEL_ALIGNCENTER, + QT_LABEL_ALIGNTOP, + QT_LABEL_ALIGNBOTTOM, + QT_LABEL_JUSTIFY, + }; + +#define align_num (sizeof(align_tbl) / sizeof(align_tbl[0])) + +// used in $frameStyle & $setFrameStyle +const char * const frame_tbl[] = { + "NoFrame", + "Box", + "Panel", + "WinPanel", + "Hline", + // shadow styles + "Plain", + "Raised", + "Sunken" + }; + +const int frame_cod[] = { + QFrame::NoFrame, + QFrame::Box, + QFrame::Panel, + QFrame::WinPanel, + QFrame::HLine, + QFrame::Plain, + QFrame::Raised, + QFrame::Sunken + }; + +#define frame_num (sizeof(frame_tbl) / sizeof(frame_tbl[0])) + + +/* + @doc: label + @keyterms: + label object class, show image + @title: + label class + @type: + class + @short: + Displays text or an image + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + This widget can be used to display a text or an image. It can + have different frame styles and text/image alignment. + @functions: + !fn: $setText() + Sets the text to be displayed by the label. + The text can contain limited html tags. + See also [classfnc]$text[/classfnc](). + !fn: $text() + Returns the text currently displayed by the label. + See also [classfnc]$setText[/classfnc](). + !fn: $margin() + Returns current value of margin for this label (default is 0). + See also [classfnc]$setMargin[/classfnc](). + !fn: $setMargin() + Sets margin width / height to . + See also [classfnc]$margin[/classfnc](). + !fn: $autoResize() + Returns 1, if auto-resize ability of the label is enabled. + See also [classfnc]$setAutoResize[/classfnc](). + !fn: $setAutoResize() + Sets auto-resize ability to enabled (if is 1) or disabled + (if is 0). If auto-resize is enabled, the label will + automagically resize itself accordingly to the 'size' of the + text it contains. + See also [classfnc]$autoResize[/classfnc](). + !fn: $alignment() + Returns a string containing alignment flags that are set for + this label. The flags are separated by commas. An example output + could look like this:[br] + [pre]Bottom, Right[/pre][br] + See [classfnc]$setAlignment[/classfnc]() for explanation of all + alignment flags. + !fn: $setAlignment(, , ...) + This function sets alignment flags, given as parameters, for + this label. Valid flags are: + [pre] + Right - Text is aligned to right border[br] + Left - Text is aligned to left border[br] + Top - Text is aligned to the top border[br] + Bottom - Text is aligned to the bottom border[br] + HCenter - Text is horizontally centered[br] + VCenter - Text is vertically centered[br] + Center - Equals HCenter + VCenter[br] + WordBreak - Enables automatic word breaking[br] + [/pre] + It is obvious that you can not set for example [i]Right[/i] + and [i]Left[/i] simoultaneously - this will [b]NOT[/b] + result in an error message - this will simply not work :) + !fn: $clear() + Clears the label. Equal to calling + [classfnc]$setText[/classfnc]("") + !fn: $frameStyle() + Returns a string containing this label's frame-style flags, + separated with commas. Output from this function could look like + this: + [pre]Panel, Raised[/pre] + See [classfnc]$setFrameStyle[/classfnc]() for a list of all + frame-style flags and their explenation. + !fn: $setFrameStyle(, , ...) + Sets the frame-style flags to the ones passed as arguments. + The flags can either decide of the shape or shadow of the + label's frame. Valid shape flags are:[br] + [pre] + NoFrame - draw no frame. You shouldn't specify a shadow when + using this.[br] + Box - draws a rectangular box. Its borders can be + [i]Raised[/i] or [i]Sunken[/i][br] + Panel - draws a rectangular panel which can be + [i]Raised[/i] or [i]Sunken[/i][br] + WinPanel - similar to [i]Panel[/i], but is more in Win95 + style[br] + Hline - draws a horizontal line that frames nothing (useful as separator) + [/pre] + Valid shadow flags are:[br] + [pre] + Plain - no 3D effect (draws using foreground color)[br] + Raised - makes the label look like it was raised above the + parent widget[br] + Sunken - makes the label look like it was "pushed" inside + the parent widget[br] + [/pre] + !fn: $setImage() + Sets the image to be displayed on this label. + Giving empty argument clears the pixmap[br] + See the [doc:image_id]image identifier[/doc] documentation for + the explaination of the parameter. + +*/ + + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_label,"label","widget") + KVSO_REGISTER_HANDLER(KviKvsObject_label,"setText",functionSetText) + KVSO_REGISTER_HANDLER(KviKvsObject_label,"text", functionText) + KVSO_REGISTER_HANDLER(KviKvsObject_label,"margin", functionMargin) + KVSO_REGISTER_HANDLER(KviKvsObject_label,"setMargin", functionSetMargin) + KVSO_REGISTER_HANDLER(KviKvsObject_label,"autoResize", functionAutoResize) + KVSO_REGISTER_HANDLER(KviKvsObject_label,"setAutoResize", functionSetAutoResize) + KVSO_REGISTER_HANDLER(KviKvsObject_label,"alignment", functionAlignment) + KVSO_REGISTER_HANDLER(KviKvsObject_label,"setAlignment", functionSetAlignment) + KVSO_REGISTER_HANDLER(KviKvsObject_label,"clear", functionClear) + KVSO_REGISTER_HANDLER(KviKvsObject_label,"frameStyle", functionFrameStyle) + KVSO_REGISTER_HANDLER(KviKvsObject_label,"setFrameStyle", functionSetFrameStyle) + KVSO_REGISTER_HANDLER(KviKvsObject_label,"setImage", functionSetImage) +KVSO_END_REGISTERCLASS(KviKvsObject_label) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_label,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_label) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_label) + +KVSO_END_CONSTRUCTOR(KviKvsObject_label) + +bool KviKvsObject_label::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + setObject(new QLabel(parentScriptWidget(), name()), true); + return true; +} + +bool KviKvsObject_label::functionSetText(KviKvsObjectFunctionCall *c) +{ + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QLabel *)widget())->setText(szText); + return true; +} +bool KviKvsObject_label::functionText(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setString(((QLabel *)widget())->text()); + return true; +} + +bool KviKvsObject_label::functionSetMargin(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t iMargin; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("margin",KVS_PT_UNSIGNEDINTEGER,0,iMargin) + KVSO_PARAMETERS_END(c) + if (widget()) ((QLabel *)widget())->setMargin(iMargin); + return true; +} +bool KviKvsObject_label::functionMargin(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setInteger(((QLabel *)widget())->margin()); + return true; +} + +// FIX ME +bool KviKvsObject_label::functionSetAutoResize(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + #ifdef COMPILE_USE_QT4 + return true; + #else + if(widget()) + ((QLabel *)widget())->setAutoResize(bEnabled); + return true; + #endif +} +bool KviKvsObject_label::functionAutoResize(KviKvsObjectFunctionCall *c) +{ + #ifdef COMPILE_USE_QT4 + if (widget()) c->returnValue()->setBoolean(true); + #else + if (widget()) c->returnValue()->setBoolean(((QLabel *)widget())->autoResize()); + #endif + return true; +} +// +bool KviKvsObject_label::functionSetAlignment(KviKvsObjectFunctionCall *c) +{ + QStringList alignment; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("alignment",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,alignment) + KVSO_PARAMETERS_END(c) + if (!widget()) return true; + int align,sum=0; + for ( QStringList::Iterator it = alignment.begin(); it != alignment.end(); ++it ) + { + + align = 0; + for(unsigned int j = 0; j < align_num; j++) + { + if(KviQString::equalCI((*it), align_tbl[j])) + { + align=align_cod[j]; + break; + } + } + if(align) + sum = sum | align; + else + c->warning(__tr2qs("Unknown alignment: '%Q'"),&(*it)); + + } + ((QLabel *)widget())->setAlignment(sum); + return true; +} +bool KviKvsObject_label::functionAlignment(KviKvsObjectFunctionCall *c) +{ + int mode = ((QLabel *)widget())->alignment(); + QString szAlignment=""; + for(unsigned int i = 0; i < align_num; i++) + { + if(mode == align_cod[i]) + { + szAlignment=align_tbl[i]; + break; + } + } + c->returnValue()->setString(szAlignment); + return true; +} +bool KviKvsObject_label::functionClear(KviKvsObjectFunctionCall *c) +{ + if(widget()) + ((QLabel *)widget())->clear(); + return true; +} + + +bool KviKvsObject_label::functionSetFrameStyle(KviKvsObjectFunctionCall *c) +{ + + QStringList style; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("style",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,style) + KVSO_PARAMETERS_END(c) + if (!widget()) return true; + int framestyle,sum=0; + for ( QStringList::Iterator it = style.begin(); it != style.end(); ++it ) + { + framestyle = 0; + for(unsigned int j = 0; j < align_num; j++) + { + if(KviQString::equalCI((*it), frame_tbl[j])) + { + framestyle=frame_cod[j]; + break; + } + } + if(framestyle) + sum = sum | framestyle; + else + c->warning(__tr2qs("Unknown style: '%Q'"),&(*it)); + + } + ((QLabel *)widget())->setFrameStyle(sum); + return true; + + + + +} +bool KviKvsObject_label::functionFrameStyle(KviKvsObjectFunctionCall *c) +{ + int mode = ((QLabel *)widget())->frameStyle(); + QString szStyle=""; + for(unsigned int i = 0; i < frame_num; i++) + { + if(mode == frame_cod[i]) + { + szStyle=frame_tbl[i]; + break; + } + } + c->returnValue()->setString(szStyle); + return true; +} +bool KviKvsObject_label::functionSetImage(KviKvsObjectFunctionCall *c) +{ + + QString icon; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("icon",KVS_PT_STRING,0,icon) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + QPixmap * pix = g_pIconManager->getImage(icon); + if(pix) ((QLabel *)widget())->setPixmap(*pix); + return true; +} diff --git a/src/modules/objects/class_label.h b/src/modules/objects/class_label.h new file mode 100644 index 00000000..38fa58a3 --- /dev/null +++ b/src/modules/objects/class_label.h @@ -0,0 +1,54 @@ +#ifndef _CLASS_LABEL_H_ +#define _CLASS_LABEL_H_ +//vim: ts=8 +// File : class_label.h +// Creation date : Mon Sep 18 14:21:48 CEST 2000 by Krzysztof Godlewski +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 +#include "class_widget.h" +#include "object_macros.h" + +class KviKvsObject_label : public KviKvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KviKvsObject_label) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool functionSetTitle(KviKvsObjectFunctionCall *c); + bool functionSetText(KviKvsObjectFunctionCall *c); + bool functionText(KviKvsObjectFunctionCall *c); + bool functionMargin(KviKvsObjectFunctionCall *c); + bool functionSetMargin(KviKvsObjectFunctionCall *c); + bool functionAutoResize(KviKvsObjectFunctionCall *c); + bool functionSetAutoResize(KviKvsObjectFunctionCall *c); + bool functionAlignment(KviKvsObjectFunctionCall *c); + bool functionSetAlignment(KviKvsObjectFunctionCall *c); + bool functionClear(KviKvsObjectFunctionCall *c); + bool functionFrameStyle(KviKvsObjectFunctionCall *c); + bool functionSetFrameStyle(KviKvsObjectFunctionCall *c); + bool functionSetImage(KviKvsObjectFunctionCall *c); +}; +#endif // !_CLASS_LABEL_H_ diff --git a/src/modules/objects/class_layout.cpp b/src/modules/objects/class_layout.cpp new file mode 100644 index 00000000..900b9856 --- /dev/null +++ b/src/modules/objects/class_layout.cpp @@ -0,0 +1,274 @@ +// +// File : class_layout.cpp +// Creation date : Fri Now 22 2002 00:50:01 by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2002 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. +// +#define _KVI_DEBUG_CHECK_RANGE_ +#include "kvi_debug.h" + +#include "kvi_locale.h" + +#include "class_layout.h" + +#ifdef COMPILE_USE_QT4 +#define QLAYOUT_AUTO_CONSTRAINT QLayout::SetDefaultConstraint +#define QLAYOUT_FIXED QLayout::SetFixedSize +#define QLAYOUT_FREE_RESIZE QLayout::SetNoConstraint +#define QLAYOUT_MINIMUM QLayout::SetMinimumSize +#else +#define QLAYOUT_AUTO_CONSTRAINT QLayout::Auto +#define QLAYOUT_FIXED QLayout::Fixed +#define QLAYOUT_FREE_RESIZE QLayout::FreeResize +#define QLAYOUT_MINIMUM QLayout::Minimum +#endif + + +/* + @doc: layout + @keyterms: + layout object class, child widgets + @title: + layout class + @type: + class + @short: + Manages child widget geometry + @inherits: + [class]object[/class] + @description: + The layout is a geometry management tool for child widgets. + You create a layout , give it some widgets to manage and it will layout them + automatically.[br] + The parent of the layout must be the widget for which child widget geometries have to be managed. + A layout is a grid of NxM cells in which you insert child widgets with [classfnc:layout]$addWidget[/classfnc]().[br] + Widgets that must span multiple cells can be added to the layout with [classfnc:layout]$addMultiCellWidget[/classfnc]().[br] + @functions: + !fn: $addWidget(,,) + Adds a widget to this layout placing it at position , in the grid + !fn: $addMultiCellWidget(,,,,) + Adds a widget to this layout spanning multiple grid cells + !fn: $setRowStretch(,) + Sets the stretch value for a particular row of this layout. The + must be a positive integer. The rows with bigger stretch values will take more space + in the layout. + !fn: $setColStretch(,) + Sets the stretch value for a particular column in this layout. The + must be a positive integer. The rows with bigger stretch values will take more space + in the layout. + !fn: $addRowSpacing(,) + Sets the minimum height of the specified to which must be a positive integer + !fn: $addColSpacing(,) + Sets the minimum width of the specigfied to which must be a positive integer + !fn: $setSpacing() + Sets the default spacing of the widgets in pixels + !fn: $setMargin() + Sets the dimension of the layout margin : the distance from the border to the outermost child widget edges. + !fn: $setResizeMode() + Sets the resize mode of the parent widget in relation to this layout. + can be one of:[br] + -Auto: this is the default[br] + -Fixed: the parent widget of this layout is resized to the "sizeHint" value and it cannot be resized by the user.[br] + -Minimum: the minimum size of the parent widget of this layout is set to minimumSize() and it cannot be smaller[br] + -FreeResize: the parent widget of this layout is not constrained at all[br] +*/ + + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_layout,"layout","object") + KVSO_REGISTER_HANDLER(KviKvsObject_layout,"addWidget", functionAddWidget) + KVSO_REGISTER_HANDLER(KviKvsObject_layout,"addMultiCellWidget", functionAddMultiCellWidget) + KVSO_REGISTER_HANDLER(KviKvsObject_layout,"setRowStretch", functionSetRowStretch) + KVSO_REGISTER_HANDLER(KviKvsObject_layout,"setColStretch", functionSetColStretch) + KVSO_REGISTER_HANDLER(KviKvsObject_layout,"addRowSpacing", functionAddRowSpacing) + KVSO_REGISTER_HANDLER(KviKvsObject_layout,"addColSpacing", functionAddColSpacing) + KVSO_REGISTER_HANDLER(KviKvsObject_layout,"setMargin", functionSetMargin) + KVSO_REGISTER_HANDLER(KviKvsObject_layout,"setSpacing", functionSetSpacing) + KVSO_REGISTER_HANDLER(KviKvsObject_layout,"setResizeMode", functionSetResizeMode) +KVSO_END_REGISTERCLASS(KviKvsObject_layout) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_layout,KviKvsObject) + +KVSO_END_CONSTRUCTOR(KviKvsObject_layout) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_layout) + +KVSO_END_CONSTRUCTOR(KviKvsObject_layout) + +bool KviKvsObject_layout::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + QWidget * w = parentScriptWidget(); + + if(!w) + { + pContext->warning(__tr2qs("The parent of a layout must be a widget!")); + return false; + } + setObject(new QGridLayout(w)); + return true; +} + +bool KviKvsObject_layout::functionAddWidget(KviKvsObjectFunctionCall *c) +{ + KviKvsObject * pObject; + kvs_hobject_t hObject; + kvs_uint_t uCol,uRow; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow) + KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if(!widget())return true; + if (!pObject) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!pObject->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!pObject->object()->isWidgetType()) + { + c->warning(__tr2qs("Can't add a non-widget object")); + return true; + } + ((QGridLayout *)object())->addWidget(((QWidget *)(pObject->object())),uRow,uCol); + return true; +} +bool KviKvsObject_layout::functionAddMultiCellWidget(KviKvsObjectFunctionCall *c) +{ + KviKvsObject * pObject; + kvs_hobject_t hObject; + kvs_uint_t uStartCol,uStartRow,uEndCol,uEndRow; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("start_row",KVS_PT_UNSIGNEDINTEGER,0,uStartRow) + KVSO_PARAMETER("end_row",KVS_PT_UNSIGNEDINTEGER,0,uEndRow) + KVSO_PARAMETER("start_column",KVS_PT_UNSIGNEDINTEGER,0,uStartCol) + KVSO_PARAMETER("end_column",KVS_PT_UNSIGNEDINTEGER,0,uEndCol) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if(!widget())return true; + if (!pObject) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!pObject->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!pObject->object()->isWidgetType()) + { + c->warning(__tr2qs("Can't add a non-widget object")); + return true; + } + ((QGridLayout *)object())->addMultiCellWidget(((QWidget *)(pObject->object())),uStartRow,uEndRow,uStartCol,uEndCol); + return true; +} +bool KviKvsObject_layout::functionSetRowStretch(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uRow,uStretch; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow) + KVSO_PARAMETER("stretch",KVS_PT_UNSIGNEDINTEGER,0,uStretch) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + ((QGridLayout *)object())->setRowStretch(uRow,uStretch); + return true; +} +bool KviKvsObject_layout::functionSetColStretch(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uCol,uStretch; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("stretch",KVS_PT_UNSIGNEDINTEGER,0,uStretch) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + ((QGridLayout *)object())->setColStretch(uCol,uStretch); + return true; +} + +bool KviKvsObject_layout::functionSetMargin(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uMargin; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("margin",KVS_PT_UNSIGNEDINTEGER,0,uMargin) + KVSO_PARAMETERS_END(c) + if (widget()) ((QGridLayout *)object())->setMargin(uMargin); + return true; +} + +bool KviKvsObject_layout::functionSetSpacing(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uSpacing; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("spacing",KVS_PT_UNSIGNEDINTEGER,0,uSpacing) + KVSO_PARAMETERS_END(c) + if (widget()) ((QGridLayout *)object())->setSpacing(uSpacing); + return true; +} + + +bool KviKvsObject_layout::functionAddRowSpacing(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uSpacing,uRow; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow) + KVSO_PARAMETER("spacing",KVS_PT_UNSIGNEDINTEGER,0,uSpacing) + KVSO_PARAMETERS_END(c) + if (widget()) ((QGridLayout *)object())->addRowSpacing(uRow,uSpacing); + return true; +} + +bool KviKvsObject_layout::functionAddColSpacing(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uSpacing,uCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("spacing",KVS_PT_UNSIGNEDINTEGER,0,uSpacing) + KVSO_PARAMETERS_END(c) + if (widget()) ((QGridLayout *)object())->addColSpacing(uCol,uSpacing); + return true; +} + +bool KviKvsObject_layout::functionSetResizeMode(KviKvsObjectFunctionCall *c) +{ + QString szMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("resize_mode",KVS_PT_STRING,0,szMode) + KVSO_PARAMETERS_END(c) + if(!widget())return true; +#ifdef COMPILE_USE_QT4 + QLayout::SizeConstraint r = QLAYOUT_AUTO_CONSTRAINT; +#else + QLayout::ResizeMode r = QLAYOUT_AUTO_CONSTRAINT; +#endif + if(KviQString::equalCI(szMode,"FreeResize")) r = QLAYOUT_FREE_RESIZE; + else if(KviQString::equalCI(szMode,"Minimum")) r = QLAYOUT_MINIMUM; + else if(KviQString::equalCI(szMode,"Fixed"))r = QLAYOUT_FIXED; + else c->warning(__tr2qs("Invalid resize mode defaulting to Auto")); + ((QGridLayout *)object())->setResizeMode(r); + return true; + +} + diff --git a/src/modules/objects/class_layout.h b/src/modules/objects/class_layout.h new file mode 100644 index 00000000..e821316a --- /dev/null +++ b/src/modules/objects/class_layout.h @@ -0,0 +1,52 @@ +#ifndef _CLASS_LAYOUT_H_ +#define _CLASS_LAYOUT_H_ +// +// File : class_layout.h +// Creation date : Fri Now 22 2002 00:50:01 by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2002 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 "kvi_string.h" + +#include +#include "object_macros.h" + +class KviKvsObject_layout : public KviKvsObject +{ +public: + KVSO_DECLARE_OBJECT(KviKvsObject_layout) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool functionAddWidget(KviKvsObjectFunctionCall *c); + bool functionAddMultiCellWidget(KviKvsObjectFunctionCall *c); + bool functionSetRowStretch(KviKvsObjectFunctionCall *c); + bool functionSetColStretch(KviKvsObjectFunctionCall *c); + bool functionSetMargin(KviKvsObjectFunctionCall *c); + bool functionSetSpacing(KviKvsObjectFunctionCall *c); + bool functionAddRowSpacing(KviKvsObjectFunctionCall *c); + bool functionAddColSpacing(KviKvsObjectFunctionCall *c); + bool functionSetResizeMode(KviKvsObjectFunctionCall *c); + + +}; + + +#endif //_CLASS_LAYOUT_H_ diff --git a/src/modules/objects/class_lcd.cpp b/src/modules/objects/class_lcd.cpp new file mode 100644 index 00000000..0f0ba49a --- /dev/null +++ b/src/modules/objects/class_lcd.cpp @@ -0,0 +1,180 @@ +// +// File : class_lcd.cpp +// Creation date : Mon Gen 27 14:30:48 CEST 2005 by Tonino Imbesi(Grifisx) +// and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 "class_lcd.h" +#include "kvi_error.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_iconmanager.h" + +/* + @doc: lcdnumber + @keyterms: + lcdnumber object class, lcd + @title: + lcdnumber class + @type: + class + @short: + The lcdNumber widget displays a number with LCD-like digits. + @inherits: + + @description: + It can display a number in just about any size. It can display decimal, + hexadecimal, octal or binary numbers. + @functions: + !fn: $setDisplayStr() + Displays the number represented by the string s. + !fn: $setDisplayInt() + Sets the displayed value rounded to the nearest integer to number. + !fn: $setDisplayDouble() + Sets the displayed value to number (double). + !fn: $setMode() + Sets the current display mode (number base): valid mode are HEX,BIN,OCT,DEC. + !fn: $setSegmentStyles() + Sets the style of the lcdnumber, valid styles are: Outline,Filled,Flat. + !fn: $setNumDigits() + Sets the lcd number value. + !fn: $checkOverflow() + Returns TRUE if num is too big to be displayed in its entirety; + otherwise returns FALSE. + !fn: $setSmallDecimalPoint() + Sets the the decimal point style, valid bool values are 1 or 0. + !fn: $checkOverflow() + Returns 1 (TRUE) if num is too big to be displayed in its entirety; otherwise returns 0 (FALSE). +*/ + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_lcd,"lcdnumber","widget") + + KVSO_REGISTER_HANDLER(KviKvsObject_lcd,"setDisplayStr", functiondisplayStr) + KVSO_REGISTER_HANDLER(KviKvsObject_lcd,"setDisplayInt", functiondisplayInt) + KVSO_REGISTER_HANDLER(KviKvsObject_lcd,"setDisplayDouble", functiondisplayDouble) + KVSO_REGISTER_HANDLER(KviKvsObject_lcd,"setMode", functionsetMode) + KVSO_REGISTER_HANDLER(KviKvsObject_lcd,"setSegmentStyle", functionsetSegmentStyle) + KVSO_REGISTER_HANDLER(KviKvsObject_lcd,"setNumDigits", functionsetNumDigits) + KVSO_REGISTER_HANDLER(KviKvsObject_lcd,"setSmallDecimalPoint",functionsetSmallDecimalPoint) + KVSO_REGISTER_HANDLER(KviKvsObject_lcd,"checkOverflow", functioncheckOverflow) +KVSO_END_REGISTERCLASS(KviKvsObject_lcd) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_lcd,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_lcd) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_lcd) + +KVSO_END_CONSTRUCTOR(KviKvsObject_lcd) + +bool KviKvsObject_lcd::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + setObject(new QLCDNumber(parentScriptWidget(), name()), true); + return true; +} + +bool KviKvsObject_lcd::functiondisplayInt(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iDigit; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("number",KVS_PT_INT,0,iDigit) + KVSO_PARAMETERS_END(c) + if(widget())((QLCDNumber *)widget())->display((int)iDigit); + return true; +} + +bool KviKvsObject_lcd::functiondisplayStr(KviKvsObjectFunctionCall *c) +{ + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("number",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if(widget()) ((QLCDNumber *)widget())->display(szText); + return true; +} + +bool KviKvsObject_lcd::functiondisplayDouble(KviKvsObjectFunctionCall *c) +{ + kvs_real_t dDigit; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("number",KVS_PT_DOUBLE,0,dDigit) + KVSO_PARAMETERS_END(c) + if(widget()) ((QLCDNumber *)widget())->display(dDigit); + return true; +} +bool KviKvsObject_lcd::functionsetMode(KviKvsObjectFunctionCall *c) +{ + QString szMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("mode",KVS_PT_STRING,0,szMode) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + if(KviQString::equalCI(szMode, "HEX")) ((QLCDNumber *)widget())->setHexMode(); + else if(KviQString::equalCI(szMode, "DEC")) ((QLCDNumber *)widget())->setDecMode(); + else if(KviQString::equalCI(szMode, "BIN")) ((QLCDNumber *)widget())->setBinMode(); + else if(KviQString::equalCI(szMode, "OCT")) ((QLCDNumber *)widget())->setOctMode(); + else c->warning( __tr2qs("Unknown mode ")); + return true; +} +bool KviKvsObject_lcd::functionsetSegmentStyle(KviKvsObjectFunctionCall *c) +{ + QString szStyle; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("style",KVS_PT_STRING,0,szStyle) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + if(KviQString::equalCI(szStyle, "Outline")) ((QLCDNumber *)widget())->setSegmentStyle(QLCDNumber::Outline); + else if(KviQString::equalCI(szStyle, "Filled")) ((QLCDNumber *)widget())->setSegmentStyle(QLCDNumber::Filled); + else if(KviQString::equalCI(szStyle, "Flat")) ((QLCDNumber *)widget())->setSegmentStyle(QLCDNumber::Flat); + else c->warning( __tr2qs("Unknown segment style ")); + return true; +} +bool KviKvsObject_lcd::functionsetNumDigits(KviKvsObjectFunctionCall *c) +{ + kvs_real_t digit; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("digit",KVS_PT_DOUBLE,0,digit) + KVSO_PARAMETERS_END(c) + if(widget()) ((QLCDNumber *)widget())->setNumDigits(digit); + return true; +} +bool KviKvsObject_lcd::functionsetSmallDecimalPoint(KviKvsObjectFunctionCall *c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bflag",KVS_PT_BOOLEAN,0,bFlag) + KVSO_PARAMETERS_END(c) + if(widget()) ((QLCDNumber *)widget())->setSmallDecimalPoint(bFlag); + return true; +} +bool KviKvsObject_lcd::functioncheckOverflow(KviKvsObjectFunctionCall *c) +{ + kvs_real_t iDigit; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("digit",KVS_PT_DOUBLE,0,iDigit) + KVSO_PARAMETERS_END(c) + if(widget())c->returnValue()->setBoolean(((QLCDNumber *)widget())->checkOverflow(iDigit)); + return true; +} + + diff --git a/src/modules/objects/class_lcd.h b/src/modules/objects/class_lcd.h new file mode 100644 index 00000000..4976850a --- /dev/null +++ b/src/modules/objects/class_lcd.h @@ -0,0 +1,51 @@ +#ifndef _CLASS_LCD_H_ +#define _CLASS_LCD_H_ + +// File : class_lcd.h +// Creation date : Mon Gen 27 14:30:48 CEST 2005 by Tonino Imbesi(Grifisx) +// and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 +#include "class_widget.h" + + +class KviKvsObject_lcd : public KviKvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KviKvsObject_lcd) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool functiondisplayStr(KviKvsObjectFunctionCall *c); + bool functionsetMode(KviKvsObjectFunctionCall *c); + bool functionsetSegmentStyle(KviKvsObjectFunctionCall *c); + bool functionsetNumDigits(KviKvsObjectFunctionCall *c); + bool functionsetSmallDecimalPoint(KviKvsObjectFunctionCall *c); + bool functioncheckOverflow(KviKvsObjectFunctionCall *c); + bool functiondisplayInt(KviKvsObjectFunctionCall *c); + bool functiondisplayDouble(KviKvsObjectFunctionCall *c); +}; + +#endif // !_CLASS_LCD_H_ diff --git a/src/modules/objects/class_lineedit.cpp b/src/modules/objects/class_lineedit.cpp new file mode 100644 index 00000000..c8ba58ff --- /dev/null +++ b/src/modules/objects/class_lineedit.cpp @@ -0,0 +1,461 @@ +//vim: ts=8 +// File : class_lineedit.cpp +// Creation date : Wed 20 Sep 2000 04:34:40 CEST by Krzysztof Godlewski +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 "kvi_error.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" + +#include "class_lineedit.h" + +static const char * mode_tbl[] = { + "Normal", + "NoEcho", + "Password" + }; + +static const int mode_cod[] = { + QLineEdit::Normal, + QLineEdit::NoEcho, + QLineEdit::Password + }; + +#define mode_num (sizeof(mode_tbl) / sizeof(mode_tbl[0])) + + +/* + @doc: lineedit + @keyterms: + lineedit object class, line editor, input + @title: + lineedit class + @type: + class + @short: + Simple line editor for inputting short text + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + This is a simple, one-line editor usually used for inputting + short text like names, phone numbers etc. It can display text + in three echo modes (see [classfnc]$setEchoMode[/classfnc]() + for details). + @functions: + !fn: $text() + Returns text contained by the widget.[br] + See also [classfnc]$setText[/classfnc](). + !fn: $setText() + Sets editor text to .[br] + See also [classfnc]$text[/classfnc](). + !fn: $setEchoMode() + Sets the line edit's echo mode. Possible value are:[br] + -Normal: display chars as they entered[br] + -Noecho : do not display anything[br] + -Password : display asterisks instead of the characters actually entered[br] + See also [classfnc]$echoMode[/classfnc](). + !fn: $echoMode() + Return the line edit's echo mode. + See also [classfnc]$setEchoMode[/classfnc](). + !fn: $maxLength() + Returns the current maximum length of the text that can be typed + in the editor.[br] + See also [classfnc]$setMaxLength[/classfnc](). + !fn: $setMaxLength() + Sets maximum length of the text that can be typed in the + editor.[br] + See also [classfnc]$maxLength[/classfnc](). + !fn: $frame() + Returns '1' if the editor is drawn inside a frame, which is 2 + pixels wide, '0' otherwise.[br] + See also [classfnc]$setFrame[/classfnc](). + !fn: $setFrame() + Sets editor frame drawing to .[br] + See also [classfnc]$frame[/classfnc](). + !fn: $cursorPosition() + Returns current cursor position in the editor.[br] + See also [classfnc]$setCursorPosition[/classfnc](). + !fn: $setCursorPosition() + Moves the cursor to place pointed by .[br] + See also [classfnc]$cursorPosition[/classfnc](). + !fn: $selectAll() + Selects whole text inside the editor.[br] + See also [classfnc]$setSelection[/classfnc](), + [classfnc]$cut[/classfnc](), [classfnc]$copy[/classfnc](), + [classfnc]$paste[/classfnc](). + !fn: $setSelection(, ) + Selects characters in the editor starting at position + .[br] + See also [classfnc]$selectAll[/classfnc](), + [classfnc]$cut[/classfnc](), [classfnc]$copy[/classfnc](), + [classfnc]$paste[/classfnc](). + !fn: $copy() + Copies selected text in the editor to the clipboard.[br] + See also [classfnc]$setSelection[/classfnc](), + [classfnc]$cut[/classfnc](), [classfnc]$paste[/classfnc](). + !fn: $cut() + Cuts selected text from the editor to the clipboard.[br] + See also [classfnc]$setSelection[/classfnc](), + [classfnc]$copy[/classfnc](), [classfnc]$paste[/classfnc](). + !fn: $paste() + Pastes text from the clipboard into the editor. The pasted text + will start at cursor position.[br] + See also [classfnc]$setSelection[/classfnc](), + [classfnc]$copy[/classfnc](), [classfnc]$cut[/classfnc](). + !fn: $clear() + Deletes all text from the editor. Equal to calling [classfnc]$setText[/classfnc](""). + !fn: $setDragEnabled() + With this property user can drag text in the lineedit. + !fn: $setReadOnly() + Sets the lineedit to read only mode. + !fn: $setInputMask() + Sets the validation input mask to inputMask.[br] + Example:[br] + [br] + %esempio->$setInputMask( "+99 99 99 99 99;_" );[br] + %esempio->$setInputMask( "000.000.000.000;_" );[br] + %esempio->Ip Number Mask.[br] + %esempio->setInputMask( ">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#" );[br] + [br] + The mask format understands these mask characters:[br] + Character Meaning[br] + A ASCII alphabetic character required. A-Z, a-z.[br] + a ASCII alphabetic character permitted but not required.[br] + N ASCII alphanumeric character required. A-Z, a-z, 0-9.[br] + n ASCII alphanumeric character permitted but not required.[br] + X Any character required.[br] + x Any character permitted but not required.[br] + 9 ASCII digit required. 0-9.[br] + 0 ASCII digit permitted but not required.[br] + D ASCII digit required. 1-9.[br] + d ASCII digit permitted but not required.[br] + # ASCII digit or plus/minus sign permitted but not required.[br] + > All following alphabetic characters are uppercased.[br] + < All following alphabetic characters are lowercased.[br] + ! Switch off case conversion.[br] + \ Use \ to escape the special characters listed above to use them as separators.[br] + [br] + The mask consists of a string of mask characters and separators, optionally[br] + followed by a semi-colon and the character used for blanks: the blank characters [br] + are always removed from the text after editing. The default blank character is space. [br] + !fn: $returnPressedEvent() + This function is called by the framework when the enter key is pressed. + !fn: $lostFocusEvent() + Called when the lineedit lost focus. + !fn: $textChangedEvent() + This event is called when the text changed, In $0 there is the new text. + @signals: + !sg: $returnPressed() + This signal is emitted by the default implementation of [classfnc]$returnPressedEvent[/classfnc](). + !sg: $lostFocus() + This signal is emitted by the default implementation of [classfnc]$lostFocusEvent[/classfnc](). + !sg: $textChanged() + This signal is emitted by the default implementation of [classfnc]$textChangedEvent[/classfnc](). + +*/ + + + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_lineedit,"lineedit","widget") + + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"text", functionText) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setText", functionSetText) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"maxLength", functionMaxLength) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setMaxLength", functionSetMaxLength) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"frame", functionFrame) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setCursorPosition", functionSetCursorPosition) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"cursorPosition", functionCursorPosition) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setFrame", functionSetFrame) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"selectAll" , functionSelectAll) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setSelection", functionSetSelection) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"copy", functionCopy) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"cut", functionCut) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"paste", functionPaste) + + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"echoMode", functionEchoMode) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setEchoMode", functionSetEchoMode) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"clear", functionClear) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setDragEnabled", functionDragAndDrop) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setInputMask", functionSetInputMask) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"setReadOnly", functionSetReadOnly) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"returnPressedEvent", functionreturnPressedEvent) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"lostFocusEvent", functionlostFocusEvent) + KVSO_REGISTER_HANDLER(KviKvsObject_lineedit,"textChangedEvent", functiontextChangedEvent) + + +KVSO_END_REGISTERCLASS(KviKvsObject_lineedit) + + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_lineedit,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_lineedit) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_lineedit) + +KVSO_END_CONSTRUCTOR(KviKvsObject_lineedit) + + +bool KviKvsObject_lineedit::init(KviKvsRunTimeContext * pContext,KviKvsVariantList * pParams) +{ + setObject(new QLineEdit(parentScriptWidget(),getName()),true); + connect(widget(),SIGNAL(returnPressed()),this,SLOT(slotreturnPressed())); + connect(widget(),SIGNAL(lostFocus()),this,SLOT(slotlostFocus())); + connect(widget(),SIGNAL(textChanged(const QString & )),this,SLOT(slottextChanged(const QString & ))); + return true; +} + +bool KviKvsObject_lineedit::functionText(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setString(((QLineEdit *)widget())->text()); + return true; +} + +bool KviKvsObject_lineedit::functionSetText(KviKvsObjectFunctionCall *c) +{ + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QLineEdit *)widget())->setText(szText); + return true; +} + +bool KviKvsObject_lineedit::functionMaxLength(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setInteger(((QLineEdit *)widget())->maxLength()); + return true; +} + +bool KviKvsObject_lineedit::functionSetMaxLength(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t iMaxlen; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("maxlen",KVS_PT_UNSIGNEDINTEGER,0,iMaxlen) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QLineEdit *)widget())->setMaxLength(iMaxlen); + return true; +} + +bool KviKvsObject_lineedit::functionFrame(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setBoolean(((QLineEdit *)widget())->frame()); + return true; +} + +bool KviKvsObject_lineedit::functionSetFrame(KviKvsObjectFunctionCall *c) +{ + bool bFrame; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bframe",KVS_PT_BOOL,0,bFrame) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QLineEdit *)widget())->setFrame(bFrame); + return true; +} + +bool KviKvsObject_lineedit::functionCursorPosition(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setInteger(((QLineEdit *)widget())->cursorPosition()); + return true; +} + +bool KviKvsObject_lineedit::functionSetCursorPosition(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t iPos; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("position",KVS_PT_UNSIGNEDINTEGER,0,iPos) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QLineEdit *)widget())->setCursorPosition(iPos); + return true; +} + +bool KviKvsObject_lineedit::functionSelectAll(KviKvsObjectFunctionCall *c) +{ + if(widget()) + ((QLineEdit *)widget())->selectAll(); + return true; +} + +bool KviKvsObject_lineedit::functionSetSelection(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uStart,uLen; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("start",KVS_PT_UNSIGNEDINTEGER,0,uStart) + KVSO_PARAMETER("len",KVS_PT_UNSIGNEDINTEGER,0,uLen) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QLineEdit *)widget())->setSelection(uStart, uLen); + return true; +} + +bool KviKvsObject_lineedit::functionCopy(KviKvsObjectFunctionCall *c) +{ + if(widget()) + ((QLineEdit *)widget())->copy(); + return true; +} + +bool KviKvsObject_lineedit::functionCut(KviKvsObjectFunctionCall *c) +{ + if(widget()) + ((QLineEdit *)widget())->cut(); + return true; +} + +bool KviKvsObject_lineedit::functionPaste(KviKvsObjectFunctionCall *c) +{ + if(widget()) + ((QLineEdit *)widget())->paste(); + return true; +} + +bool KviKvsObject_lineedit::functionEchoMode(KviKvsObjectFunctionCall *c) +{ + int mode = ((QLineEdit *)widget())->echoMode(); + QString szEchomode=""; + for(unsigned int i = 0; i < mode_num; i++) + { + if(mode == mode_cod[i]) + { + szEchomode=mode_tbl[i]; + break; + } + } + c->returnValue()->setString(szEchomode); + return true; +} + +bool KviKvsObject_lineedit::functionSetEchoMode(KviKvsObjectFunctionCall *c) +{ + QString szMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("mode",KVS_PT_STRING,0,szMode) + KVSO_PARAMETERS_END(c) + if (!widget()) return true; + for(unsigned int i = 0; i < mode_num; i++) + { + if(KviQString::equalCI(szMode, mode_tbl[i])) + { + ((QLineEdit *)widget())->setEchoMode( \ + ((QLineEdit::EchoMode)mode_cod[i])); + return true; + } + } + c->warning(__tr2qs("Unknown echo mode %Q"),&szMode); + return true; +} + +bool KviKvsObject_lineedit::functionClear(KviKvsObjectFunctionCall *c) +{ + if(widget()) + ((QLineEdit *)widget())->clear(); + return true; +} + +//-| Grifisx & Noldor |-Start: +bool KviKvsObject_lineedit::functionDragAndDrop(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QLineEdit *)widget())->setDragEnabled(bEnabled); + return true; +} + +bool KviKvsObject_lineedit::functionSetReadOnly(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bReadonly",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QLineEdit *)widget())->setReadOnly(bEnabled); + return true; +} + +bool KviKvsObject_lineedit::functionSetInputMask(KviKvsObjectFunctionCall *c) +{ + QString szMask; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("mask",KVS_PT_STRING,0,szMask) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QLineEdit *)widget())->setInputMask(szMask); + return true; +} + +bool KviKvsObject_lineedit::functionreturnPressedEvent(KviKvsObjectFunctionCall *c) +{ + + emitSignal("returnPressed",c); + return true; + +} + +void KviKvsObject_lineedit::slotreturnPressed() +{ + KviKvsVariantList * params = 0; + callFunction(this,"returnPressedEvent",params); + +} +// FIND ME +bool KviKvsObject_lineedit::functionlostFocusEvent(KviKvsObjectFunctionCall *c) +{ + + + emitSignal("lostFocus",c); + return true; + +} + +void KviKvsObject_lineedit::slotlostFocus() +{ + KviKvsVariantList * params = 0; + callFunction(this,"lostFocusEvent",params); +} +///// +bool KviKvsObject_lineedit::functiontextChangedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("textChanged",c,c->params()); + return true; + +} + +void KviKvsObject_lineedit::slottextChanged(const QString &text) +{ + KviKvsVariantList params(new KviKvsVariant(text)); + callFunction(this,"textChangedEvent",¶ms); +} + + +#include "m_class_lineedit.moc" diff --git a/src/modules/objects/class_lineedit.h b/src/modules/objects/class_lineedit.h new file mode 100644 index 00000000..d7036824 --- /dev/null +++ b/src/modules/objects/class_lineedit.h @@ -0,0 +1,81 @@ +#ifndef _CLASS_LINEEDIT_H_ +#define _CLASS_LINEEDIT_H_ +//vim: ts=8 +// File : class_lineedit.h +// Creation date : Wed 20 Sep 2000 04:34:22 CEST by Krzysztof Godlewski +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 +#include "class_widget.h" + +//#warning "Signals !" + +#include "object_macros.h" + +class KviKvsObject_lineedit : public KviKvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_lineedit) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + + + bool functionText(KviKvsObjectFunctionCall *c); + bool functionSetText(KviKvsObjectFunctionCall *c); + bool functionMaxLength(KviKvsObjectFunctionCall *c); + bool functionSetMaxLength(KviKvsObjectFunctionCall *c); + bool functionFrame(KviKvsObjectFunctionCall *c); + bool functionSetCursorPosition(KviKvsObjectFunctionCall *c); + bool functionCursorPosition(KviKvsObjectFunctionCall *c); + bool functionSetFrame(KviKvsObjectFunctionCall *c); + bool functionSelectAll(KviKvsObjectFunctionCall *c); + bool functionSetSelection(KviKvsObjectFunctionCall *c); + bool functionCopy(KviKvsObjectFunctionCall *c); + bool functionCut(KviKvsObjectFunctionCall *c); + + bool functionPaste(KviKvsObjectFunctionCall *c); + bool functionEchoMode(KviKvsObjectFunctionCall *c); + bool functionSetEchoMode(KviKvsObjectFunctionCall *c); + bool functionClear(KviKvsObjectFunctionCall *c); + bool functionDragAndDrop(KviKvsObjectFunctionCall *c); + bool functionSetInputMask(KviKvsObjectFunctionCall *c); + bool functionSetReadOnly(KviKvsObjectFunctionCall *c); + + bool functionreturnPressedEvent(KviKvsObjectFunctionCall *c); + + bool functionlostFocusEvent(KviKvsObjectFunctionCall *c); + + bool functiontextChangedEvent(KviKvsObjectFunctionCall *c); + +protected slots: + void slotreturnPressed(); + void slotlostFocus(); + void slottextChanged(const QString &); + +}; + + +#endif // ! _CLASS_LINEEDIT_H_ diff --git a/src/modules/objects/class_list.cpp b/src/modules/objects/class_list.cpp new file mode 100644 index 00000000..2d6c9e84 --- /dev/null +++ b/src/modules/objects/class_list.cpp @@ -0,0 +1,392 @@ +//============================================================================= +// +// File : class_list.cpp +// Creation date : Wed Sep 09 2000 21:07:55 by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 "kvi_debug.h" + +#include "kvi_malloc.h" +#include "kvi_locale.h" + +#include "class_list.h" + +#include + + +/* + @doc: list + @keyterms: + list object class, sorted list + @title: + list class + @type: + class + @short: + Abstracts a double linked list of strings + @inherits: + [class]object[/class] + @description: + + + This object class abstracts a double linked list of strings. + You can insert/remove items by zero based position, at the end (tail) or at the + beginning (head). The list incorporates an efficient iteration + method by using the [classfnc:list]$moveFirst[/classfnc](),[classfnc:list]$moveLast[/classfnc](), + [classfnc:list]$moveNext[/classfnc](),[classfnc:list]$movePrev[/classfnc](), + [classfnc:list]$current[/classfnc]() and [classfnc:list]$eof[/classfnc]() functions. + @functions: + !fn: $count() + Returns the number of items in the list + + !fn: $isEmpty() + Returns $true if the list is empty, $false otherwise. + + !fn: $clear() + Removes all the items from the list.This is the same as + [classfnc:list]$removeAll[/classfnc](). + + !fn: $removeAll() + Removes all the items from the list. This is the same as + [classfnc:list]$clear[/classfnc](). + + !fn: $append() + Inserts the at the end (tail) of the list. + + !fn: $prepend() + Inserts the at the beginning (head) of the list. + + !fn: $insert(,) + Inserts the at zero-based position in the list. + If is greater or equal to [classfnc:list]$count[/classfnc]() + then the item is simply appended to the end of the list. + + !fn: $add(,) + This is exactly the same as [classfnc:list]$insert[/classfnc](). + + !fn: $item() + Returns the item at zero-based . If is greater + or equal to [classfnc:list]$count[/classfnc]() (beyond the end of the list) + then [fnc]$nothing[/fnc] is returned. + + !fn: $remove() + Removes the item at zero-based . Returns $true + if the item was succesfully removed and $false otherwise (i.e. + pointed beyond the end of the list). + + !fn: $removeFirst() + Removes the first item from the list. Returns $true + if the item was succesfully removed (the list was not empty) + and $false otherwise. + + !fn: $removeLast() + Removes the last item from the list. Returns $true + if the item was succesfully removed (the list was not empty) + and $false otherwise. + + !fn: $removeCurrent() + Removes the current item from the list. Returns $true + if the item was succesfully removed or $false otherwise. + Invalidates any iteration operation. + + !fn: $moveFirst() + Moves the iterator to the first item in the list and returns + $true if the move was succesfull (i.e., the list is not empty) + and $false otherwise. + + !fn: $moveLast() + Moves the iterator to the last item in the list and returns + $true if the move was succesfull (i.e., the list is not empty) + and $false otherwise. + + !fn: $movePrev() + Moves the iterator to the previous item and returns $true + if the move was succesfull (i.e., there IS a previous item) + and $false otherwise. + + !fn: $moveNext() + Moves the iterator to the next item and returns $true + if the move was succesfull (i.e., there IS a next item) + and $false otherwise. + + !fn: $eof() + Returns $true if the iterator points to a valid + item in the list (and thus [classfnc:list]$current[/classfnc]() + would return a valid value) and $false otherwise. + + !fn: $current() + Returns the item pointed by the current iterator + or [fnc]$nothing[/fnc] is the iterator is not valid (points + beyond the end of the list). +*/ + + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_list,"list","object") + KVSO_REGISTER_HANDLER(KviKvsObject_list,"count",function_count) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"isEmpty",function_isEmpty) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"clear",function_clear) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"removeAll",function_clear) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"append",function_append) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"prepend",function_prepend) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"insert",function_insert) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"add",function_insert) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"at",function_at) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"item",function_at) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"remove",function_remove) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"removeFirst",function_removeFirst) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"removeLast",function_removeLast) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"removeCurrent",function_removeCurrent) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"moveFirst",function_moveFirst) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"moveNext",function_moveNext) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"movePrev",function_movePrev) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"moveLast",function_moveLast) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"sort",function_sort) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"eof",function_eof) + KVSO_REGISTER_HANDLER(KviKvsObject_list,"current",function_current) +KVSO_END_REGISTERCLASS(KviKvsObject_list) + + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_list,KviKvsObject) + m_pDataList = new KviPointerList; + m_pDataList->setAutoDelete(true); +KVSO_END_CONSTRUCTOR(KviKvsObject_list) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_list) + delete m_pDataList; + m_pDataList = 0; +KVSO_END_CONSTRUCTOR(KviKvsObject_list) + +bool KviKvsObject_list::function_current(KviKvsObjectFunctionCall *c) +{ + if(!m_pDataList) + { + c->returnValue()->setNothing(); + return true; + } + KviKvsVariant * v = m_pDataList->current(); + if(v)c->returnValue()->copyFrom(*v); + else c->returnValue()->setNothing(); + return true; +} + +bool KviKvsObject_list::function_eof(KviKvsObjectFunctionCall *c) +{ + if(!m_pDataList) + { + c->returnValue()->setBoolean(true); + return true; + } + c->returnValue()->setBoolean(m_pDataList->current() != 0); + return true; +} + +bool KviKvsObject_list::function_moveLast(KviKvsObjectFunctionCall *c) +{ + if(!m_pDataList) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(m_pDataList->last() != 0); + return true; +} + +bool KviKvsObject_list::function_movePrev(KviKvsObjectFunctionCall *c) +{ + if(!m_pDataList) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(m_pDataList->prev() != 0); + return true; +} + +bool KviKvsObject_list::function_moveNext(KviKvsObjectFunctionCall *c) +{ + if(!m_pDataList) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(m_pDataList->next() != 0); + return true; +} + +bool KviKvsObject_list::function_moveFirst(KviKvsObjectFunctionCall *c) +{ + if(!m_pDataList) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(m_pDataList->first() != 0); + return true; +} + +bool KviKvsObject_list::function_removeLast(KviKvsObjectFunctionCall *c) +{ + if(!m_pDataList) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(m_pDataList->removeLast()); + return true; +} + +bool KviKvsObject_list::function_removeCurrent(KviKvsObjectFunctionCall *c) +{ + if(!m_pDataList) + { + c->returnValue()->setBoolean(false); + return true; + } + if(m_pDataList->current()) + { + m_pDataList->removeCurrent(); + c->returnValue()->setBoolean(true); + } else { + c->returnValue()->setBoolean(false); + } + return true; +} + +bool KviKvsObject_list::function_removeFirst(KviKvsObjectFunctionCall *c) +{ + if(!m_pDataList) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(m_pDataList->removeFirst()); + return true; +} + +bool KviKvsObject_list::function_remove(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UINT,0,uIndex) + KVSO_PARAMETERS_END(c) + if(!m_pDataList) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(m_pDataList->remove(uIndex)); + return true; +} + +bool KviKvsObject_list::function_at(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UINT,0,uIndex) + KVSO_PARAMETERS_END(c) + if(!m_pDataList) + { + c->returnValue()->setNothing(); + return true; + } + KviKvsVariant * v = m_pDataList->at(uIndex); + if(v)c->returnValue()->copyFrom(*v); + else c->returnValue()->setNothing(); + return true; +} + +bool KviKvsObject_list::function_insert(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uIndex; + KviKvsVariant * pVar; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UINT,0,uIndex) + KVSO_PARAMETER("item",KVS_PT_VARIANT,0,pVar) + KVSO_PARAMETERS_END(c) + if(!m_pDataList)return true; + m_pDataList->insert(uIndex,new KviKvsVariant(*pVar)); + return true; +} + +bool KviKvsObject_list::function_prepend(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pVar; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("item",KVS_PT_VARIANT,0,pVar) + KVSO_PARAMETERS_END(c) + if(!m_pDataList)return true; + m_pDataList->prepend(new KviKvsVariant(*pVar)); + return true; +} + +bool KviKvsObject_list::function_append(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pVar; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("item",KVS_PT_VARIANT,0,pVar) + KVSO_PARAMETERS_END(c) + if(!m_pDataList)return true; + m_pDataList->append(new KviKvsVariant(*pVar)); + return true; +} + +bool KviKvsObject_list::function_clear(KviKvsObjectFunctionCall *c) +{ + if(!m_pDataList)return true; + m_pDataList->clear(); + return true; +} + +inline int kvi_compare(const KviKvsVariant * p1,const KviKvsVariant * p2) +{ + return p1->compare(p2); +} + +bool KviKvsObject_list::function_sort(KviKvsObjectFunctionCall *c) +{ + if(!m_pDataList)return true; + m_pDataList->sort(); + return true; +} + +bool KviKvsObject_list::function_isEmpty(KviKvsObjectFunctionCall *c) +{ + if(!m_pDataList) + { + c->returnValue()->setBoolean(true); + return true; + } + c->returnValue()->setBoolean(m_pDataList->isEmpty()); + return true; +} + +bool KviKvsObject_list::function_count(KviKvsObjectFunctionCall *c) +{ + if(!m_pDataList) + { + c->returnValue()->setInteger(0); + return true; + } + c->returnValue()->setInteger(m_pDataList->count()); + return true; +} + diff --git a/src/modules/objects/class_list.h b/src/modules/objects/class_list.h new file mode 100644 index 00000000..41d2816e --- /dev/null +++ b/src/modules/objects/class_list.h @@ -0,0 +1,64 @@ +#ifndef _CLASS_LIST_H_ +#define _CLASS_LIST_H_ +//========================================================================================= +// +// File : class_list.h +// Creation date : Wed Sep 09 2000 21:07:01 by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2000-2005 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 "kvi_settings.h" +#include "kvi_string.h" +#include "kvi_pointerlist.h" +#include "kvi_kvs_variant.h" +#include "object_macros.h" + + +class KviKvsObject_list : public KviKvsObject +{ +public: + KVSO_DECLARE_OBJECT(KviKvsObject_list) +protected: + KviPointerList * m_pDataList; +protected: + KviPointerList * dataList() const { return m_pDataList; }; +public: + bool function_count(KviKvsObjectFunctionCall *c); + bool function_isEmpty(KviKvsObjectFunctionCall *c); + bool function_clear(KviKvsObjectFunctionCall *c); + bool function_append(KviKvsObjectFunctionCall *c); + bool function_prepend(KviKvsObjectFunctionCall *c); + bool function_insert(KviKvsObjectFunctionCall *c); + bool function_at(KviKvsObjectFunctionCall *c); + bool function_remove(KviKvsObjectFunctionCall *c); + bool function_removeFirst(KviKvsObjectFunctionCall *c); + bool function_removeLast(KviKvsObjectFunctionCall *c); + bool function_removeCurrent(KviKvsObjectFunctionCall *c); + bool function_moveFirst(KviKvsObjectFunctionCall *c); + bool function_moveNext(KviKvsObjectFunctionCall *c); + bool function_movePrev(KviKvsObjectFunctionCall *c); + bool function_moveLast(KviKvsObjectFunctionCall *c); + bool function_eof(KviKvsObjectFunctionCall *c); + bool function_current(KviKvsObjectFunctionCall *c); + bool function_sort(KviKvsObjectFunctionCall *c); +}; + + +#endif //_CLASS_LIST_H_ diff --git a/src/modules/objects/class_listbox.cpp b/src/modules/objects/class_listbox.cpp new file mode 100644 index 00000000..111f7952 --- /dev/null +++ b/src/modules/objects/class_listbox.cpp @@ -0,0 +1,390 @@ +//vim: ts=8 +// File : class_listbox.cpp +// Creation date : Sat Oct 2 03:40:28 CET 2004 by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2004 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 "kvi_error.h" +#include "kvi_locale.h" +#include "kvi_debug.h" + + +#include "kvi_tal_listbox.h" + +#include "class_list.h" +#include "class_listbox.h" + +/* + @doc: listbox + @keyterms: + listbox object class + @title: + listbox class + @type: + class + @short: + A widget displaying a list of items + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + The listbox class is a widget displaying a list of string items.[br] + The listbox can operate in four selection modes: single, multi, extended + and none. In the "single" mode only one item can be selected at a time + and that item is also the current one. In the "multi" mode multiple + items can be selected and unselected and the current item may or may not + be one of the selected items. In the "extended" mode multiple items + can be selected but they must be selected in a single mouse action + or by keeping the shift button pressed while clicking on the item. + In this mode the current item is always one of the selected items.[br] + In the "none" mode no items can be selected and the current item + may be any item in the list.[br] + In most situations you will operate the listbox in "single" mode + (and this is the default mode set at widget creation). + @functions: + !fn: $setSelectionMode() + Sets the current selection mode specified by the parameter + that can be one of the following string:[br] + "single" : only one item can be selected at a time[br] + "multi" : multiple items can be selected at a time[br] + "extended" : multiple items can be selected but only in a single mouse interaction[br] + "none" : no items can be selected[br] + The default mode is "single" + !fn: $selectionMode() + Returns the current selection mode + !fn: $insertItem(, ) + Inserts a text item at position . If index is negative or + not specified the item is appended. + !fn: $changeItem(, ) + Changes text of item at to . + !fn: $removeItem() + Removes item at given index. + !fn: $count() + Returns number of items in the widget. + !fn: $currentText() + Returns the text of the currently selected item. + !fn: $currentItem() + Returns index of current item or -1 if no item is current. + !fn: $textAt() + Returns item at given index. + !fn: $setCurrentItem() + Sets the current listbox item. + !fn: $clear() + Removes all the items + !fn: $isSelected() + Returns 1 if the item at is selected and 0 otherwise + !fn: $setSelected(,) + Changes the selection status of the item at to the value + specified by . If is 1 the item is selected, + if is 0 the item is unselected. + !fn: $selectionChangeEvent() + This function is called by KVIrc when the selection in the listbox changes. + !fn: $currentItemChangeEvent() + This function is called by KVIrc when the current item changes. + !fn: $onItemEvent() + This function is called by KVIrc when the current item pointed by the mouse changes and gives in $0 the item index. + !fn: $itemRect() + Returns the rectangle on the screen that item occupies, or an invalid rectangle if item is 0 or is not currently visible. + + @signals: + !sg: $currentItemChange() + This signal is emitted by the default implementation of [classfnc]$currentItemChangeEvent[/classfnc]().[br] + !sg: $onItem() + This signal is emitted by the default implementation of [classfnc]$onItemEvent[/classfnc]().[br] + + */ + + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_listbox,"listbox","widget") + KVSO_REGISTER_HANDLER(KviKvsObject_listbox,"insertItem", functioninsertItem) + KVSO_REGISTER_HANDLER(KviKvsObject_listbox,"changeItem", functionchangeItem) + KVSO_REGISTER_HANDLER(KviKvsObject_listbox,"removeItem", functionremoveItem) + KVSO_REGISTER_HANDLER(KviKvsObject_listbox,"clear", functionclear) + KVSO_REGISTER_HANDLER(KviKvsObject_listbox,"count", functioncount) + KVSO_REGISTER_HANDLER(KviKvsObject_listbox,"currentText", functioncurrentText) + KVSO_REGISTER_HANDLER(KviKvsObject_listbox,"currentItem", functioncurrentItem) + KVSO_REGISTER_HANDLER(KviKvsObject_listbox,"textAt", functiontextAt); + KVSO_REGISTER_HANDLER(KviKvsObject_listbox,"itemAt", functionitemAt); + KVSO_REGISTER_HANDLER(KviKvsObject_listbox,"itemRect", functionitemRect); + KVSO_REGISTER_HANDLER(KviKvsObject_listbox,"setCurrentItem", functionsetCurrentItem); + + + KVSO_REGISTER_HANDLER(KviKvsObject_listbox,"setSelectionMode",functionsetSelectionMode); + KVSO_REGISTER_HANDLER(KviKvsObject_listbox,"selectionMode",functionselectionMode); + KVSO_REGISTER_HANDLER(KviKvsObject_listbox,"setSelected",functionsetSelected); + KVSO_REGISTER_HANDLER(KviKvsObject_listbox,"isSelected",functionisSelected); + KVSO_REGISTER_HANDLER(KviKvsObject_listbox,"currentItemChangeEvent",functioncurrentItemChangeEvent); + KVSO_REGISTER_HANDLER(KviKvsObject_listbox,"onItemEvent",functiononItemEvent); + + + KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KviKvsObject_listbox,"selectionChangeEvent") + + +KVSO_END_REGISTERCLASS(KviKvsObject_listbox) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_listbox,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_listbox) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_listbox) + +KVSO_END_CONSTRUCTOR(KviKvsObject_listbox) + +bool KviKvsObject_listbox::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + KviTalListBox * b = new KviTalListBox(parentScriptWidget()); + b->setSelectionMode(KviTalListBox::Single); + connect(b,SIGNAL(selectionChanged()),this,SLOT(selectionChanged())); + connect(b,SIGNAL(currentChanged(KviTalListBoxItem *)),this,SLOT(currentItemChanged(KviTalListBoxItem *))); + + connect(b,SIGNAL(onItem(KviTalListBoxItem *)),this,SLOT(onItem(KviTalListBoxItem *))); + + setObject(b,true);; + return true; +} + +bool KviKvsObject_listbox::functioninsertItem(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iIndex; + QString szItem; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szItem) + KVSO_PARAMETER("index",KVS_PT_INT,KVS_PF_OPTIONAL,iIndex) + KVSO_PARAMETERS_END(c) + if(widget()) + ((KviTalListBox *)widget())->insertItem(szItem, iIndex); + return true; +} +bool KviKvsObject_listbox::functionclear(KviKvsObjectFunctionCall *c) +{ + if (widget()) ((KviTalListBox *)widget())->clear(); + return true; +} +bool KviKvsObject_listbox::functionchangeItem(KviKvsObjectFunctionCall *c) +{ + + kvs_uint_t uIndex,cnt; + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + if(!widget()) return true; + if (szText.isEmpty()) c->warning(__tr2qs("No string parameter given - using empty string")); + if(uIndex >= (cnt = ((KviTalListBox *)widget())->count())) + { + c->warning(__tr2qs("Item index [%d] is too big - defaulting to " \ + "$count() - 1 [%d]"), uIndex, cnt); + uIndex = cnt - 1; + } + + ((KviTalListBox *)widget())->changeItem(szText, uIndex); + + return true; + +} +bool KviKvsObject_listbox::functionremoveItem(KviKvsObjectFunctionCall *c) +{ + + kvs_uint_t uIndex,cnt; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + if(!widget()) return true; + if(uIndex >= (cnt = ((KviTalListBox *)widget())->count())) + { + c->warning(__tr2qs("Item index [%d] is too big - defaulting to " \ + "$count() - 1 [%d]"), uIndex, cnt); + uIndex = cnt - 1; + } + + ((KviTalListBox *)widget())->removeItem(uIndex); + + return true; + +} + +bool KviKvsObject_listbox::functioncount(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setInteger(((KviTalListBox *)widget())->count()); + return true; +} +bool KviKvsObject_listbox::functioncurrentText(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setString(((KviTalListBox *)widget())->currentText().local8Bit().data()); + return true; +} +bool KviKvsObject_listbox::functioncurrentItem(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setInteger(((KviTalListBox *)widget())->currentItem()); + return true; +} + +bool KviKvsObject_listbox::functiontextAt(KviKvsObjectFunctionCall *c) +{ + + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + if(widget()) + c->returnValue()->setString(((KviTalListBox *)widget())->text(uIndex)); + return true; +} +bool KviKvsObject_listbox::functionsetCurrentItem(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + if(widget()) + ((KviTalListBox *)widget())->setCurrentItem(uIndex); + return true; +} +bool KviKvsObject_listbox::functionsetSelectionMode(KviKvsObjectFunctionCall *c) +{ + QString szMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("selection_mode",KVS_PT_STRING,0,szMode) + KVSO_PARAMETERS_END(c) + if(!widget()) return true; + KviTalListBox::SelectionMode iMode = KviTalListBox::Single; + + if(KviQString::equalCI(szMode,"single")) iMode = KviTalListBox::Single; + + else if(KviQString::equalCI(szMode,"multi")) iMode = KviTalListBox::Multi; + + else if(KviQString::equalCI(szMode,"extended")) iMode = KviTalListBox::Extended; + + else if(KviQString::equalCI(szMode,"none")) iMode = KviTalListBox::NoSelection; + + else c->warning(__tr2qs("Invalid selection mode '%Q' assuming single"),&szMode); + ((KviTalListBox *)widget())->setSelectionMode(iMode); + + return true; +} +bool KviKvsObject_listbox::functionselectionMode(KviKvsObjectFunctionCall *c) +{ + + if(!widget()) return true; + switch(((KviTalListBox *)widget())->selectionMode()) + { + case KviTalListBox::Single: c->returnValue()->setString("single"); break; + case KviTalListBox::Multi: c->returnValue()->setString("multi"); break; + case KviTalListBox::Extended: c->returnValue()->setString("extended"); break; + case KviTalListBox::NoSelection: c->returnValue()->setString("none"); break; + default: c->returnValue()->setString("single"); break; + } + return true; +} + +bool KviKvsObject_listbox::functionisSelected(KviKvsObjectFunctionCall *c) +{ + + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + if(widget())c->returnValue()->setBoolean(((KviTalListBox *)widget())->isSelected(uIndex)); + return true; +} +bool KviKvsObject_listbox::functionsetSelected(KviKvsObjectFunctionCall *c) +{ + bool bSel; + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETER("benabled",KVS_PT_BOOLEAN,0,bSel) + KVSO_PARAMETERS_END(c) + if(widget()) ((KviTalListBox *)widget())->setSelected(uIndex,bSel); + return true; +} +bool KviKvsObject_listbox::functionitemAt(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uX,uY; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("uX",KVS_PT_UNSIGNEDINTEGER,0,uX) + KVSO_PARAMETER("uY",KVS_PT_UNSIGNEDINTEGER,0,uY) + KVSO_PARAMETERS_END(c) + if(widget()) + c->returnValue()->setInteger(((KviTalListBox *)widget())->index(((KviTalListBox *)widget())->itemAt(QPoint(uX,uY)))); + return true; +} + +bool KviKvsObject_listbox::functioncurrentItemChangeEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("currentItemChange",c,c->params()); + + return true; +} + +void KviKvsObject_listbox::selectionChanged() +{ + KviKvsVariantList *params=0; + callFunction(this,"selectionChangeEvent",0,0); +} + +void KviKvsObject_listbox::currentItemChanged(KviTalListBoxItem *item) +{ + if (!item) callFunction(this,"currentItemChangeEvent",0,0); + else + { + KviKvsVariantList params(new KviKvsVariant(item->text())); + callFunction(this,"currentItemChangeEvent",0,¶ms); + } + +} +bool KviKvsObject_listbox::functiononItemEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("onItem",c,c->params()); + + return true; +} + +void KviKvsObject_listbox::onItem(KviTalListBoxItem *item) +{ + KviTalListBox *lbx = (KviTalListBox *)(item->listBox()); + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)lbx->index(item))); + callFunction(this,"onItemEvent",0,¶ms); +} + + +bool KviKvsObject_listbox::functionitemRect(KviKvsObjectFunctionCall *c) +{ +kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("uIndex",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + if(widget()) + { + QRect rect=((KviTalListBox *)widget())->itemRect(((KviTalListBox *)widget())->item(uIndex)); + KviKvsArray * a = new KviKvsArray(); + a->set(0,new KviKvsVariant((kvs_int_t)rect.left())); + a->set(1,new KviKvsVariant((kvs_int_t)rect.top())); + a->set(2,new KviKvsVariant((kvs_int_t)rect.width())); + a->set(3,new KviKvsVariant((kvs_int_t)rect.height())); + c->returnValue()->setArray(a); + } + return true; +} + + +#include "m_class_listbox.moc" diff --git a/src/modules/objects/class_listbox.h b/src/modules/objects/class_listbox.h new file mode 100644 index 00000000..471337fd --- /dev/null +++ b/src/modules/objects/class_listbox.h @@ -0,0 +1,70 @@ +#ifndef _CLASS_LISTBOX_H_ +#define _CLASS_LISTBOX_H_ + +//vim: ts=8 +// File : class_listbox.h +// Creation date : Sat Oct 2 03:40:28 CET 2004 by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2004 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 "class_widget.h" + +class KviTalListBox; +class KviTalListBoxItem; + +#include "object_macros.h" + +class KviKvsObject_listbox: public KviKvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_listbox) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + + bool functioninsertItem(KviKvsObjectFunctionCall *c); + bool functionchangeItem(KviKvsObjectFunctionCall *c); + bool functionremoveItem(KviKvsObjectFunctionCall *c); + bool functioncount(KviKvsObjectFunctionCall *c); + bool functioncurrentText(KviKvsObjectFunctionCall *c); + bool functioncurrentItem(KviKvsObjectFunctionCall *c); + bool functiontextAt(KviKvsObjectFunctionCall *c); + bool functionsetCurrentItem(KviKvsObjectFunctionCall *c); + bool functionclear(KviKvsObjectFunctionCall *c); + bool functionsetSelectionMode(KviKvsObjectFunctionCall *c); + bool functionselectionMode(KviKvsObjectFunctionCall *c); + bool functionsetSelected(KviKvsObjectFunctionCall *c); + bool functionisSelected(KviKvsObjectFunctionCall *c); + bool functioncurrentItemChangeEvent(KviKvsObjectFunctionCall *c); + bool functiononItemEvent(KviKvsObjectFunctionCall *c); + + bool functionitemAt(KviKvsObjectFunctionCall *c); + bool functionitemRect(KviKvsObjectFunctionCall *c); +protected slots: + void selectionChanged(); + void currentItemChanged(KviTalListBoxItem *); + void onItem(KviTalListBoxItem *); +}; + + +#endif // !_CLASS_COMBOBOX_H_ diff --git a/src/modules/objects/class_listview.cpp b/src/modules/objects/class_listview.cpp new file mode 100644 index 00000000..f571788c --- /dev/null +++ b/src/modules/objects/class_listview.cpp @@ -0,0 +1,557 @@ +//================================================================================= +// +// File : class_listview.cpp +// Creation date : Fri Jan 28 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2006 Szymon Stefanek (pragma at kvirc dot net) +// Copyright (C) 2005-2006 Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// 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 "kvi_tal_listview.h" +#ifdef COMPILE_USE_QT4 +#include +#include +#else +#include +#endif +#include "class_listview.h" +#include "kvi_error.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_iconmanager.h" + + + +/* + @doc: listview + @keyterms: + listview widget class + @title: + listview class + @type: + class + @short: + A listview class + @inherits: + [class]widget[/class] + @description: + It can display and control a hierarchy of multi-column items, and provides the ability to add new items at any time. + The items are added by creating children [class]listviewitem[/class] objects: simply allocating them with $new + will add the items to the listview and simply deleting them will remove them. + Allocating a [class]listviewitem[/class] item2 as a child of item1 will insert it to the same listview creating + a subtree of items spannig from item1. The subtree can be opened or closed by a simple click either + on the parent item or on the little plus sign on the side of it (when [classfnc:listview]$setRootIsDecorated[/classfnc] + is set to $true. The listview can be in Single, Multi, Extended or NoSelection selection mode. + In single selection mode there can be only one selected item at a time and the selected item is also + the current item (this mode is the default). In Multi and Extended selection mode there can be multiple selected items + and the current item is one of them. The difference between Multi and Extended is in the way + that items can be selected by the mouse actions: experiment with the two modes :). + The NoSelection mode has obviously no selection at all. + @functions: + !fn: $addColumn( ) + Adds a width pixels wide column with the column header label to the list view. + + !fn: $setSorting(,) + Sets the list view to be sorted by column column in ascending order if ascending is 1 or descending order if it is FALSE. + If column is -1, sorting is disabled and the user cannot sort columns by clicking on the column headers + + !fn: $hideListViewHeader() + Hide the listview column header. + + !fn: $showListViewHeader() + Show the listview column header. + + !fn: $isListViewHeaderVisible() + Returns '1' if the listview header is currently visible. Otherwise this function returns '0'. + + !fn: $setAllColumnsShowFocus() + When the argument is $true, causes the listview to display the focus and selection + by highlighting all the columns of the item. When the argument is $false then + only the first column is selected/highlighted. + + !fn: $setSelectionMode() + Sets the selection mode for this listview. can be one of "Single","NoSelection","Multi" or "Extended". + + !fn: $selectedItem() + Returns the currently selected [class]listviewitem[/class] or $null if no items are selected. + This function works only if the list view is in single selection mode. + + !fn: $currentItem() + Returns the current [class]listviewitem[/class] or $null if no item is current at the moment. + + !fn: $firstChild() + Returns the first child [class]listviewitem[/class] of this listview or $null if there are no items at all. + + !fn: $clickEvent() + This function is called when the user clicks in the list view. + In its argument the [class]listviewitem[/class] object clicked or 0 if the user didn't click on an item.[br] + The default implementation emits the [classfnc]$clicked[/classfnc]() signal. + + !fn: $selectionChangedEvent() + This event handle whenever the set of selected items has changed. + The argument is the newly selected item if the listview is in single selection mode.[br] + When the listview is in Multi or Extended selection mode then item is always $null.[br] + The default implementation emits the [classfnc]$selectionChanged[/classfnc]() signal. + + !fn: $currentChangedEvent() + This event are called whenever the current item has changed. + In its argument is the newly selected item or 0 if the change made no item current.[br] + The default implementation emits the [classfnc]$currentChanged[/classfnc]() signal. + + !fn: $returnPressedEvent() + This function is called by the framework when the enter key is pressed.[br] + In its arument the currrent item.[br] + The default implementation emits the [classfnc]$returnPressed[/classfnc]() signal. + + !fn: $spacePressedEvent() + This function is called by the framework when the space key is pressed.[br] + In its arument the currrent item.[br] + The default implementation emits the [classfnc]$spacePressed[/classfnc]() signal. + + !fn: $onItemEvent() + This event is called when an item has been expanded, i.e. when the children of item are shown. + The default implementation emits the [classfnc]$expanded[/classfnc]() signal. + + !fn: $itemCollapsedEvent() + This event is called when an item has been collapsed, i.e. when the children of item are hidden. + The default implementation emits the [classfnc]$collapsed[/classfnc]() signal. + + !fn: $itemRenamedEvent(,,) + This event is called when the item has been renamed in text, e.g. by in in-place renaming, in column col.[br] + The default implementation emits the [classfnc]$itemRenamed[/classfnc]() signal. + + !fn: $rightButtonClickEvent(,,>y:integer>) + This signal is emitted when the right button is clicked.[br] + The arguments are the relevant item (may be 0), the point in global coordinates and the relevant column (or -1 if the click was outside the list). + The default implementation emits the [classfnc]$rightButtonClicked[/classfnc]() signal. + @signals: + !sg: $clicked() + This signal is emitted by the default implementation of [classfnc]$clickEvent[/classfnc](). + !sg: $selectionChanged() + This signal is emitted by the default implementation of [classfnc]$selectionChangedEvent[/classfnc](). + !sg: $currentChanged() + This signal is emitted by the default implementation of [classfnc]$currentChangedEvent[/classfnc](). + !sg: $returnPressed() + This signal is emitted by the default implementation of [classfnc]$returnPressedEvent[/classfnc](). + !sg: $spacePressed() + This signal is emitted by the default implementation of [classfnc]$spacePredssedEvent[/classfnc](). + !sg: $onItem() + This signal is emitted by the default implementation of [classfnc]$onItemEvent[/classfnc](). + !sg: $itemExpanded() + This signal is emitted by the default implementation of [classfnc]$itemExpandedEvent[/classfnc](). + !sg: $itemCollapsed() + This signal is emitted by the default implementation of [classfnc]$itemCollapsedEvent[/classfnc](). + !sg: $itemRenamed() + This signal is emitted by the default implementation of [classfnc]$itemRenamedEvent[/classfnc](). + !sg: $rightButtonClicked() + This signal is emitted by the default implementation of [classfnc]$rightButtonClickedEvent[/classfnc](). + + +*/ + +//--------------------------------------------------------------------------------- + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_listview,"listview","widget") + + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"addColumn",function_addColumn) + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"setColumnText",function_setColumnText) + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"setSorting",function_setSorting) + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"setRootIsDecorated",function_setRootIsDecorated) + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"setAllColumnsShowFocus",function_setAllColumnsShowFocus) + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"clear",function_clear) + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"selectedItem",function_selectedItem) + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"currentItem",function_currentItem) + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"setSelectionMode",function_setSelectionMode) + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"listViewHeaderIsVisible",function_listViewHeaderIsVisible) + + + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"hideListViewHeader",function_hideListViewHeader) + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"showListViewHeader",function_showListViewHeader) + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"firstChild",function_firstChild) + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"selectionChangedEvent",function_selectionChangedEvent); + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"currentChangedEvent",function_currentChangedEvent); + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"returnPressedEvent",function_returnPressedEvent); + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"spacePressedEvent",function_spacePressedEvent); + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"onItemEvent",function_onItemEvent); + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"itemClickedEvent",function_itemClickedEvent); + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"itemExpandedEvent",function_itemExpandedEvent); + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"itemCollapsedEvent",function_itemCollapsedEvent); + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"itemRenamedEvent",function_itemRenamedEvent); + KVSO_REGISTER_HANDLER(KviKvsObject_listview,"rightButtonClickedEvent",function_rightButtonClickedEvent); + + KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KviKvsObject_listview,"fileDroppedEvent") + +KVSO_END_REGISTERCLASS(KviKvsObject_listview) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_listview,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_listview) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_listview) + +KVSO_END_CONSTRUCTOR(KviKvsObject_listview) + +bool KviKvsObject_listview::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + setObject(new KviKvsMdmListView(parentScriptWidget(),name(),this),true); + connect(widget(),SIGNAL(clicked(KviTalListViewItem *)),this,SLOT(slotClicked(KviTalListViewItem *))); + connect(widget(),SIGNAL(selectionChanged(KviTalListViewItem *)),this,SLOT(slotSelectionChanged(KviTalListViewItem *))); + connect(widget(),SIGNAL(selectionChanged()),this,SLOT(slotMultipleSelectionChanged())); + connect(widget(),SIGNAL(currentChanged(KviTalListViewItem *)),this,SLOT(slotCurrentChanged(KviTalListViewItem *))); + connect(widget(),SIGNAL(returnPressed(KviTalListViewItem *)),this,SLOT(slotReturnPressed(KviTalListViewItem *))); + connect(widget(),SIGNAL(spacePressed(KviTalListViewItem *)),this,SLOT(slotSpacePressed(KviTalListViewItem *))); + connect(widget(),SIGNAL(onItem(KviTalListViewItem *)),this,SLOT(slotOnItem(KviTalListViewItem *))); + connect(widget(),SIGNAL(expanded(KviTalListViewItem *)),this,SLOT(slotItemExpanded(KviTalListViewItem *))); + connect(widget(),SIGNAL(collapsed(KviTalListViewItem *)),this,SLOT(slotItemCollapsed(KviTalListViewItem *))); + connect(widget(),SIGNAL(rightButtonClicked(KviTalListViewItem *,const QPoint &,int)),this,SLOT(slotRightButtonClicked(KviTalListViewItem *,const QPoint &,int))); + connect(widget(),SIGNAL(itemRenamed(KviTalListViewItem *,int,const QString &)),this,SLOT(slotItemRenamed(KviTalListViewItem *,int,const QString &))); + return true; +} + +bool KviKvsObject_listview::function_addColumn(KviKvsObjectFunctionCall *c) +{ + QString szLabel; + kvs_int_t iW; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("label",KVS_PT_STRING,0,szLabel) + KVSO_PARAMETER("width",KVS_PT_INT,0,iW) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalListView *)object())->addColumn(szLabel,iW); + return true; +} +/* +bool KviKvsObject_listview::function_setAcceptDrops(KviKvsObjectFunctionCall *c) +{ + bool bEnable; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnable",KVS_PT_BOOLEAN,0,bEnable) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalListView *)object())->setAcceptDrops(bEnable); + return true; +} +*/ +bool KviKvsObject_listview::function_clear(KviKvsObjectFunctionCall *c) +{ + if (widget()) + ((KviTalListView *)object())->clear(); + return true; +} + +bool KviKvsObject_listview::function_selectedItem(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setHObject(KviKvsObject_listviewitem::itemToHandle(((KviTalListView *)widget())->selectedItem())); + else + c->returnValue()->setHObject((kvs_hobject_t)0); + return true; +} + +bool KviKvsObject_listview::function_firstChild(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setHObject(KviKvsObject_listviewitem::itemToHandle(((KviTalListView *)widget())->firstChild())); + else + c->returnValue()->setHObject((kvs_hobject_t)0); + return true; +} + +bool KviKvsObject_listview::function_currentItem(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setHObject(KviKvsObject_listviewitem::itemToHandle(((KviTalListView *)widget())->currentItem())); + else + c->returnValue()->setHObject((kvs_hobject_t)0); + return true; +} + +bool KviKvsObject_listview::function_setColumnText(KviKvsObjectFunctionCall *c) +{ + kvs_int_t uCol; + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if (widget())((KviTalListView *)widget())->setColumnText(uCol,szText); + return true; +} + +bool KviKvsObject_listview::function_setSelectionMode(KviKvsObjectFunctionCall *c) +{ + QString szMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("mode",KVS_PT_NONEMPTYSTRING,0,szMode) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + if(KviQString::equalCI(szMode,"NoSelection")) + ((KviTalListView *)widget())->setSelectionMode(KviTalListView::NoSelection); + else if(KviQString::equalCI(szMode,"Multi")) + ((KviTalListView *)widget())->setSelectionMode(KviTalListView::Multi); + else if(KviQString::equalCI(szMode,"Extended")) + ((KviTalListView *)widget())->setSelectionMode(KviTalListView::Extended); + else if(KviQString::equalCI(szMode,"Single")) + ((KviTalListView *)widget())->setSelectionMode(KviTalListView::Single); + else c->warning(__tr2qs("Invalid selection mode '%Q'"),&szMode); + return true; +} + +bool KviKvsObject_listview::function_setSorting(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iCol; + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_INT,0,iCol) + KVSO_PARAMETER("benabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if (widget()) ((KviTalListView *)widget())->setSorting(iCol,bEnabled); + return true; +} + + +bool KviKvsObject_listview::function_setRootIsDecorated(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if (widget()) ((KviTalListView *)widget())->setRootIsDecorated(bEnabled); + return true; +} + +bool KviKvsObject_listview::function_setAllColumnsShowFocus(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bAllColumnsShowFocus",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if (widget())((KviTalListView *)widget())->setAllColumnsShowFocus(bEnabled); + return true; +} + +bool KviKvsObject_listview::function_hideListViewHeader(KviKvsObjectFunctionCall *c) +{ +// ((KviTalListView *)widget())->header()->hide(); + return true; +} +bool KviKvsObject_listview::function_showListViewHeader(KviKvsObjectFunctionCall *c) +{ +// ((KviTalListView *)widget())->header()->show(); + return true; +} +bool KviKvsObject_listview::function_listViewHeaderIsVisible(KviKvsObjectFunctionCall *c) +{ + c->returnValue()->setBoolean(((KviTalListView *)widget())->header()->isVisible()); + return true; +} + +bool KviKvsObject_listview::function_itemClickedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("itemClicked",c,c->params()); + return true; +} + +void KviKvsObject_listview::slotClicked(KviTalListViewItem * i) +{ + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_listviewitem::itemToHandle(i))); + callFunction(this,"itemClickedEvent",0,¶ms); +} + +bool KviKvsObject_listview::function_selectionChangedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("selectionChanged",c,c->params()); + return true; +} + +void KviKvsObject_listview::slotSelectionChanged(KviTalListViewItem * i) +{ + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_listviewitem::itemToHandle(i))); + callFunction(this,"selectionChangedEvent",0,¶ms); +} + +void KviKvsObject_listview::slotMultipleSelectionChanged() +{ + KviKvsVariantList params(new KviKvsVariant((kvs_hobject_t)0)); + callFunction(this,"selectionChangedEvent",0,¶ms); +} + + +bool KviKvsObject_listview::function_currentChangedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("currentChanged",c,c->params()); + return true; +} + +void KviKvsObject_listview::slotCurrentChanged(KviTalListViewItem * i) +{ + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_listviewitem::itemToHandle(i))); + callFunction(this,"currentChangedEvent",0,¶ms); +} + + +bool KviKvsObject_listview::function_returnPressedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("returnPressed",c,c->params()); + return true; +} + +void KviKvsObject_listview::slotReturnPressed(KviTalListViewItem * i) +{ + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_listviewitem::itemToHandle(i))); + callFunction(this,"returnPressedEvent",0,¶ms); +} + +bool KviKvsObject_listview::function_spacePressedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("spacePressed",c,c->params()); + return true; +} + +void KviKvsObject_listview::slotSpacePressed(KviTalListViewItem * i) +{ + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_listviewitem::itemToHandle(i))); + callFunction(this,"spacePressedEvent",0,¶ms); +} + +bool KviKvsObject_listview::function_onItemEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("onItem",c,c->params()); + return true; +} + +void KviKvsObject_listview::slotOnItem(KviTalListViewItem * i) +{ + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_listviewitem::itemToHandle(i))); + callFunction(this,"onItemEvent",0,¶ms); +} + + +bool KviKvsObject_listview::function_itemExpandedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("itemExpanded",c,c->params()); + return true; +} + +void KviKvsObject_listview::slotItemExpanded(KviTalListViewItem * i) +{ + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_listviewitem::itemToHandle(i))); + callFunction(this,"itemExpandedEvent",0,¶ms); +} + +bool KviKvsObject_listview::function_itemCollapsedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("itemCollapsed",c,c->params()); + return true; +} + +void KviKvsObject_listview::slotItemCollapsed(KviTalListViewItem * i) +{ + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_listviewitem::itemToHandle(i))); + callFunction(this,"itemCollapsedEvent",0,¶ms); +} + +bool KviKvsObject_listview::function_rightButtonClickedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("rightButtonClicked",c,c->params()); + return true; +} + +void KviKvsObject_listview::slotRightButtonClicked(KviTalListViewItem * i,const QPoint &coor, int col) +{ + KviKvsVariant *xpos=new KviKvsVariant((kvs_int_t)coor.x()); + KviKvsVariant *ypos=new KviKvsVariant((kvs_int_t)coor.y()); + KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col); + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_listviewitem::itemToHandle(i)),xpos,ypos,column); + callFunction(this,"rightButtonClickedEvent",0,¶ms); +} + +bool KviKvsObject_listview::function_itemRenamedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("itemRenamed",c,c->params()); + return true; +} + +void KviKvsObject_listview::slotItemRenamed(KviTalListViewItem *item,int col,const QString & szText) +{ + KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col); + KviKvsVariant *txt=new KviKvsVariant(szText); + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_listviewitem::itemToHandle(item)),column,txt); + callFunction(this,"itemRenamedEvent",0,¶ms); +} +void KviKvsObject_listview::fileDropped(QString &szFile,KviTalListViewItem *item) +{ + KviKvsVariant *file=new KviKvsVariant(szFile); + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_listviewitem::itemToHandle(item)),file); + callFunction(this,"fileDroppedEvent",0,¶ms); +} + +KviKvsMdmListView::KviKvsMdmListView(QWidget * par,const char * name,KviKvsObject_listview *parent) +:KviTalListView(par) +{ + m_pParentScript=parent; + setAcceptDrops(true); + viewport()->setAcceptDrops( TRUE ); + +} +KviKvsMdmListView::~KviKvsMdmListView() +{ +} + +void KviKvsMdmListView::contentsDragEnterEvent( QDragEnterEvent *e ) +{ + if ( !KviUriDrag::canDecode(e)) + { + e->ignore(); + return; + } + +} + + +void KviKvsMdmListView::contentsDropEvent(QDropEvent *e) +{ + QStringList list; + if(KviUriDrag::decodeLocalFiles(e,list)) + { + if(!list.isEmpty()) + { + QStringList::ConstIterator it = list.begin(); //kewl ! :) + for( ; it != list.end(); ++it ) + { + QString tmp = *it; //wow :) + #ifndef COMPILE_ON_WINDOWS + if(tmp[0] != '/')tmp.prepend("/"); //HACK HACK HACK for Qt bug (?!?) + #endif + KviTalListViewItem *i = itemAt( contentsToViewport(e->pos()) ); + m_pParentScript->fileDropped(tmp,i); + } + } + } + +} +#include "m_class_listview.moc" diff --git a/src/modules/objects/class_listview.h b/src/modules/objects/class_listview.h new file mode 100644 index 00000000..7849f36c --- /dev/null +++ b/src/modules/objects/class_listview.h @@ -0,0 +1,102 @@ +#ifndef _CLASS_LISTVIEW_H_ +#define _CLASS_LISTVIEW_H_ +//================================================================================= +// +// File : class_listview.h +// Creation date : Fri Jan 28 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2006 Szymon Stefanek (pragma at kvirc dot net) +// Copyright (C) 2005-2006 Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// 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 "kvi_tal_listview.h" +#include "kvi_draganddrop.h" +#include "class_widget.h" +#include "class_listviewitem.h" + +#include "object_macros.h" + +class KviKvsObject_listview : public KviKvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_listview) + +public: + QWidget * widget() { return (QWidget *)object(); }; + void fileDropped(QString &,KviTalListViewItem *); +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool function_addColumn(KviKvsObjectFunctionCall *c); + bool function_setColumnText(KviKvsObjectFunctionCall *c); + bool function_takeItem(KviKvsObjectFunctionCall *c); + bool function_setSorting(KviKvsObjectFunctionCall *c); + bool function_setRootIsDecorated(KviKvsObjectFunctionCall *c); + bool function_clear(KviKvsObjectFunctionCall *c); + bool function_setAllColumnsShowFocus(KviKvsObjectFunctionCall *c); + bool function_itemClickedEvent(KviKvsObjectFunctionCall *c); + bool function_selectionChangedEvent(KviKvsObjectFunctionCall *c); + bool function_currentChangedEvent(KviKvsObjectFunctionCall *c); + bool function_returnPressedEvent(KviKvsObjectFunctionCall *c); + bool function_spacePressedEvent(KviKvsObjectFunctionCall *c); + bool function_onItemEvent(KviKvsObjectFunctionCall *c); + bool function_itemExpandedEvent(KviKvsObjectFunctionCall *c); + bool function_itemCollapsedEvent(KviKvsObjectFunctionCall *c); + bool function_itemRenamedEvent(KviKvsObjectFunctionCall *c); + bool function_rightButtonClickedEvent(KviKvsObjectFunctionCall *c); + bool function_selectedItem(KviKvsObjectFunctionCall *c); + bool function_currentItem(KviKvsObjectFunctionCall *c); + bool function_setSelectionMode(KviKvsObjectFunctionCall *c); + bool function_firstChild(KviKvsObjectFunctionCall *c); + bool function_listViewHeaderIsVisible(KviKvsObjectFunctionCall *c); + bool function_showListViewHeader(KviKvsObjectFunctionCall *c); + bool function_hideListViewHeader(KviKvsObjectFunctionCall *c); + + bool function_setAcceptDrops(KviKvsObjectFunctionCall *c); + +protected slots: + void slotClicked(KviTalListViewItem *); + void slotSelectionChanged(KviTalListViewItem *); + void slotMultipleSelectionChanged(); + void slotCurrentChanged(KviTalListViewItem *); + void slotReturnPressed(KviTalListViewItem *); + void slotSpacePressed(KviTalListViewItem *); + void slotOnItem(KviTalListViewItem *); + void slotItemExpanded(KviTalListViewItem *); + void slotItemCollapsed(KviTalListViewItem *); + void slotItemRenamed(KviTalListViewItem *,int,const QString &); + void slotRightButtonClicked(KviTalListViewItem * i,const QPoint &coor, int col); +}; + +class KviKvsMdmListView : public KviTalListView +{ + Q_OBJECT +public: + KviKvsMdmListView(QWidget * par,const char * name,KviKvsObject_listview *); + + virtual ~KviKvsMdmListView(); +protected: + KviKvsObject_listview *m_pParentScript; + void contentsDropEvent(QDropEvent *e); + void contentsDragEnterEvent( QDragEnterEvent *e ); + +}; +#endif //!_CLASS_LISTVIEW_H_ diff --git a/src/modules/objects/class_listviewitem.cpp b/src/modules/objects/class_listviewitem.cpp new file mode 100644 index 00000000..31df9020 --- /dev/null +++ b/src/modules/objects/class_listviewitem.cpp @@ -0,0 +1,421 @@ +//mdm: +// File : class_ListViewItem.h +// Creation date : Thu Feb 1 14:39:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 "class_listviewitem.h" +#include "class_pixmap.h" +#include "kvi_error.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_iconmanager.h" + + + +/* + @doc: listviewitem + @keyterms: + listview listviewitem class + @title: + listviewitem class + @type: + class + @short: + A listviewitem class + @inherits: + [class]listviewitem[/class] + @description: + The listviewitem class implements a list view item. + A list view item is a multi-column object capable of displaying itself in a [class]listview[/class]. + To use this class you must instantiate it with another listviewitem or a [class]listview[/class] + as parent. The item will be automatically displayed. + You can set the text and a pixmap in each column and you can make it checkable + with [classfnc:listviewitem]$setCheckable[/classfnc](). + A checkable listviewitem will display a small check mark in the first column. + @functions: + !fn: $setText(,) + Sets the text in column column to text, if column is a valid column number and text is different from the existing text. + + !fn: $text() + Returs the text of the specified column. + + !fn: $setPixmap(,) + Sets the pixmap in column column to pm, if pm is non-null and different from the current pixmap, and if column is non-negative. + Pixmap can be a Kvirc imageid, an image file or a [class]pixmap[/class] object. + + !fn: $setRenameEnabled(,) + If b is TRUE (1), this item can be in-place renamed in the column col by the user; otherwise it cannot be renamed in-place. + + !fn: $setEnabled() + Enables or disables the item + + !fn: $isEnabled() + Returns $true if this item is enabled and $false otherwise + + !fn: $setOpen() + Opens or closes the item to show its children items + + !fn: $isOpen() + Returns the open state of this item + + !fn: $setCheckable() + Makes this item checkable or not. This function should be called immediately + after the item creation: changing this property later at runtime may have + strange results (like the item being moved inside the list, text disappearing, + hidden children etc... don't do it :D ). + + !fn: $isCheckable() + Returns $true if this item is checkable and $false otherwise + + !fn: $setChecked() + Sets this item to be checked or not. [classfnc:listviewitem]$setCheckable[/classfnc]() must + have been previously called. + + !fn: $isChecked() + Returns the check status of this item. [classfnc:listviewitem]$setCheckable[/classfnc]() must + have been previously called. + + !fn: $firstChild() + Returns the first child item of this listviewitem or $null if this item has no children. + + !fn: $nextSibling() + Returns the next sibling item of this listviewitem or $null if there are no sibling items. + Next sibling stands for the item at the same tree level coming just after :) +*/ + + +//=========================================================================================== + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_listviewitem,"listviewitem","object") + KVSO_REGISTER_HANDLER(KviKvsObject_listviewitem,"setText",function_setText) + KVSO_REGISTER_HANDLER(KviKvsObject_listviewitem,"text",function_text) + KVSO_REGISTER_HANDLER(KviKvsObject_listviewitem,"setPixmap",function_setPixmap); + KVSO_REGISTER_HANDLER(KviKvsObject_listviewitem,"setRenameEnabled",function_setRenameEnabled); + KVSO_REGISTER_HANDLER(KviKvsObject_listviewitem,"setEnabled",function_setEnabled); + KVSO_REGISTER_HANDLER(KviKvsObject_listviewitem,"isEnabled",function_isEnabled); + KVSO_REGISTER_HANDLER(KviKvsObject_listviewitem,"setOpen",function_setOpen); + KVSO_REGISTER_HANDLER(KviKvsObject_listviewitem,"isOpen",function_isOpen); + KVSO_REGISTER_HANDLER(KviKvsObject_listviewitem,"setCheckable",function_setCheckable); + KVSO_REGISTER_HANDLER(KviKvsObject_listviewitem,"isCheckable",function_isCheckable); + KVSO_REGISTER_HANDLER(KviKvsObject_listviewitem,"setChecked",function_setChecked); + KVSO_REGISTER_HANDLER(KviKvsObject_listviewitem,"isChecked",function_isChecked); + KVSO_REGISTER_HANDLER(KviKvsObject_listviewitem,"firstChild",function_firstChild); + KVSO_REGISTER_HANDLER(KviKvsObject_listviewitem,"nextSibling",function_nextSibling); +KVSO_END_REGISTERCLASS(KviKvsObject_listviewitem) + + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_listviewitem,KviKvsObject) + + m_pListViewItem = 0; + +KVSO_END_CONSTRUCTOR(KviKvsObject_listviewitem) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_listviewitem) + + if(m_pListViewItem)delete m_pListViewItem; + +KVSO_END_CONSTRUCTOR(KviKvsObject_listviewitem) + +bool KviKvsObject_listviewitem::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + if (!parentObject()) + { + pContext->error(__tr2qs("The listviewitem cannot be parentless")); + return false; + } + if(parentObject()->inherits("KviKvsObject_listviewitem")) + { + m_pListViewItem = new KviKvsMdmStandardListViewItem(this,((KviKvsObject_listviewitem *)parentObject())->m_pListViewItem); + } else { + if(parentObject()->inherits("KviKvsObject_listview")) + m_pListViewItem = new KviKvsMdmStandardListViewItem(this,((KviTalListView *)parentScriptWidget())); + else { + pContext->error(__tr2qs("The parent of the listviewitem must be either another listviewitem or a listview")); + return false; + } + } + return true; +} + +void KviKvsObject_listviewitem::childDestroyed() +{ + if(m_pListViewItem == 0)return; + m_pListViewItem = 0; + die(); +} + +KviKvsMdmStandardListViewItem::KviKvsMdmStandardListViewItem(KviKvsObject_listviewitem * ob,KviTalListView * par) +:KviTalListViewItem(par), m_pMasterObject(ob) +{ +} + +KviKvsMdmStandardListViewItem::KviKvsMdmStandardListViewItem(KviKvsObject_listviewitem * ob,KviTalListViewItem * par) +:KviTalListViewItem(par), m_pMasterObject(ob) +{ +} + +KviKvsMdmStandardListViewItem::~KviKvsMdmStandardListViewItem() +{ + if(m_pMasterObject)m_pMasterObject->childDestroyed(); +} + + + +KviKvsMdmCheckListViewItem::KviKvsMdmCheckListViewItem(KviKvsObject_listviewitem * ob,KviTalListView * par) +:KviTalCheckListItem(par,QString::null,KviTalCheckListItem::CheckBox), m_pMasterObject(ob) +{ +} + +KviKvsMdmCheckListViewItem::KviKvsMdmCheckListViewItem(KviKvsObject_listviewitem * ob,KviTalListViewItem * par) +:KviTalCheckListItem(par,QString::null,KviTalCheckListItem::CheckBox), m_pMasterObject(ob) +{ +} + +KviKvsMdmCheckListViewItem::~KviKvsMdmCheckListViewItem() +{ + if(m_pMasterObject)m_pMasterObject->childDestroyed(); +} + + +kvs_hobject_t KviKvsObject_listviewitem::itemToHandle(KviTalListViewItem * it) +{ + if(!it)return (kvs_hobject_t)0; + KviKvsObject_listviewitem * pObject; + if(it->rtti() == 1)pObject = ((KviKvsMdmCheckListViewItem *)it)->masterObject(); + else pObject = ((KviKvsMdmStandardListViewItem *)it)->masterObject(); + if(!pObject)return (kvs_hobject_t)0; + return pObject->handle(); +} + + +bool KviKvsObject_listviewitem::function_setText(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uCol; + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if(m_pListViewItem) + m_pListViewItem->setText(uCol,szText); + return true; +} + +bool KviKvsObject_listviewitem::function_firstChild(KviKvsObjectFunctionCall *c) +{ + if(m_pListViewItem) + c->returnValue()->setHObject(itemToHandle(m_pListViewItem->firstChild())); + else + c->returnValue()->setHObject((kvs_hobject_t)0); + return true; +} + +bool KviKvsObject_listviewitem::function_nextSibling(KviKvsObjectFunctionCall *c) +{ + if(m_pListViewItem) + c->returnValue()->setHObject(itemToHandle(m_pListViewItem->nextSibling())); + else + c->returnValue()->setHObject((kvs_hobject_t)0); + return true; +} + + +bool KviKvsObject_listviewitem::function_setRenameEnabled(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uCol; + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(m_pListViewItem) + m_pListViewItem->setRenameEnabled(uCol,bEnabled); + return true; +} + +bool KviKvsObject_listviewitem::function_setEnabled(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(m_pListViewItem) + m_pListViewItem->setEnabled(bEnabled); + return true; +} + +bool KviKvsObject_listviewitem::function_isEnabled(KviKvsObjectFunctionCall *c) +{ + if(!m_pListViewItem) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(m_pListViewItem->isEnabled()); + return true; +} + +bool KviKvsObject_listviewitem::function_setOpen(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(m_pListViewItem) + m_pListViewItem->setOpen(bEnabled); + return true; +} + +bool KviKvsObject_listviewitem::function_isOpen(KviKvsObjectFunctionCall *c) +{ + if(!m_pListViewItem) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(m_pListViewItem->isOpen()); + return true; +} + + +bool KviKvsObject_listviewitem::function_setChecked(KviKvsObjectFunctionCall *c) +{ + bool bChecked; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bChecked",KVS_PT_BOOL,0,bChecked) + KVSO_PARAMETERS_END(c) + if(!m_pListViewItem)return true; + if(m_pListViewItem->rtti() != 1)return true; // not a QCheckListItem + ((KviKvsMdmCheckListViewItem *)m_pListViewItem)->setOn(bChecked); + return true; +} + +bool KviKvsObject_listviewitem::function_isChecked(KviKvsObjectFunctionCall *c) +{ + if(!m_pListViewItem) + { + c->returnValue()->setBoolean(false); + return true; + } + if(m_pListViewItem->rtti() != 1) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(((KviKvsMdmCheckListViewItem *)m_pListViewItem)->isOn()); + return true; +} + +bool KviKvsObject_listviewitem::function_setCheckable(KviKvsObjectFunctionCall *c) +{ + bool bCheckable; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bCheckable",KVS_PT_BOOL,0,bCheckable) + KVSO_PARAMETERS_END(c) + if(!m_pListViewItem)return true; + if(bCheckable) + { + if(m_pListViewItem->rtti() == 1)return true; // a QCheckListItem already + KviTalListViewItem * pParent = m_pListViewItem->parent(); + KviTalListView * pLV = (KviTalListView *)m_pListViewItem->listView(); + // swap the items, so we don't die now + KviTalListViewItem * pThis = m_pListViewItem; + m_pListViewItem = 0; + delete pThis; + if(pParent) + m_pListViewItem = new KviKvsMdmCheckListViewItem(this,pParent); + else + m_pListViewItem = new KviKvsMdmCheckListViewItem(this,pLV); + } else { + if(m_pListViewItem->rtti() != 1)return true; // not a QCheckListItem yet + KviTalListViewItem * pParent = m_pListViewItem->parent(); + KviTalListView * pLV = (KviTalListView *)m_pListViewItem->listView(); + // swap the items, so we don't die now + KviTalListViewItem * pThis = m_pListViewItem; + m_pListViewItem = 0; + delete pThis; + if(pParent) + m_pListViewItem = new KviKvsMdmStandardListViewItem(this,pParent); + else + m_pListViewItem = new KviKvsMdmStandardListViewItem(this,pLV); + } + return true; +} + +bool KviKvsObject_listviewitem::function_isCheckable(KviKvsObjectFunctionCall *c) +{ + if(!m_pListViewItem) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(m_pListViewItem->rtti() == 1); + return true; +} + +bool KviKvsObject_listviewitem::function_text(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETERS_END(c) + if(m_pListViewItem) + c->returnValue()->setString(m_pListViewItem->text(uCol)); + return true; +} + +bool KviKvsObject_listviewitem::function_setPixmap(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uCol; + KviKvsObject *obPixmap; + kvs_hobject_t obHpixmap; + KviKvsVariant * vPixmap; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("pixmap",KVS_PT_VARIANT,0,vPixmap) + KVSO_PARAMETERS_END(c) + QPixmap *pix = 0; + if(vPixmap->isHObject()) + { + vPixmap->asHObject(obHpixmap); + obPixmap=KviKvsKernel::instance()->objectController()->lookupObject(obHpixmap); + if (!obPixmap->inherits("KviKvsObject_pixmap")) + { + c->warning(__tr2qs("Pixmap object or image Id required")); + return true; + } + pix=((KviKvsObject_pixmap *)obPixmap)->getPixmap(); + } else { + QString szPix; + vPixmap->asString(szPix); + pix=g_pIconManager->getImage(szPix); + if(!pix) + { + c->warning(__tr2qs("Error occured: the suitable file '%Q' is not of the correct format or it is not a valid icon number."),&szPix); + return true; + } + } + m_pListViewItem->setPixmap(uCol,*pix); + return true; +} + +#include "m_class_listviewitem.moc" diff --git a/src/modules/objects/class_listviewitem.h b/src/modules/objects/class_listviewitem.h new file mode 100644 index 00000000..eb806324 --- /dev/null +++ b/src/modules/objects/class_listviewitem.h @@ -0,0 +1,88 @@ +#ifndef _CLASS_LISTVIEWITEM_H_ +#define _CLASS_LISTVIEWITEM_H_ +//mdm: +// File : class_ListViewItem.h +// Creation date : Thu Feb 1 14:39:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 "kvi_tal_listview.h" +#include "class_widget.h" + + + +#include "object_macros.h" + +class KviKvsObject_listviewitem : public KviKvsObject +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_listviewitem) + void childDestroyed(); +protected: + KviTalListViewItem * m_pListViewItem; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); +protected: + bool function_setText(KviKvsObjectFunctionCall *c); + bool function_insertItem(KviKvsObjectFunctionCall *c); + bool function_setPixmap(KviKvsObjectFunctionCall *c); + bool function_setRenameEnabled(KviKvsObjectFunctionCall *c); + bool function_setEnabled(KviKvsObjectFunctionCall *c); + bool function_isEnabled(KviKvsObjectFunctionCall *c); + bool function_setOpen(KviKvsObjectFunctionCall *c); + bool function_isOpen(KviKvsObjectFunctionCall *c); + bool function_text(KviKvsObjectFunctionCall *c); + bool function_setCheckable(KviKvsObjectFunctionCall *c); + bool function_isCheckable(KviKvsObjectFunctionCall *c); + bool function_setChecked(KviKvsObjectFunctionCall *c); + bool function_isChecked(KviKvsObjectFunctionCall *c); + bool function_firstChild(KviKvsObjectFunctionCall *c); + bool function_nextSibling(KviKvsObjectFunctionCall *c); +public: + static kvs_hobject_t itemToHandle(KviTalListViewItem * it); +}; + + + +class KviKvsMdmStandardListViewItem : public KviTalListViewItem +{ +public: + KviKvsMdmStandardListViewItem(KviKvsObject_listviewitem * ob,KviTalListView * par); + KviKvsMdmStandardListViewItem(KviKvsObject_listviewitem * ob,KviTalListViewItem * par); + virtual ~KviKvsMdmStandardListViewItem(); +protected: + KviKvsObject_listviewitem * m_pMasterObject; +public: + KviKvsObject_listviewitem * masterObject(){ return m_pMasterObject; } +}; + +class KviKvsMdmCheckListViewItem : public KviTalCheckListItem +{ +public: + KviKvsMdmCheckListViewItem(KviKvsObject_listviewitem * ob,KviTalListView * par); + KviKvsMdmCheckListViewItem(KviKvsObject_listviewitem * ob,KviTalListViewItem * par); + virtual ~KviKvsMdmCheckListViewItem(); +protected: + KviKvsObject_listviewitem * m_pMasterObject; +public: + KviKvsObject_listviewitem * masterObject(){ return m_pMasterObject; } +}; + +#endif // !_CLASS_LISTVIEWITEM_H_ diff --git a/src/modules/objects/class_mainwindow.cpp b/src/modules/objects/class_mainwindow.cpp new file mode 100644 index 00000000..e30f480b --- /dev/null +++ b/src/modules/objects/class_mainwindow.cpp @@ -0,0 +1,158 @@ +//mdm: +// File : class_mainwindow.cpp +// Creation date : Mon Feb 28 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 "kvi_tal_mainwindow.h" +#include "class_mainwindow.h" +#include "kvi_error.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_iconmanager.h" + + +/* + @doc: mainwindow + @keyterms: + mainwindow object class, + @title: + mainwindow class + @type: + class + @short: + Provides a mainwindow. + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + The mainwindow class provides a main application window, with menubar, toolbars. + @functions: + !fn: $setCentralWidget() + Sets the central widget for the main window to . +*/ + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_mainwindow,"mainwindow","widget") + KVSO_REGISTER_HANDLER(KviKvsObject_mainwindow,"setCentralWidget",functionsetCentralWidget) + KVSO_REGISTER_HANDLER(KviKvsObject_mainwindow,"setDockEnabled",functionsetDockEnabled) + KVSO_REGISTER_HANDLER(KviKvsObject_mainwindow,"isDockEnabled",functionisDockEnabled) + +KVSO_END_REGISTERCLASS(KviKvsObject_mainwindow) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_mainwindow,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_mainwindow) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_mainwindow) + +KVSO_END_CONSTRUCTOR(KviKvsObject_mainwindow) + +bool KviKvsObject_mainwindow::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + setObject(new KviTalMainWindow(parentScriptWidget(), name()), true); + return true; +} + +bool KviKvsObject_mainwindow::functionsetCentralWidget(KviKvsObjectFunctionCall *c) +{ + KviKvsObject * pObject; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!pObject) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!pObject->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!pObject->object()->inherits("KviKvsObject_widget")) + { + c->warning(__tr2qs("Widget object required")); + return TRUE; + } + if(widget()) ((KviTalMainWindow *)widget())->setCentralWidget(((QWidget *)(pObject->object()))); + return true; +} +bool KviKvsObject_mainwindow::functionsetDockEnabled(KviKvsObjectFunctionCall *c) +{ + QString szDockarea; + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("dock area",KVS_PT_STRING,0,szDockarea) + KVSO_PARAMETER("bool enabled",KVS_PT_BOOL,0,bFlag) + KVSO_PARAMETERS_END(c) + if(widget()) + { +#ifndef COMPILE_USE_QT4 + if(KviQString::equalCI(szDockarea,"Top")) + ((KviTalMainWindow *)widget())->setDockEnabled(Qt::DockTop,bFlag); + else if(KviQString::equalCI(szDockarea,"Left")) + ((KviTalMainWindow *)widget())->setDockEnabled(Qt::DockLeft,bFlag); + else if(KviQString::equalCI(szDockarea,"Right")) + ((KviTalMainWindow *)widget())->setDockEnabled(Qt::DockRight,bFlag); + else if(KviQString::equalCI(szDockarea,"Bottom")) + ((KviTalMainWindow *)widget())->setDockEnabled(Qt::DockBottom,bFlag); + else if(KviQString::equalCI(szDockarea,"Minimized")) + ((KviTalMainWindow *)widget())->setDockEnabled(Qt::DockMinimized,bFlag); + else if(KviQString::equalCI(szDockarea,"TornOff")) + ((KviTalMainWindow *)widget())->setDockEnabled(Qt::DockTornOff,bFlag); + else if(KviQString::equalCI(szDockarea,"Unmanaged")) + ((KviTalMainWindow *)widget())->setDockEnabled(Qt::DockUnmanaged,bFlag); + else c->warning(__tr2qs("Unknown dock area '%Q'"),&szDockarea); +#endif + } + return true; + +} +bool KviKvsObject_mainwindow::functionisDockEnabled(KviKvsObjectFunctionCall *c) +{ + + QString szDockarea; + bool bFlag = false; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("dock_area",KVS_PT_STRING,0,szDockarea) + KVSO_PARAMETERS_END(c) + if(!widget()) return true; +#ifndef COMPILE_USE_QT4 + if(KviQString::equalCI(szDockarea,"Top")) bFlag=((KviTalMainWindow *)widget())->isDockEnabled(Qt::DockTop); + else if(KviQString::equalCI(szDockarea,"Left")) bFlag=((KviTalMainWindow *)widget())->isDockEnabled(Qt::DockLeft); + else if(KviQString::equalCI(szDockarea,"Right")) bFlag=((KviTalMainWindow *)widget())->isDockEnabled(Qt::DockRight); + else if(KviQString::equalCI(szDockarea,"Bottom"))bFlag=((KviTalMainWindow *)widget())->isDockEnabled(Qt::DockBottom); + else if(KviQString::equalCI(szDockarea,"Minimized")) bFlag=((KviTalMainWindow *)widget())->isDockEnabled(Qt::DockMinimized); + else if(KviQString::equalCI(szDockarea,"TornOff")) bFlag=((KviTalMainWindow *)widget())->isDockEnabled(Qt::DockTornOff); + else if(KviQString::equalCI(szDockarea,"Unmanaged")) bFlag=((KviTalMainWindow *)widget())->isDockEnabled(Qt::DockUnmanaged); + else + { + c->warning(__tr2qs("Unknown dock area '%Q'"),&szDockarea); + return true; + } +#endif + c->returnValue()->setBoolean(bFlag); + return true; + +} diff --git a/src/modules/objects/class_mainwindow.h b/src/modules/objects/class_mainwindow.h new file mode 100644 index 00000000..7afddf8c --- /dev/null +++ b/src/modules/objects/class_mainwindow.h @@ -0,0 +1,47 @@ +#ifndef _CLASS_MAINWINDOW_H_ +#define _CLASS_MAINWINDOW_H_ +// +// File : class_mainwindow.h +// Creation date : Fri Jan 28 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 +#include "class_widget.h" +#include "object_macros.h" + +class KviKvsObject_mainwindow : public KviKvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KviKvsObject_mainwindow) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool functionsetCentralWidget(KviKvsObjectFunctionCall *c); + bool functionsetDockEnabled(KviKvsObjectFunctionCall *c); + bool functionisDockEnabled(KviKvsObjectFunctionCall *c); + +}; + + +#endif //!_CLASS_MAINWINDOW_H_ + diff --git a/src/modules/objects/class_menubar.cpp b/src/modules/objects/class_menubar.cpp new file mode 100644 index 00000000..90ad0e7d --- /dev/null +++ b/src/modules/objects/class_menubar.cpp @@ -0,0 +1,76 @@ +// +// File : class_menubar.cpp +// Creation date : Tue Now 26 13:16:59 CEST 2002 by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2002 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 "class_menubar.h" +#include "kvi_error.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" + +/* + @doc: menubar + @title: + menubar class + @type: + class + @short: + A menu bar object implementation + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + + @functions: + !fn: $insertItem() + Returns an integer that identifies the inserted item. +*/ + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_menubar,"menubar","widget") + KVSO_REGISTER_HANDLER(KviKvsObject_menubar,"inserItem",functionInsertItem) +KVSO_END_REGISTERCLASS(KviKvsObject_menubar) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_menubar,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_menubar) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_menubar) + +KVSO_END_CONSTRUCTOR(KviKvsObject_menubar) + +bool KviKvsObject_menubar::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + setObject(new QMenuBar(parentScriptWidget(), name())); + return true; +} + +bool KviKvsObject_menubar::functionInsertItem(KviKvsObjectFunctionCall *c) +{ + QString szItem; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("item",KVS_PT_STRING,0,szItem) + KVSO_PARAMETERS_END(c) + if (widget()) ((QMenuBar *)widget())->insertItem(szItem); + return true; +} diff --git a/src/modules/objects/class_menubar.h b/src/modules/objects/class_menubar.h new file mode 100644 index 00000000..c959d272 --- /dev/null +++ b/src/modules/objects/class_menubar.h @@ -0,0 +1,40 @@ +#ifndef _CLASS_MENUBAR_H_ +#define _CLASS_MENUBAR_H_ +// +// File : class_menubar.h +// Creation date : Tue Now 26 13:15:48 CEST 2002 by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2002 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 +#include "class_widget.h" +#include "object_macros.h" + +class KviKvsObject_menubar : public KviKvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KviKvsObject_menubar) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool functionInsertItem(KviKvsObjectFunctionCall *c); +}; +#endif // !_CLASS_MENUBAR_H_ diff --git a/src/modules/objects/class_multilineedit.cpp b/src/modules/objects/class_multilineedit.cpp new file mode 100644 index 00000000..6b2f8af9 --- /dev/null +++ b/src/modules/objects/class_multilineedit.cpp @@ -0,0 +1,1217 @@ +//vim: ts=8 +// File : class_multilineedit.cpp +// Creation date : Mon Feb 19 00:45:34 CET by Krzysztof Godlewski +// +// Modification date: Thu 15 Feb 2005 22:00 :00 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 "kvi_error.h" +#include "kvi_debug.h" +#include "kvi_locale.h" +#include "kvi_malloc.h" +#include +#ifdef COMPILE_USE_QT4 + #include +#include + +#include +#define KviTalMultiLineEdit Q3MultiLineEdit +#define QTEXTEDIT_AUTO_ALL Q3TextEdit::AutoAll +#define QTEXTEDIT_AUTO_NONE Q3TextEdit::AutoNone +#define QTEXTEDIT_AUTO_BULLET_LIST Q3TextEdit::AutoBulletList + +#else + #include + + #include + #define KviTalMultiLineEdit QMultiLineEdit + #define QTEXTEDIT_AUTO_ALL QTextEdit::AutoAll + #define QTEXTEDIT_AUTO_NONE QTextEdit::AutoNone + #define QTEXTEDIT_AUTO_BULLET_LIST QTextEdit::AutoBulletList + +#endif + + +#include "class_multilineedit.h" + + +//->Tables for Text Format +static char * const mod_tbl[] = { + "PlainText", + "RichText", + "AutoText", + "LogText" + }; + +static int mod_cod[] = { + Qt::PlainText, + Qt::RichText, + Qt::AutoText, + Qt::LogText + }; + +#define mod_num (sizeof(mod_tbl) / sizeof(mod_tbl[0])) + + + +/* + @doc: multilineedit + @keyterms: + multilineedit object class, line editor, input + @title: + multilineedit class + @type: + class + @short: + An editor for inputting larger portions of text + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + This is class an editor for inputting larger portions of text. + Besides that, it has unfinished docs. + @functions: + !fn: $textLine() + Returns the string at line . Note that it can be an empty + string. + !fn: $insertLine(, ) + Inserts at line number . If line is less than + zero, or larger than the number of rows, the new text is + put at the end. If txt contains newline characters, several + lines are inserted. The parameter is optional. If it is + ommited, the line is put at end. + !fn: $removeLine() + Removes line number . + !fn: $insertAt(, , ) + Inserts txt at line number line, after character number col in + the line. If txt contains newline characters, new lines are + inserted. + !fn: $numLines() + Returns number of lines in the widget. + !fn: $setCursorPosition(, , ) + Sets the cursor position to character number col in line + number line. The parameters are adjusted to lie within the + legal range.[br] + If mark is 1, the selection is cleared. otherwise it + is extended + !fn: $cursorPosition() + Returns current cursor position in ", " format. + !fn: $setReadOnly() + Sets the editor to be read-only if bReadOnly is 1 or + removes the read-only status is ReadOnly is 0 + !fn: $atBeginning() + Returns 1(TRUE) if the cursor is placed at the beginning of the text; otherwise returns 0(FALSE). + !fn: $atEnd() + Returns 1(TRUE) if the cursor is placed at the end of the text; otherwise returns 0(FALSE). + !fn: $setWordWrap() + Sets the word wrap mode to mode. Valid Values are:[br] + - NoWrap - Do not wrap the text.[br] + - WidgetWidth - Wrap the text at the current width of the widget.[br] + - FixedPixelWidth - Wrap the text at a fixed number of pixels from the widget's left side.[br] + - FixedColumnWidth - Wrap the text at a fixed number of character columns from the widget's left side. + !fn: $wordWrap() + Returns the word wrap mode. NoWrap, WidgetWidth, FixedPixelWidth, FixedColumnWidth. + !fn: $text() + Returns the multiline edit's text. + !fn: $length() + Returns the number of characters in the text This function ignores newlines. + !fn: $setMaxLines() + Sets the max number of the lines to + !fn: $maxLines() + Returns the max number of the lines in the multiline edit. + !fn: $insert() + Inserts text at the current cursor position. + !fn: $append() + Appends a new paragraph with text to the end of the multiline edit. + !fn: $copy() + Copies any selected text from selection to the clipboard. + !fn: $cut() + Copies the selected text from selection to the clipboard and deletes it from the multiline edit. + !fn: $paste() + Pastes the text from the clipboard into the multiline edit at the current cursor position. + !fn: $setFamily() + Sets the font family of the current format to fontFamily. + !fn: $setItalic() + If the bool value is 1 sets the current format to italic; otherwise, if it's 0 sets the current format to no-italic. + !fn: $setBold() + If the bool value is 1 sets the current format to bold; otherwise, if it's 0 sets the current format to no-bold. + !fn: $setUnderline() + If the bool value is 1 sets the current format to underline; otherwise, if it's 0 sets the current format to no-underline. + !fn: $italic() + Returns 1(TRUE) if the current format is italic; otherwise returns 0(FALSE). + !fn: $bold() + Returns 1(TRUE) if the current format is bold; otherwise returns 0(FALSE). + !fn: $underline() + Returns 1(TRUE) if the current format is underline; otherwise returns 0(FALSE). + !fn: $zoomIn() + Zooms in on the text by making the base font size range points larger. + !fn: $zoomOut() + Zooms out on the text by making the base font size range points smaller. + !fn: $zoomTo() + Zooms the text by making the base font size points. + !fn: $undo() + Undoes the last operation. + !fn: $redo() + Redoes the last operation. + !fn: $clear() + Deletes all the text in the multiline edit. + !fn: $setUndoRedoEnabled() + Sets whether undo/redo is enabled to the bool value. + !fn: $setUndoDepth() + Sets the depth of the undo history to x. + !fn: $isUndoRedoEnabled() + Returns 1 (TRUE) if undo/redo is enabled; otherwise returns 0 (FALSE). + !fn: $undoDepth() + Returns the depth of the undo history. + !fn: $indent() + Re-indents the current paragraph. + !fn: $setText() + Sets the text edit's text to txt. + !fn: $setPointSize() + Sets the foreground color of this widget to :valid values are: + - hex string: must be a string with 6 hexadecimal digits (like the ones used to + specify colors in html pages). The first two digits specify + the RED component, the third and fourth digit specify the GREEN component + and the last two specify the BLUE component. + For example "FFFF00" means full red, full green and no blue that gives + a yellow color, "808000" designates a brown color (dark yellow), + "A000A0" is a kind of violet. + - array(red:integer,green:integer,blue:integer) + - red:integer,green:integer,blue:integer. + !fn: $setModified() + Sets whether the document has been modified by the user. Valid Values are 1(TRUE) or 0(FALSE) + !fn: $insertParagraph(,) + Inserts text as a new paragraph at position . + !fn: $removeParagraph() + Removes the paragraph . + !fn: $setLinkUnderline() + Sets to 1 if you want that hypertext links will be underlined; otherwise sets to 0. + !fn: $setOverwriteMode() + Sets the Multilineedit edit's overwrite mode to b (1=Enabled or 0=Disabled) . + !fn: $setTextFormat() + Sets the text format. Correct values are RichText, PlainText, LogText or AutoText. + !fn: $textFormat() + Returns the text format: rich text, plain text, log text or auto text. + // findme + !fn: $setParagraphBackgroundColor(,) + Sets the background color of the paragraph to color value specified.[br] + Example: %mymultiline->$setParagraphBackgroundColor(2,0C686F) + !fn: $clearParagraphBackground() + Clear the background color of the paragraph . + !fn: $loadFile() + Load the file specified in the , also html files. + !fn: $isUndoAvailable () + Returns 1(TRUE) if undo is available; otherwise returns 0(FALSE). + !fn: $isRedoAvailable () + Returns 1(TRUE) if redo is available; otherwise returns 0(FALSE). + !fn: $setAlignment() + Sets the alignment of the current paragraph to . Valid values are:[br] + - AlignAuto - Aligns according to the language.[br] + - Qt::AlignLeft - Aligns with the left edge.[br] + - Qt::AlignRight - Aligns with the right edge.[br] + - Qt::AlignCenter - Centers in both dimensions. + !fn: $setVerticalAlignment() + Sets the vertical alignment of the current format to . Valid Values are:[br] + - AlignNormal - Normal alignment.[br] + - AlignSuperScript - Superscript.[br] + - AlignSubScript - Subscript. + !fn: $setAutoFormatting() + Sets the enabled set of auto formatting features to afvalue. Valid values are: [br] + - AutoNone - Do not perform any automatic formatting[br] + - AutoBulletList - Only automatically format bulletted lists[br] + - AutoAll - Apply all available autoformatting + !fn: $setWrapPolicy() + Sets the word wrap policy, at . Valid values are:[br] + - AtWhiteSpace - Don't use this deprecated value (it is a synonym for AtWordBoundary which you should use instead).[br] + - Anywhere - Break anywhere, including within words.[br] + - AtWordBoundary - Break lines at word boundaries, e.g. spaces or newlines[br] + - AtWordOrDocumentBoundary - Break lines at whitespace, e.g. spaces or newlines if possible. Break it anywhere otherwise.[br] + !fn: $paragraphs() + Returns the number of paragraphs in the text. + !fn: $lines() + Returns the number of lines in the multilineedit. + !fn: $linesOfParagraph() + Returns the number of lines in paragraph , or -1 if there is no paragraph with index . + !fn: $lineOfChar(,) + Returns the line number of the line in paragraph par in which the character at position index appears.[br] + If there is no such paragraph or no such character at the index position -1 is returned. + !fn: $paragraphLenght() + Returns the length of the paragraph par, or -1 if there is no paragraph with index par. + +*/ + + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_mledit,"multilineedit","widget") + + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"textLine", functionTextLine) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"insertLine", functionInsertLine) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"removeLine", functionRemoveLine) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"insertAt", functionInsertAt) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"numLines", functionNumLines) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setCursorPosition", functionSetCursorPosition) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"cursorPosition", functionCursorPosition) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"atBeginning", functionAtBeginning) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"atEnd", functionAtEnd) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setWordWrap", functionSetWordWrap) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"wordWrap", functionWordWrap) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"text", functionText) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"length", functionLength); + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setMaxLines", functionSetMaxLines) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"maxLines", functionMaxLines) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"insert", functionInsert) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"append", functionAppend) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"copy", functionCopy) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"cut", functionCut) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"paste", functionPaste) + +//->Set Style + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setFamily" , functionsetFamily) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setItalic", functionsetItalic) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setBold", functionsetBold) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setUnderline", functionsetUnderline) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"italic", functionitalic) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"bold", functionbold) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"underline", functionunderline) +//->Zoom In, Out, To + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"zoomIn", functionzoomIn) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"zoomOut", functionzoomOut) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"zoomTo", functionzoomTo) +//->Undo & Redo + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"undo", functionundo) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"redo", functionredo) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"del", functiondel) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"clear", functionclear) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setUndoRedoEnabled", functionsetUndoRedoEnabled) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setUndoDepth", functionsetUndoDepth) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"isUndoRedoEnabled", functionsetUndoRedoEnabled) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"undoDepth", functionundoDepth) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"indent", functionundoDepth) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"isUndoAvailable", functionisUndoAvailable) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"isUndoRedoAvailable", functionisRedoAvailable) +//->Text color & others + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setText", functionsetText) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setPointSize", functionsetPointSize) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setColor", functionsetColor) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setModified" , functionsetModified) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setLinkUnderline" , functionsetLinkUnderline) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setOverwriteMode" , functionsetOverwriteMode) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setReadOnly",functionSetReadOnly) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setTextFormat" , functionsetTextFormat) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"textFormat" , functiontextFormat) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setParagraphBackgroundColor", functionsetParagraphBackgroundColor) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"clearParagraphBackgroundColor", functionsetParagraphBackgroundColor) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"loadFile" , functionloadFile); // let's fantasy + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setAlignment" , functionsetAlignment) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setAutoFormatting" , functionsetAutoFormatting) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setVerticalAlignment" , functionsetVerticalAlignment) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"setWrapPolicy" , functionsetWrapPolicy) +//->Paragraph & line + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"paragraphs" , functionparagraphs) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"paragraphLength" , functionparagraphLength) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"insertParagraph" , functioninsertParagraph) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"removeParagraph" , functionremoveParagraph) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"lines" , functionlines) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"lineOfChar" , functionlineOfChar) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"linesOfParagraph" , functionlinesOfParagraph) + KVSO_REGISTER_HANDLER(KviKvsObject_mledit,"selectAll" , functionselectAll) + + +KVSO_END_REGISTERCLASS(KviKvsObject_mledit) + + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_mledit,KviKvsObject_widget) + + +KVSO_END_CONSTRUCTOR(KviKvsObject_mledit) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_mledit) + +KVSO_END_CONSTRUCTOR(KviKvsObject_mledit) + +bool KviKvsObject_mledit::init(KviKvsRunTimeContext * pContext,KviKvsVariantList * pParams) +{ + setObject(new KviTalMultiLineEdit(parentScriptWidget(),getName()),true); + return true; +} + + +bool KviKvsObject_mledit::functionSetReadOnly(KviKvsObjectFunctionCall *c) + +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((KviTalMultiLineEdit *)widget())->setReadOnly(bEnabled); + return true; +} + + +bool KviKvsObject_mledit::functionTextLine(KviKvsObjectFunctionCall *c) + +{ + kvs_int_t iLine; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("line",KVS_PT_INT,0,iLine) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + if(iLine > ((KviTalMultiLineEdit *)widget())->numLines() || iLine < 0) c->warning(__tr2qs("No such line number")); + else + c->returnValue()->setString(((KviTalMultiLineEdit *)widget())->textLine(iLine)); + return true; +} + +bool KviKvsObject_mledit::functionInsertLine(KviKvsObjectFunctionCall *c) + +{ + kvs_int_t iLine; + QString szInsert; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szInsert) + KVSO_PARAMETER("line",KVS_PT_INT,KVS_PF_OPTIONAL,iLine) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + ((KviTalMultiLineEdit *)widget())->insertLine(szInsert,iLine); + return true; +} + +bool KviKvsObject_mledit::functionRemoveLine(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iLine; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("line",KVS_PT_INT,0,iLine) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + if(iLine > ((KviTalMultiLineEdit *)widget())->numLines() || iLine < 0) + c->warning("No such line number"); + else ((KviTalMultiLineEdit *)widget())->removeLine(iLine); + return true; +} + +bool KviKvsObject_mledit::functionInsertAt(KviKvsObjectFunctionCall *c) + +{ + kvs_uint_t iLine,iCol; + QString szInsert; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szInsert) + KVSO_PARAMETER("line",KVS_PT_UNSIGNEDINTEGER,0,iLine) + KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,iCol) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + if(iLine < 0 || iCol < 0 || iLine > ((KviTalMultiLineEdit *)widget())->numLines()) + c->warning("No such line number"); + else + ((KviTalMultiLineEdit *)widget())->insertAt(szInsert,iLine,iCol); + return true; +} + +bool KviKvsObject_mledit::functionNumLines(KviKvsObjectFunctionCall *c) + +{ + if(widget()) c->returnValue()->setInteger(((KviTalMultiLineEdit *)widget())->numLines()); + return true; +} + +bool KviKvsObject_mledit::functionSetCursorPosition(KviKvsObjectFunctionCall *c) +{ + + bool bFlag; + kvs_uint_t iLine,iCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("line",KVS_PT_UNSIGNEDINTEGER,0,iLine) + KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,iCol) + KVSO_PARAMETER("mark",KVS_PT_BOOL,0,bFlag) + KVSO_PARAMETERS_END(c) + if(widget()) + ((KviTalMultiLineEdit *)widget())->setCursorPosition(iLine, iCol, bFlag); + return true; +} + +bool KviKvsObject_mledit::functionCursorPosition(KviKvsObjectFunctionCall *c) +{ + if(!widget()) return true; + int line, col; + #if QT_VERSION >= 300 + ((KviTalMultiLineEdit *)widget())->getCursorPosition(&line, &col); + #else + ((KviTalMultiLineEdit *)widget())->cursorPosition(&line, &col); + #endif + KviKvsArray * a = new KviKvsArray(); + a->set(0,new KviKvsVariant((kvs_int_t)line)); + a->set(1,new KviKvsVariant((kvs_int_t)col)); + c->returnValue()->setArray(a); + return true; +} + +bool KviKvsObject_mledit::functionAtBeginning(KviKvsObjectFunctionCall *c) +{ + if(!widget()) return true; + c->returnValue()->setBoolean(((KviTalMultiLineEdit *)widget())->atBeginning()); + return true; +} + +bool KviKvsObject_mledit::functionAtEnd(KviKvsObjectFunctionCall *c) +{ + if(!widget()) return true; + c->returnValue()->setBoolean(((KviTalMultiLineEdit *)widget())->atEnd()); + return true; +} + +bool KviKvsObject_mledit::functionSetWordWrap(KviKvsObjectFunctionCall *c) +{ + if(!widget())return true; + QString szWrap; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("word_wrap",KVS_PT_STRING,0,szWrap) + KVSO_PARAMETERS_END(c) + if(KviQString::equalCI(szWrap,"NoWrap")) + ((KviTalMultiLineEdit *)widget())->setWordWrap(KviTalMultiLineEdit::NoWrap); + else if(KviQString::equalCI(szWrap,"WidgetWidth")) + ((KviTalMultiLineEdit *)widget())->setWordWrap(KviTalMultiLineEdit::WidgetWidth); + else if(KviQString::equalCI(szWrap,"FixedPixelWidth")) + ((KviTalMultiLineEdit *)widget())->setWordWrap(KviTalMultiLineEdit::FixedPixelWidth); + else if(KviQString::equalCI(szWrap,"FixedColumnWidth")) + ((KviTalMultiLineEdit *)widget())->setWordWrap(KviTalMultiLineEdit::FixedColumnWidth); + else c->warning(__tr2qs("Unknown word wrap '%Q'"),&szWrap); + return true; +} + +bool KviKvsObject_mledit::functionsetWrapPolicy(KviKvsObjectFunctionCall *c) +{ + if(!widget())return true; + QString szPolicy; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("wrap_policy",KVS_PT_STRING,0,szPolicy) + KVSO_PARAMETERS_END(c) + if(KviQString::equalCI(szPolicy,"AtWhiteSpace)")) + ((KviTalMultiLineEdit *)widget())->setWrapPolicy(KviTalMultiLineEdit::AtWhiteSpace); + else if(KviQString::equalCI(szPolicy,"Anywhere")) + ((KviTalMultiLineEdit *)widget())->setWrapPolicy(KviTalMultiLineEdit::Anywhere); + else if(KviQString::equalCI(szPolicy,"AtWordBoundary")) + ((KviTalMultiLineEdit *)widget())->setWrapPolicy(KviTalMultiLineEdit::AtWordBoundary); + else if(KviQString::equalCI(szPolicy,"AtWordOrDocumentBoundary")) + ((KviTalMultiLineEdit *)widget())->setWrapPolicy(KviTalMultiLineEdit::AtWordOrDocumentBoundary); + else c->warning(__tr2qs("Unknown wrap policy'%Q'"),&szPolicy); + return true; +} + +bool KviKvsObject_mledit::functionWordWrap(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setBoolean(((KviTalMultiLineEdit *)widget())->wordWrap() & KviTalMultiLineEdit::WidgetWidth); + return true; +} + +bool KviKvsObject_mledit::functionText(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setString(((KviTalMultiLineEdit *)widget())->text()); + return true; +} + +bool KviKvsObject_mledit::functionLength(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setInteger(((KviTalMultiLineEdit *)widget())->length()); + return true; +} + +bool KviKvsObject_mledit::functionSetMaxLines(KviKvsObjectFunctionCall *c) +{ + + kvs_uint_t imaxLines; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("max_lines",KVS_PT_UNSIGNEDINTEGER,0,imaxLines) + KVSO_PARAMETERS_END(c) + if(widget()) + ((KviTalMultiLineEdit *)widget())->setMaxLines(imaxLines); + return true; +} + +bool KviKvsObject_mledit::functionMaxLines(KviKvsObjectFunctionCall *c) + +{ + if(widget()) + c->returnValue()->setInteger(((KviTalMultiLineEdit *)widget())->maxLines()); + return true; +} + +bool KviKvsObject_mledit::functionInsert(KviKvsObjectFunctionCall *c) + +{ + QString szInsert; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szInsert) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalMultiLineEdit *)widget())->insert(szInsert); + return true; +} + +bool KviKvsObject_mledit::functionAppend(KviKvsObjectFunctionCall *c) + +{ + QString szAppend; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szAppend) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalMultiLineEdit *)widget())->append(szAppend); + return true; +} + +bool KviKvsObject_mledit::functionCopy(KviKvsObjectFunctionCall *c) +{ + if(widget()) + ((KviTalMultiLineEdit *)widget())->copy(); + return true; +} + +bool KviKvsObject_mledit::functionCut(KviKvsObjectFunctionCall *c) +{ + if(widget()) + ((KviTalMultiLineEdit *)widget())->cut(); + return true; +} + +bool KviKvsObject_mledit::functionPaste(KviKvsObjectFunctionCall *c) +{ + if(widget()) + ((KviTalMultiLineEdit *)widget())->paste(); + return true; +} +//->Set Bold, Italic, Underline +bool KviKvsObject_mledit::functionsetBold(KviKvsObjectFunctionCall *c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bBold",KVS_PT_BOOL,0,bFlag) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalMultiLineEdit *)widget())->setBold(bFlag); + return true; +} +bool KviKvsObject_mledit::functionsetUnderline(KviKvsObjectFunctionCall *c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bUnderline",KVS_PT_BOOL,0,bFlag) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalMultiLineEdit *)widget())->setUnderline(bFlag); + return true; +} + +bool KviKvsObject_mledit::functionsetItalic(KviKvsObjectFunctionCall *c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bItalic",KVS_PT_BOOL,0,bFlag) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalMultiLineEdit *)widget())->setItalic(bFlag); + return true; +} + + +//-->Returns Italic , Bold, Underline. +bool KviKvsObject_mledit::functionbold(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setBoolean(((KviTalMultiLineEdit *)widget())->bold()); + return true; +} +bool KviKvsObject_mledit::functionitalic(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setBoolean(((KviTalMultiLineEdit *)widget())->italic()); + return true; +} +bool KviKvsObject_mledit::functionunderline(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setBoolean(((KviTalMultiLineEdit *)widget())->underline()); + return true; +} +//->Zoom In, out at +bool KviKvsObject_mledit::functionzoomIn(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iZoom; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("zoom_value",KVS_PT_INT,KVS_PF_OPTIONAL,iZoom) + KVSO_PARAMETERS_END(c) + if (!widget()) return true; + if (!iZoom) + ((KviTalMultiLineEdit *)object())->zoomIn(); + else + ((KviTalMultiLineEdit *)object())->zoomIn(iZoom); + return true; +} + +bool KviKvsObject_mledit::functionzoomOut(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iZoom; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("zoom_value",KVS_PT_INT,KVS_PF_OPTIONAL,iZoom) + KVSO_PARAMETERS_END(c) + if (!widget()) return true; + if (!iZoom) + ((KviTalMultiLineEdit *)object())->zoomOut(); + else + ((KviTalMultiLineEdit *)object())->zoomOut(iZoom); + return true; +} +bool KviKvsObject_mledit::functionzoomTo(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iZoom; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("zoom_size",KVS_PT_INT,0,iZoom) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalMultiLineEdit *)object())->zoomTo(iZoom); + return true; +} +//-> Undo & Redo functions + +bool KviKvsObject_mledit::functionundo(KviKvsObjectFunctionCall *c) +{ + if(widget()) + ((KviTalMultiLineEdit *)widget())->undo(); + return true; +} +bool KviKvsObject_mledit::functionredo(KviKvsObjectFunctionCall *c) +{ + if(widget()) + ((KviTalMultiLineEdit *)widget())->redo(); + return true; +} +bool KviKvsObject_mledit::functionclear(KviKvsObjectFunctionCall *c) +{ + if(widget()) + ((KviTalMultiLineEdit *)widget())->clear(); + return true; +} +bool KviKvsObject_mledit::functiondel(KviKvsObjectFunctionCall *c) +{ + if(widget()) + ((KviTalMultiLineEdit *)widget())->del(); + return true; +} +bool KviKvsObject_mledit::functionindent(KviKvsObjectFunctionCall *c) +{ + if(widget()) + ((KviTalMultiLineEdit *)widget())->indent(); + return true; +} + +bool KviKvsObject_mledit::functionsetUndoRedoEnabled(KviKvsObjectFunctionCall *c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bUndoredo",KVS_PT_BOOL,0,bFlag) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalMultiLineEdit *)widget())->setUndoRedoEnabled(bFlag); + return true; +} + +bool KviKvsObject_mledit::functionisUndoRedoEnabled(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setBoolean(((KviTalMultiLineEdit *)widget())->isUndoRedoEnabled()); + return true; +} +bool KviKvsObject_mledit::functionisUndoAvailable(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setBoolean(((KviTalMultiLineEdit *)widget())->isUndoAvailable()); + return true; +} +bool KviKvsObject_mledit::functionisRedoAvailable(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setBoolean(((KviTalMultiLineEdit *)widget())->isRedoAvailable()); + return true; +} +bool KviKvsObject_mledit::functionsetUndoDepth(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iDepth; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("undo_depth",KVS_PT_UNSIGNEDINTEGER,0,iDepth) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalMultiLineEdit *)object())->setUndoDepth(iDepth); + return true; + +} +bool KviKvsObject_mledit::functionundoDepth(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setInteger(((KviTalMultiLineEdit *)widget())->undoDepth()); + return true; +} + +//-->Text & Color & Family +// Findme +bool KviKvsObject_mledit::functionsetText(KviKvsObjectFunctionCall *c) +{ + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalMultiLineEdit *)widget())->setText(szText); + return true; +} +bool KviKvsObject_mledit::functionsetColor(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pColArray; + kvs_int_t iColR,iColG,iColB; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("red_or_array",KVS_PT_VARIANT,0,pColArray) + KVSO_PARAMETER("green",KVS_PT_INT,KVS_PF_OPTIONAL,iColG) + KVSO_PARAMETER("blue",KVS_PT_INT,KVS_PF_OPTIONAL,iColB) + KVSO_PARAMETERS_END(c) + if(pColArray->isArray()) + { + if(pColArray->array()->size() < 3) + { + c->error(__tr2qs("The array passed as parameter must contain at least 3 elements")); + return false; + } + KviKvsVariant * pColR = pColArray->array()->at(0); + KviKvsVariant * pColG = pColArray->array()->at(1); + KviKvsVariant * pColB = pColArray->array()->at(2); + + if(!(pColR && pColG && pColB)) + { + c->error(__tr2qs("One of the colors array parameters is empty")); + return false; + } + if(!(pColR->asInteger(iColR) && pColG->asInteger(iColG) && pColB->asInteger(iColB))) + { + c->error(__tr2qs("One of the colors array parameters didn't evaluate to an integer")); + return false; + } + + } else { + if (c->params()->count()==1) + { + bool bOk,bOk1,bOk2; + QString value; + pColArray->asString(value); + int i=0; + if (value.length()!=6) + { + c->warning(__tr2qs("A string of 6 digits hex is required")); + return true; + } + QString buffer(value.mid(0,2)); + iColR=buffer.toInt(&bOk,16); + buffer=value.mid(2,2); + iColG=buffer.toInt(&bOk1,16); + buffer=value.mid(4,2); + iColB=buffer.toInt(&bOk2,16); + if (!bOk || !bOk1 || !bOk2) + { + c->warning(__tr2qs("Not an hex digits")); + return true; + } + if (widget()) ((KviTalMultiLineEdit *)widget())->setColor(QColor(iColR,iColG,iColB)); + return true; + } + if(c->params()->count() < 3) + { + c->error(__tr2qs("$setColor requires either an array as first parameter or three integers")); + return false; + } + if(!pColArray->asInteger(iColR)) + { + c->error(__tr2qs("The first parameter didn't evaluate to an array nor an integer")); + return false; + } + } + if (widget()) ((KviTalMultiLineEdit *)widget())->setColor(QColor(iColR,iColG,iColB)); + return true; +} + +bool KviKvsObject_mledit::functionsetPointSize(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uPointSize; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("point_size",KVS_PT_UNSIGNEDINTEGER,0,uPointSize) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalMultiLineEdit *)widget())->setPointSize(uPointSize); + return true; +} + +bool KviKvsObject_mledit::functionsetLinkUnderline(KviKvsObjectFunctionCall *c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bLinkunderline",KVS_PT_BOOL,0,bFlag) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalMultiLineEdit *)widget())->setLinkUnderline(bFlag); + return true; +} + +bool KviKvsObject_mledit::functionsetFamily(KviKvsObjectFunctionCall *c) +{ + QString szFamily; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("family",KVS_PT_STRING,0,szFamily) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalMultiLineEdit *)widget())->setFamily(szFamily); + return true; +} + +bool KviKvsObject_mledit::functionsetModified(KviKvsObjectFunctionCall *c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bModified",KVS_PT_BOOL,0,bFlag) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalMultiLineEdit *)widget())->setModified(bFlag); + return true; +} + +bool KviKvsObject_mledit::functioninsertParagraph(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iParagraph; + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETER("paragraph",KVS_PT_INT,0,iParagraph) + KVSO_PARAMETERS_END(c) + if(widget()) + ((KviTalMultiLineEdit *)widget())->insertParagraph(szText,iParagraph); + return true; +} + +bool KviKvsObject_mledit::functionremoveParagraph(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iParagraph; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("paragraph",KVS_PT_INT,0,iParagraph) + KVSO_PARAMETERS_END(c) + if(widget()) + ((KviTalMultiLineEdit*)widget())->removeParagraph(iParagraph); + return true; +} + +bool KviKvsObject_mledit::functionsetOverwriteMode(KviKvsObjectFunctionCall *c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bOverwritemode",KVS_PT_BOOL,0,bFlag) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalMultiLineEdit *)widget())->setOverwriteMode(bFlag); + return true; +} + +bool KviKvsObject_mledit::functiontextFormat(KviKvsObjectFunctionCall *c) + +{ + if(!widget())return true; + int fstyle = ((KviTalMultiLineEdit *)widget())->textFormat(); + QString format=""; + for(unsigned int i = 0; i < mod_num; i++) + { + if(fstyle & mod_cod[i]) + { + format=mod_tbl[i]; + } + } + c->returnValue()->setString(format); + return true; + +} +bool KviKvsObject_mledit::functionsetTextFormat(KviKvsObjectFunctionCall *c) + +{ + QString szFormat; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("textformat",KVS_PT_STRING,0,szFormat) + KVSO_PARAMETERS_END(c) + if(!widget()) return true; + if(KviQString::equalCI(szFormat,"PlainText")) + ((KviTalMultiLineEdit *)widget())->setTextFormat(Qt::PlainText); + else if(KviQString::equalCI(szFormat,"RichText")) + ((KviTalMultiLineEdit *)widget())->setTextFormat(Qt::RichText); + else if(KviQString::equalCI(szFormat,"LogText")) + ((KviTalMultiLineEdit *)widget())->setTextFormat(Qt::LogText); + else if(KviQString::equalCI(szFormat,"AutoText")) + ((KviTalMultiLineEdit *)widget())->setTextFormat(Qt::AutoText); + else c->warning(__tr2qs("Unknown text format '%Q'"),&szFormat); + return true; +} +// findme +bool KviKvsObject_mledit::functionsetParagraphBackgroundColor(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pColArray; + kvs_int_t iParagraph,iColR,iColG,iColB; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("paragraph",KVS_PT_INT,0,iParagraph) + KVSO_PARAMETER("red_or_array",KVS_PT_VARIANT,0,pColArray) + KVSO_PARAMETER("green",KVS_PT_INT,KVS_PF_OPTIONAL,iColG) + KVSO_PARAMETER("blue",KVS_PT_INT,KVS_PF_OPTIONAL,iColB) + KVSO_PARAMETERS_END(c) + if(pColArray->isArray()) + { + if(pColArray->array()->size() < 3) + { + c->error(__tr2qs("The array passed as parameter must contain at least 3 elements")); + return false; + } + KviKvsVariant * pColR = pColArray->array()->at(0); + KviKvsVariant * pColG = pColArray->array()->at(1); + KviKvsVariant * pColB = pColArray->array()->at(2); + + if(!(pColR && pColG && pColB)) + { + c->error(__tr2qs("One of the colors array parameters is empty")); + return false; + } + if(!(pColR->asInteger(iColR) && pColG->asInteger(iColG) && pColB->asInteger(iColB))) + { + c->error(__tr2qs("One of the colors array parameters didn't evaluate to an integer")); + return false; + } + + } else { + if (c->params()->count()==1) + { + bool bOk,bOk1,bOk2; + QString value; + pColArray->asString(value); + int i=0; + if (value.length()!=6) + { + c->warning(__tr2qs("A string of 6 digits hex is required")); + return true; + } + QString buffer(value.mid(0,2)); + iColR=buffer.toInt(&bOk,16); + buffer=value.mid(2,2); + iColG=buffer.toInt(&bOk1,16); + buffer=value.mid(4,2); + iColB=buffer.toInt(&bOk2,16); + if (!bOk || !bOk1 || !bOk2) + { + c->warning(__tr2qs("Not an hex digits")); + return true; + } + if (widget()) ((KviTalMultiLineEdit *)widget())->setParagraphBackgroundColor(iParagraph,QColor(iColR,iColG,iColB)); + return true; + } + if(c->params()->count() < 3) + { + c->error(__tr2qs("$setColor requires either an array as first parameter or three integers")); + return false; + } + if(!pColArray->asInteger(iColR)) + { + c->error(__tr2qs("The first parameter didn't evaluate to an array nor an integer")); + return false; + } + } + if (widget()) ((KviTalMultiLineEdit *)widget())->setParagraphBackgroundColor(iParagraph,QColor(iColR,iColG,iColB)); + return true; +} + +bool KviKvsObject_mledit::functionclearParagraphBackground(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iParagraph; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("paragraph",KVS_PT_INT,0,iParagraph) + KVSO_PARAMETERS_END(c) + if(widget()) + ((KviTalMultiLineEdit*)widget())->clearParagraphBackground(iParagraph); + return true; +} + +bool KviKvsObject_mledit::functionloadFile(KviKvsObjectFunctionCall *c) +{ + QString szFile; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("file_name",KVS_PT_STRING,0,szFile) + KVSO_PARAMETERS_END(c) + if ( !QFile::exists(szFile)) + { + c->warning(__tr2qs(" I can't find the specified file '%Q'."),&szFile); + return true; + } + + QFile file( szFile ); + if ( !file.open( IO_ReadOnly ) ) + { + c->warning(__tr2qs(" I cannot read the file %Q'."),&szFile); + return true; + } + + QTextStream ts( &file ); + QString txt = ts.read(); +#ifdef COMPILE_USE_QT4 + if ( !Q3StyleSheet::mightBeRichText( txt ) ) + txt = Q3StyleSheet::convertFromPlainText( txt, Q3StyleSheetItem::WhiteSpacePre ); +#else + if ( !QStyleSheet::mightBeRichText( txt ) ) + txt = QStyleSheet::convertFromPlainText( txt, QStyleSheetItem::WhiteSpacePre ); +#endif + ((KviTalMultiLineEdit *)widget())->setText( txt ); + + file.close(); + return true; +} + +bool KviKvsObject_mledit::functionsetAlignment(KviKvsObjectFunctionCall *c) + +{ + QString szAlignment; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("alignment",KVS_PT_STRING,0,szAlignment) + KVSO_PARAMETERS_END(c) + if(!widget()) return true; + if(KviQString::equalCI(szAlignment,"Left")) + ((KviTalMultiLineEdit *)widget())->setAlignment(Qt::AlignLeft); + else if(KviQString::equalCI(szAlignment,"Right")) + ((KviTalMultiLineEdit *)widget())->setAlignment(Qt::AlignRight); + else if(KviQString::equalCI(szAlignment,"Center")) + ((KviTalMultiLineEdit *)widget())->setAlignment(Qt::AlignCenter); + else if(KviQString::equalCI(szAlignment,"Justify")) + ((KviTalMultiLineEdit *)widget())->setAlignment(Qt::AlignJustify); + else c->warning(__tr2qs("Unknown alignment '%Q'"),&szAlignment); + return true; +} + +bool KviKvsObject_mledit::functionsetAutoFormatting(KviKvsObjectFunctionCall *c) + +{ + QString szAutoformatting; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("autoformatting",KVS_PT_STRING,0,szAutoformatting) + KVSO_PARAMETERS_END(c) + if(!widget()) return true; + if(KviQString::equalCI(szAutoformatting,"AutoNone")) + ((KviTalMultiLineEdit *)widget())->setAutoFormatting(QTEXTEDIT_AUTO_NONE); + else if(KviQString::equalCI(szAutoformatting,"BulletList")) + ((KviTalMultiLineEdit *)widget())->setAutoFormatting(QTEXTEDIT_AUTO_BULLET_LIST); + else if(KviQString::equalCI(szAutoformatting,"AutoAll")) + ((KviTalMultiLineEdit *)widget())->setAutoFormatting(QTEXTEDIT_AUTO_ALL); + else c->warning(__tr2qs("Unknown auto formatting mode '%Q'"),&szAutoformatting); + return true; +} + +bool KviKvsObject_mledit::functionsetVerticalAlignment(KviKvsObjectFunctionCall *c) + +{ + QString szValignment; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("alignment",KVS_PT_STRING,0,szValignment) + KVSO_PARAMETERS_END(c) + if(!widget()) return true; + if(KviQString::equalCI(szValignment,"Normal")) + ((KviTalMultiLineEdit *)widget())->setVerticalAlignment(KviTalMultiLineEdit::AlignNormal); + else if(KviQString::equalCI(szValignment,"SuperScript")) + ((KviTalMultiLineEdit *)widget())->setVerticalAlignment(KviTalMultiLineEdit::AlignSuperScript); + else if(KviQString::equalCI(szValignment,"SubScript")) + ((KviTalMultiLineEdit *)widget())->setVerticalAlignment(KviTalMultiLineEdit::AlignSubScript); + else c->warning(__tr2qs("Unknown vertical alignment '%Q'"),&szValignment); + return true; +} + +bool KviKvsObject_mledit::functionparagraphs(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setInteger(((KviTalMultiLineEdit *)widget())->paragraphs()); + return true; + +} + +bool KviKvsObject_mledit::functionlines(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setInteger(((KviTalMultiLineEdit *)widget())->lines()); + return true; +} + +bool KviKvsObject_mledit::functionlineOfChar(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iPara,iIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("paragraph",KVS_PT_INT,0,iPara) + KVSO_PARAMETER("index",KVS_PT_INT,0,iIndex) + KVSO_PARAMETERS_END(c) + if (widget()) + c->returnValue()->setInteger(((KviTalMultiLineEdit *)widget())->lineOfChar(iPara,iIndex)); + return true; +} + +bool KviKvsObject_mledit::functionlinesOfParagraph(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iLine; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("paragraph",KVS_PT_INT,0,iLine) + KVSO_PARAMETERS_END(c) + if(widget()) + c->returnValue()->setInteger(((KviTalMultiLineEdit *)widget())->linesOfParagraph(iLine)); + return true; +} + + +bool KviKvsObject_mledit::functionparagraphLength(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iParagraph; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("paragraph",KVS_PT_INT,0,iParagraph) + KVSO_PARAMETERS_END(c) + if(widget()) + c->returnValue()->setInteger(((KviTalMultiLineEdit *)widget())->paragraphLength(iParagraph)); + return true; + +} + +bool KviKvsObject_mledit::functionselectAll(KviKvsObjectFunctionCall *c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bSelectall",KVS_PT_BOOL,0,bFlag) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalMultiLineEdit *)widget())->selectAll(bFlag); + return true; +} + + + +#include "m_class_multilineedit.moc" diff --git a/src/modules/objects/class_multilineedit.h b/src/modules/objects/class_multilineedit.h new file mode 100644 index 00000000..8639266e --- /dev/null +++ b/src/modules/objects/class_multilineedit.h @@ -0,0 +1,110 @@ +#ifndef _CLASS_MULTILINEEDIT_H_ +#define _CLASS_MULTILINEEDIT_H_ +//vim: ts=8 +// File : class_multilineedit.cpp +// Creation date : Mon Feb 19 00:45:34 CET by Krzysztof Godlewski +// +// Modification date: Thu 15 Feb 2005 22:00 :00 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 "class_widget.h" +#include "object_macros.h" + +class KviKvsObject_mledit : public KviKvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_mledit) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + bool functionTextLine(KviKvsObjectFunctionCall *c); + bool functionInsertLine(KviKvsObjectFunctionCall *c); + bool functionRemoveLine(KviKvsObjectFunctionCall *c); + bool functionInsertAt(KviKvsObjectFunctionCall *c); + bool functionNumLines(KviKvsObjectFunctionCall *c); + bool functionSetCursorPosition(KviKvsObjectFunctionCall *c); + bool functionAtBeginning(KviKvsObjectFunctionCall *c); + bool functionAtEnd(KviKvsObjectFunctionCall *c); + bool functionSetWordWrap(KviKvsObjectFunctionCall *c); + bool functionWordWrap(KviKvsObjectFunctionCall *c); + bool functionCursorPosition(KviKvsObjectFunctionCall *c); + bool functionText(KviKvsObjectFunctionCall *c); + bool functionLength(KviKvsObjectFunctionCall *c); + bool functionSetMaxLines(KviKvsObjectFunctionCall *c); + bool functionMaxLines(KviKvsObjectFunctionCall *c); + bool functionSetReadOnly(KviKvsObjectFunctionCall *c); + bool functionInsert(KviKvsObjectFunctionCall *c); + bool functionAppend(KviKvsObjectFunctionCall *c); + bool functionCopy(KviKvsObjectFunctionCall *c); + bool functionPaste(KviKvsObjectFunctionCall *c); + bool functionCut(KviKvsObjectFunctionCall *c); +// |-G&N add-| + bool functionsetItalic(KviKvsObjectFunctionCall *c); + bool functionitalic(KviKvsObjectFunctionCall *c); + bool functionsetBold(KviKvsObjectFunctionCall *c); + bool functionbold(KviKvsObjectFunctionCall *c); + bool functionsetUnderline(KviKvsObjectFunctionCall *c); + bool functionunderline(KviKvsObjectFunctionCall *c); + bool functionzoomIn(KviKvsObjectFunctionCall *c); + bool functionzoomOut(KviKvsObjectFunctionCall *c); + bool functionzoomTo(KviKvsObjectFunctionCall *c); + bool functionundo(KviKvsObjectFunctionCall *c); + bool functionredo(KviKvsObjectFunctionCall *c); + bool functiondel(KviKvsObjectFunctionCall *c); + bool functionclear(KviKvsObjectFunctionCall *c); + bool functionindent(KviKvsObjectFunctionCall *c); + bool functionsetUndoRedoEnabled(KviKvsObjectFunctionCall *c); + bool functionsetUndoDepth(KviKvsObjectFunctionCall *c); + bool functionisUndoRedoEnabled(KviKvsObjectFunctionCall *c); + bool functionundoDepth(KviKvsObjectFunctionCall *c); + bool functionsetText(KviKvsObjectFunctionCall *c); + bool functionsetPointSize(KviKvsObjectFunctionCall *c); + bool functionsetColor(KviKvsObjectFunctionCall *c); + bool functionisUndoAvailable(KviKvsObjectFunctionCall *c); + bool functionisRedoAvailable(KviKvsObjectFunctionCall *c); + bool functionsetLinkUnderline(KviKvsObjectFunctionCall *c); + bool functionsetFamily(KviKvsObjectFunctionCall *c); + bool functionsetModified(KviKvsObjectFunctionCall *c); + bool functioninsertParagraph(KviKvsObjectFunctionCall *c); + bool functionremoveParagraph(KviKvsObjectFunctionCall *c); + bool functionsetOverwriteMode(KviKvsObjectFunctionCall *c); + bool functionsetTextFormat(KviKvsObjectFunctionCall *c); + bool functiontextFormat(KviKvsObjectFunctionCall *c); + bool functionsetParagraphBackgroundColor(KviKvsObjectFunctionCall *c); + bool functionclearParagraphBackground(KviKvsObjectFunctionCall *c); + bool functionloadFile(KviKvsObjectFunctionCall *c); + bool functionsetAlignment(KviKvsObjectFunctionCall *c); + bool functionsetAutoFormatting(KviKvsObjectFunctionCall *c); + bool functionsetVerticalAlignment(KviKvsObjectFunctionCall *c); + bool functionsetWrapPolicy(KviKvsObjectFunctionCall *c); + bool functionparagraphs(KviKvsObjectFunctionCall *c); + bool functionparagraphLength(KviKvsObjectFunctionCall *c); + bool functionlines(KviKvsObjectFunctionCall *c); + bool functionlineOfChar(KviKvsObjectFunctionCall *c); + bool functionlinesOfParagraph(KviKvsObjectFunctionCall *c); + bool functionselectAll(KviKvsObjectFunctionCall *c); + +}; + +#endif //!_CLASS_MULTILINEEDIT_H_ diff --git a/src/modules/objects/class_painter.cpp b/src/modules/objects/class_painter.cpp new file mode 100644 index 00000000..b27a24a3 --- /dev/null +++ b/src/modules/objects/class_painter.cpp @@ -0,0 +1,1007 @@ +//mdm: +// Painter : class_painter.cpp +// Creation date : Fri Mar 18 14:30:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// Lucia Papini (^ashura^) English Translation. +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 "class_painter.h" +#include "class_pixmap.h" +#include "class_widget.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_error.h" +#include "kvi_iconmanager.h" +#include "kvi_malloc.h" + + +/* + @doc: painter + @keyterms: + painter object class, line editor, input + @title: + painter class + @type: + class + @short: + This class provide a painter to paint line and shapes. + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + With this class you can draw many graphics objects from simple lines to complex shapes like pies and chords.[br] + It can also draw aligned text and pixmaps. Normally, it draws in a "natural" coordinate system, but it can also do view and world transformation.[br] + The class need to be implemented into a [classfnc]$paintEvent[/classfnc](); + @functions: + !fn: $drawLine(,,,) + Draws a line from (x1, y1) to (x2, y2) and sets the current pen position to (x2, y2). + !fn: $begin() + Begins painting the paint device : the parameter MUST be a widget or a pixmap.[br] + Warning: A paint device can only be painted by one painter at a time. + !fn: $end() + Ends painting. Any resources used while painting are released. + !fn: $setPen(,,][,,],[system color:RGB or HSV) + The pen defines the lines or text, color. You can set it with Red,Green,Blue, or H,S,V value[br] + All parameters are in integer form. + The HSV system, like RGB, has three components:[br] + * H, for hue, is either 0-359 if the color is chromatic (not gray), or meaningless if it is gray.[br] + It represents degrees on the color wheel familiar to most people. Red is 0 (degrees), green is 120 and blue is 240.[br] + * S, for saturation, is 0-255, and the bigger it is, the stronger the color is. Grayish colors have saturation near 0; very strong colors have saturation near 255.[br] + * V, for value, is 0-255 and represents lightness or brightness of the color. 0 is black; 255 is as far from black as possible.[br] + Examples: RED is H=0, S=255, V=255.[br] + Light RED could have H about 0, S about 50-100, and S=255. + ES: $setPen(00,00,00) for black;[br] + Default color mode is RGB; + !fn: $setBrush(,,][,,],[system color:RGB or HSV) + Sets the painter's brush to have the specified color.[br] + Example:[br] + class (wdg,widget)[br] + {[br] + paintevent()[br] + {[br] + %b=$new(painter)[br] + %b->$setBackgroundMode(Opaque)[br] + %b->$setBrush(0,250,250)[br] + %b->$begin($$)[br] + %b->$drawEllipse(50,50,100,50)[br] + }[br] + }[br] + %aa=$new(wdg)[br] + %aa->$show()[br] + !fn: $drawRect(,,,) + Draws a rectangle with upper left corner at (x, y) and with width w and height h. + !fn: $drawWinFocusRect(,,,) + Draws a Windows focus rectangle with upper left corner at (x, y) and with width w and height h.[br] + This function draws nothing if the coordinate system has been rotated or sheared. + !fn: $drawRoundRect(,,,,,) + Draws a rectangle with rounded corners at (x, y), with width w and height h.[rb] + The xCor and yCor arguments specify how rounded the corners should be (range is 0->99). + !fn: $drawPie(,,,,,) + Draws a pie defined by the rectangle (x, y, w, h), the start angle a and the arc length alen.[br] + The angles and are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). + !fn: $drawArc(,,,,,) + Draws an arc defined by the rectangle (x, y, w, h), the start angle a and the arc length alen.[br] + The angles and are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). + !fn: $drawPoint(,) + Draws a point at x and y coordinates. + !fn: $drawEllipse(,,,) + Draws an ellipse with center at (x + w/2, y + h/2) and size (w, h). + !fn: $drawChord(,,,,,) + Draws a chord defined by the rectangle (x, y, w, h), the start angle a and the arc length alen.[br] + The angles and are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). + !fn: $drawText(,,,,) + Draws the given at position , .[br] + If is -1 (the default) all the text is drawn, otherwise the first characters are drawn. + The text's direction is given by , valid flag are:[br] + [pre] + Auto [br] + RTL (right to left) [br] + LTR (left to right) [br] + [/pre] + !fn: $drawPixmap(,,,,,,) + Draws a pixmap at x,y coordinates[br] + !fn: $setFont(,,)[br] + Set the font's size, family and stile, valid flag for style are:[br] + [pre] + italic [br] + bold [br] + underline [br] + overline [br] + strikeout [br] + fixedpitch [br] + [/pre] + !fn: $setFontSize()[br] + Set the current painter font's size.[br] + !fn: $fontAscent() + Return the distance from the baseline to the highest position characters extend to. + !fn: $fontDescent() + Return the distance from the baseline to the lowest point characters extend to. + !fn: $fontMetricsWidth() + Returns the font metrics width for the painter's current font. + !fn: $fontMetricsHeight() + Returns the font metrics height for the painter's current font. + !fn: $rotate() + Rotates the coordinate system a degrees counterclockwise. + !fn: $translate(,) + Translates the coordinate system by , . + !fn: $shear(,) + Shears the coordinate system by , . + !fn: $scale(,) + Scales the coordinate system by , . + !fn: $setBackgroundMode() + Sets the background mode of the painter to : valid values are:[br] + - Transparent (that is the default value);[br] + - Opaque.[br] + !fn: $setOpacity() [QT4 ONLY] + Sets the painter opacity that affects all painter operations (drawpixmap, drawtext...). Valid values range are from 0 (total transparency) to 1 (total opacity)[br] + You must invoke the [classfnc]$begin[/classfnc] before using it. + !fn: $setTextAntialiasing() [QT4 ONLY] + Enable/disable antialias in text if possible. + You must call the [classfnc]$begin[/classfnc] before using it. + !fn: $setAntialiasing() [QT4 ONLY] + Enable/disable antialias in edges of primitives if possible. + You must call the [classfnc]$begin[/classfnc] before using it. + !fn: $setSmoothPixmapTransform() [QT4 ONLY] + Enable/disable smooth bilinear pixmap transformation algorithm (such as bilinear). + You must call the [classfnc]$begin[/classfnc] before using it. + Example:[br] + [br] + class (hello,widget)[br] + {[br] + constructor()[br] + {[br] + $$->%sintbl[]= $array( 0, 38, 71, 92, 100, 92, 71, 38,0, -38, -71, -92, -100, -92, -71, -38);[br] + $$->%index=0[br] + $$->$starttimer( 30 );[br] + $$->$resize(800,600 );[br] + $$->%string=$0[br] + $$->%waitfor=1;[br] + $$->%nextanim=0[br] + [br] + #zoom and rotation anim[br] + $$->%Zoomindex=11[br] + $$->%degree=0[br] + $$->%Noanim=0[br] + $$->%scrollright=-450[br] + [br] + #anim effect init[br] + $$->%xoffset=4[br] + $$->%yoffset=3[br] + $$->%xstart=270[br] + $$->%ystart=200[br] + $$->%b=0[br] + $$->%yoffs=400[br] + [br] + #parallax parameter[br] + $$->%Off=400[br] + $$->%roll=1[br] + }[br] + timerevent()[br] + {[br] + $$->%b = $(($$->%b + 1) & 15);[br] + if ($$->%nextanim == 1) $$->$repaint(1);[br] + $$->$repaint(0);[br] + }[br] + drawAnim()[br] + {[br] + %P->$setFont(32,"times",bold);[br] + %w=$(%P->$fontMetricsWidth($$->%string[$$->%index]) + 20);[br] + %h=$(%P->$fontMetricsHeight * 2);[br] + %pmx = $(($$->$width/2) -%w/2);[br] + %pmy = $(($$->$height()/2) - %h/2);[br] + %x = 10;[br] + %y= $((%h/2) + $$->$fontDescent());[br] + %i=0[br] + while ( $str.mid("Grifisx/Noldor",%i,1) != "") [br] + {[br] + %i16 = $(($$->%b+%i) & 15);[br] + %char=$str.mid("Grifisx/Noldor",%i,1)[br] + %P->$setPen($((15-%i16)*16),$((15-%i16)*16),$((15-%i16)*16) );[br] + %P->$drawText( $(%x+$$->%xstart),$($$->%ystart+%y-$$->%sintbl[%i16]*%h/800),%char,1,Auto);[br] + %x += %P->$fontMetricsWidth(%char);[br] + %i++;[br] + }[br] + }[br] + matrixeffect()[br] + {[br] + if (($$->%Zoomindex == 99) && ($$->%degree==360)) return %P->$drawPixmap($(400-32),$(300-32),"kvirc.png",0,0,-1,-1)[br] + %P->$scale(0.$$->%Zoomindex,0.$$->%Zoomindex)[br] + if ($$->%Zoomindex != 99) $$->%Zoomindex++;[br] + %P->$rotate($$->%degree)[br] + %P->$translate(400,300)[br] + %P->$drawPixmap(-32,-32,"kvirc.png",0,0,-1,-1)[br] + %P->$setFont(28,"times",bold);[br] + %P->$reset()[br] + if ($$->%scrollright >= 550) return[br] + %P->$scale(0.$$->%Zoomindex,0.$$->%Zoomindex)[br] + %P->$translate(400,350)[br] + %P->$drawText($$->%scrollright,10,"Another cool class brought to you by...",-1,Auto) [br] + $$->%scrollright += 3;[br] + %P->$reset()[br] + }[br] + nextanim()[br] + {[br] + %p=$new(painter)[br] + %p->$setBackgroundMode(Opaque)[br] + %p->$setBrush($rand(255),$rand(255),$rand(255))[br] + %p->$begin($$)[br] + %rand=$rand(5)[br] + %p->$drawrect($rand(800),$rand(400),120,200)[br] + %p->$drawArc($rand(800),$rand(400),120,200,20,$(16*20))[br] + %p->$drawPie($rand(800),$rand(400),120,200,20,$(16*20))[br] + %p->$drawChord($rand(800),$rand(400),120,200,20,$(16*20))[br] + %p->$drawEllipse($rand(800),$rand(400),100,30)[br] + %p->$end()[br] + delete %p[br] + }[br] + paintEvent()[br] + {[br] + if ($$->%nextanim ==1) return $$->$nextanim()[br] + # pixmap creation: every effect will be painted on it then copied on widget[br] + %pixmap=$new(pixmap)[br] + %pixmap->$resize($$->$width(),$$->$height())[br] + [br] + # painter creation [br] + %P=$new(painter);[br] + %P->$begin(%pixmap);[br] + $$->$drawanim[br] + $$->$matrixeffect[br] + %i=0[br] + while (%i != 100)[br] + {[br] + %i16 = $(($$->%b+%i) & 15);[br] + %P->$setPen($((15-%i16)*16),$((15-%i16)*16),$((15-%i16)*16) );[br] + %P->$drawpoint($rand(800),$rand(600))[br] + %i++[br] + }[br] + [br] + # sets the animations order to manage the parallax effect[br] + %P->$end[br] + objects.bitBlt $$ 0 0 %pixmap[br] + delete %pixmap[br] + delete %P[br] + if (%Pauseflag == 1) return[br] + [br] + # manage the animations parameters[br] + if (($$->%Off<=60) && ($$->%roll<182)) $$->%roll += 2;[br] + if ($$->%roll>182) $$->%waitfor=0[br] + if ($$->%Noanim != 1) $$->%degree += 16;[br] + if ($$->%degree >= 360)[br] + {[br] + $$->%degree=0;[br] + if ($$->%Zoomindex == 99) $$->%Noanim=1[br] + } [br] + if ($$->%Noanim != 1) return[br] + [br] + #sinusoid animation[br] + if (($$->%xstart <1) && ($$->%xoffset == -4)) $$->%xoffset=4;[br] + if (($$->%xstart >$($$->$width()-%P->$fontMetricsWidth("Grifisx/Noldor"))) && ($$->%xoffset == 4)) $$->%xoffset=-4;[br] + if (($$->%ystart <1) && ($$->%yoffset == -3)) $$->%yoffset=3;[br] + if (($$->%ystart >$($$->$height()-60)) && ($$->%yoffset == 3)) $$->%yoffset=-3;[br] + $$->%xstart += $$->%xoffset;[br] + $$->%ystart += $$->%yoffset;[br] + }[br] + }[br] + [br] + %Hello=$new(hello)[br] + %Hello->$setcaption("Painter effects" );[br] + %Hello->$setFont(28,"times",bold);[br] + %Btn=$new(button,%Hello)[br] + %Btn->$setmaximumwidth(80)[br] + %Btn->$setmaximumheight(30)[br] + %Btn->$setFont(8,"times",bold);[br] + %Btn->$settext(Next)[br] + [br] + privateimpl(%Btn,mousepressevent)[br] + {[br] + if ($$->$parent->%nextanim==0) [br] + {[br] + $$->$parent->%nextanim=1[br] + $$->$settext(Prev)[br] + } [br] + else[br] + {[br] + $$->$parent->%nextanim=0[br] + $$->$settext(Next)[br] + }[br] + }[br] + [br] + %lay=$new(layout,%Hello)[br] + %lay->$addwidget(%Btn,4,0)[br] + %Hello->$setBackgroundColor("000000");[br] + %Hello->$setmaximumwidth(800)[br] + %Hello->$setminimumwidth(780)[br] + %Hello->$setmaximumheight(600)[br] + %Hello->$setminimumheight(600)[br] + %Hello->$move(10,10)[br] + %Hello->$show();[br] [br] + +*/ + +// ======================================================================== +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_painter,"painter","object") + + // Fonts + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setFont",functionSetFont) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setFontSize",functionSetFontSize) + + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setBrush",functionsetBrush) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setPen",functionsetPen) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"fontAscent",functionfontAscent) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"fontDescent",functionfontDescent) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"fontMetricsHeight",functionfontMetricsHeight) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"fontMetricsWidth",functionfontMetricsWidth) + // Draws + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setBackGroundMode",functionsetBackGroundMode) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawRect",functiondrawRect) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawLine",functiondrawLine) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawRoundRect",functiondrawRoundRect) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawWinFocusRect",functiondrawWinFocusRect) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawPoint",functiondrawPoint) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawArc",functiondrawArc) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawEllipse",functiondrawEllipse) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawPie",functiondrawPie) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawChord",functiondrawChord) + // Text & Pixmap + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawText",functiondrawText) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawPixmap",functiondrawPixmap) + + + // MAtrix Operation + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"rotate",functionrotateMatrix) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"shear",functionshearMatrix) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"scale",functionscaleMatrix) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"translate",functiontranslateMatrix) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"reset",functionresetMatrix) + +#ifdef COMPILE_USE_QT4 + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setOpacity",functionsetOpacity) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setTextAntialiasing",functionsetTextAntialiasing) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setAntialiasing",functionsetAntialiasing) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setSmoothPixmapTransform",functionsetSmoothPixmapTransform) +#endif + + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"begin",functionbegin) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"end",functionend) + + +KVSO_END_REGISTERCLASS(KviKvsObject_painter) + + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_painter,KviKvsObject) + + m_pPainter = new QPainter(); + + m_pDeviceObject=0; + +KVSO_END_CONSTRUCTOR(KviKvsObject_painter) + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_painter) + + if (m_pPainter) delete m_pPainter; + m_pPainter = 0; + +KVSO_END_CONSTRUCTOR(KviKvsObject_painter) + +#define KVSO_PARAMETERS_PAINTER(__pXOrArray,__iY,__iW,__iH)\ +if(__pXOrArray->isArray())\ + {\ + if(__pXOrArray->array()->size() < 4)\ + {\ + c->error(__tr2qs("The array passed as parameter must contain at least 4 elements"));\ + return false;\ + }\ + KviKvsVariant * pX = __pXOrArray->array()->at(0);\ + KviKvsVariant * pY = __pXOrArray->array()->at(1);\ + KviKvsVariant * pW = __pXOrArray->array()->at(2);\ + KviKvsVariant * pH = __pXOrArray->array()->at(3);\ + if(!(pX && pY && pW && pH))\ + {\ + c->error(__tr2qs("One of the geometry array parameters is empty"));\ + return false;\ + }\ + if(!(pX->asInteger(iX) && pY->asInteger(__iY) && pW->asInteger(__iW) && pH->asInteger(__iH)))\ + {\ + c->error(__tr2qs("One of the geometry array parameters didn't evaluate to an integer"));\ + return false;\ + }\ + } else {\ + if(c->params()->count() < 4)\ + {\ + QString error=function+" requires either an array as first parameter or four integers";\ + c->error(__tr2qs(error));\ + return false;\ + }\ + if(!__pXOrArray->asInteger(iX))\ + {\ + c->error(__tr2qs("The first parameter didn't evaluate to an array nor an integer"));\ + return false;\ + }\ + }\ + +#define KVSO_2ARRAYPARAMETERS(__pXOrArray,__iY)\ +if(__pXOrArray->isArray())\ + {\ + if(__pXOrArray->array()->size() < 2)\ + {\ + c->error(__tr2qs("The array passed as parameter must contain at least 2 elements"));\ + return false;\ + }\ + KviKvsVariant * pX = __pXOrArray->array()->at(0);\ + KviKvsVariant * pY = __pXOrArray->array()->at(1);\ + if(!(pX && pY ))\ + {\ + c->error(__tr2qs("One of the array parameters is empty"));\ + return false;\ + }\ + if(!(pX->asInteger(iX) && pY->asInteger(__iY)))\ + {\ + c->error(__tr2qs("One of the array parameters didn't evaluate to an integer"));\ + return false;\ + }\ + } else {\ + if(c->params()->count() < 2)\ + {\ + QString error=function+" requires either an array as first parameter or two integers";\ + c->error(__tr2qs(error));\ + return false;\ + }\ + if(!__pXOrArray->asInteger(iX))\ + {\ + c->error(__tr2qs("The first parameter didn't evaluate to an array nor an integer"));\ + return false;\ + }\ + }\ + +#define KVSO_3ARRAYPARAMETERS(__pCol1OrArray,__iCol2,__iCol3)\ +if(__pCol1OrArray->isArray())\ + {\ + if(__pCol1OrArray->array()->size() < 3)\ + {\ + c->error(__tr2qs("The array passed as parameter must contain at least 3 elements"));\ + return false;\ + }\ + KviKvsVariant * c1 = __pCol1OrArray->array()->at(0);\ + KviKvsVariant * c2 = __pCol1OrArray->array()->at(1);\ + KviKvsVariant * c3 = __pCol1OrArray->array()->at(2);\ + if(!(c1 && c2 && c3))\ + {\ + c->error(__tr2qs("One of the array parameters is empty"));\ + return false;\ + }\ + if(!(c1->asInteger(iCol1) && c2->asInteger(__iCol2) && c3->asInteger(__iCol3)))\ + {\ + c->error(__tr2qs("One of the array parameters didn't evaluate to an integer"));\ + return false;\ + }\ + } else {\ + if(c->params()->count() < 3)\ + {\ + QString error=function+" requires either an array as first parameter or 3 integers";\ + c->error(__tr2qs(error));\ + return false;\ + }\ + if(!__pCol1OrArray->asInteger(iCol1))\ + {\ + c->error(__tr2qs("The first parameter didn't evaluate to an array nor an integer"));\ + return false;\ + }\ + }\ + +bool KviKvsObject_painter::functionSetFont(KviKvsObjectFunctionCall *c) +{ + QString szFamily,szStyle; + kvs_int_t uSize; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("size",KVS_PT_UNSIGNEDINTEGER,0,uSize) + KVSO_PARAMETER("family",KVS_PT_STRING,0,szFamily) + KVSO_PARAMETER("style",KVS_PT_STRING,0,szStyle) + KVSO_PARAMETERS_END(c) + if(!m_pPainter)return true; + QFont font=m_pPainter->font(); + font.setFamily(szFamily); + font.setPointSize(uSize); + if(KviQString::equalCI(szStyle,"italic")) font.setItalic(TRUE); + if(KviQString::equalCI(szStyle,"bold")) font.setBold(TRUE); + if(KviQString::equalCI(szStyle,"underline"))font.setUnderline(TRUE); + if(KviQString::equalCI(szStyle,"overline")) font.setOverline(TRUE); + if(KviQString::equalCI(szStyle,"strikeout"))font.setStrikeOut(TRUE); + if(KviQString::equalCI(szStyle,"fixedpitch")) font.setFixedPitch(TRUE); + m_pPainter->setFont(font); + return true; +} +bool KviKvsObject_painter::functionSetFontSize(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uSize; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("size",KVS_PT_UNSIGNEDINTEGER,0,uSize) + KVSO_PARAMETERS_END(c) + if(!m_pPainter)return true; + QFont font=m_pPainter->font(); + font.setPointSize(uSize); + m_pPainter->setFont(font); + return true; +} +bool KviKvsObject_painter::functionsetBackGroundMode(KviKvsObjectFunctionCall *c) +{ + QString szMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("background mode",KVS_PT_STRING,0,szMode) + KVSO_PARAMETERS_END(c) + if(!m_pPainter)return true; + if(KviQString::equalCI(szMode,"Transparent")) m_pPainter->setBackgroundMode(Qt::TransparentMode); + else if(KviQString::equalCI(szMode,"Opaque")) m_pPainter->setBackgroundMode(Qt::OpaqueMode); + else c->warning( __tr2qs("Unknown orientation")); + return true; + +} + +bool KviKvsObject_painter::functiondrawLine(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iX,iY,iW,iH; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) + KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) + KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) + KVSO_PARAMETERS_END(c) + QString function="$drawLine"; + KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) + if(m_pPainter) m_pPainter->drawLine(iX,iY,iW,iH); + return true; +} +bool KviKvsObject_painter::functiondrawRect(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iX,iY,iW,iH; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) + KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) + KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) + KVSO_PARAMETERS_END(c) + QString function="$drawRect"; + KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) + if(m_pPainter) m_pPainter->drawRect(iX,iY,iW,iH); + return true; +} +// FIX ME: REMOVE functiondrawWinFocusRect +bool KviKvsObject_painter::functiondrawWinFocusRect(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iX,iY,iW,iH; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) + KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) + KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) + KVSO_PARAMETERS_END(c) + QString function="$drawWinFocusRect"; + KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) +#ifndef COMPILE_USE_QT4 + if(m_pPainter) m_pPainter->drawWinFocusRect(iX,iY,iW,iH); +#endif + return true; +} +bool KviKvsObject_painter::functiondrawEllipse(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iX,iY,iW,iH; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) + KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) + KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) + KVSO_PARAMETERS_END(c) + QString function="$drawEllipse"; + KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) + if(m_pPainter) m_pPainter->drawEllipse(iX,iY,iW,iH); + return true; +} +bool KviKvsObject_painter::functiondrawRoundRect(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iXrnd,iYrnd,iX,iY,iW,iH; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x_round",KVS_PT_INT,0,iXrnd) + KVSO_PARAMETER("y_round",KVS_PT_INT,0,iYrnd) + KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) + KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) + KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) + KVSO_PARAMETERS_END(c) + QString function="$drawRoundRect"; + KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) + if(m_pPainter) + m_pPainter->drawRoundRect(iX,iY,iW,iH,iXrnd,iYrnd); + return true; +} +bool KviKvsObject_painter::functiondrawArc(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iSangle,iLena,iX,iY,iW,iH; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("start_angle",KVS_PT_INT,0,iSangle) + KVSO_PARAMETER("a_lenght",KVS_PT_INT,0,iLena) + KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) + KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) + KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) + KVSO_PARAMETERS_END(c) + QString function="$drawArc"; + KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) + if(m_pPainter) + m_pPainter->drawArc(iX,iY,iW,iH,iSangle,iLena); + return true; +} +bool KviKvsObject_painter::functiondrawChord(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iSangle,iLena,iX,iY,iW,iH; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("start_angle",KVS_PT_INT,0,iSangle) + KVSO_PARAMETER("a_lenght",KVS_PT_INT,0,iLena) + KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) + KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) + KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) + KVSO_PARAMETERS_END(c) + QString function="$drawChord"; + KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) + if(m_pPainter) + m_pPainter->drawChord(iX,iY,iW,iH,iSangle,iLena); + return true; +} +bool KviKvsObject_painter::functionsetBrush(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pCol1OrArray; + kvs_int_t iCol1,iCol2,iCol3; + QString szColorMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("Col1_or_array",KVS_PT_VARIANT,0,pCol1OrArray) + KVSO_PARAMETER("Color_2",KVS_PT_INT,KVS_PF_OPTIONAL,iCol2) + KVSO_PARAMETER("Colo3_3",KVS_PT_INT,KVS_PF_OPTIONAL,iCol3) + KVSO_PARAMETER("color_mode",KVS_PT_STRING,KVS_PF_OPTIONAL,szColorMode) + KVSO_PARAMETERS_END(c) + QString function="$drawChord"; + KVSO_3ARRAYPARAMETERS(pCol1OrArray,iCol2,iCol3) + if(!m_pPainter) return true; + if(KviQString::equalCI(szColorMode, "HSV")) + m_pPainter->setBrush(QColor(iCol1,iCol2,iCol3,QColor::Hsv)); + else + m_pPainter->setBrush(QColor(iCol1,iCol2,iCol3,QColor::Rgb)); + return true; +} +bool KviKvsObject_painter::functionsetPen(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pCol1OrArray; + kvs_int_t iCol1,iCol2,iCol3; + QString szColorMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("Col1_or_array",KVS_PT_VARIANT,0,pCol1OrArray) + KVSO_PARAMETER("Color_2",KVS_PT_INT,KVS_PF_OPTIONAL,iCol2) + KVSO_PARAMETER("Colo3_3",KVS_PT_INT,KVS_PF_OPTIONAL,iCol3) + KVSO_PARAMETER("color_mode",KVS_PT_STRING,KVS_PF_OPTIONAL,szColorMode) + KVSO_PARAMETERS_END(c) + QString function="$setPen"; + KVSO_3ARRAYPARAMETERS(pCol1OrArray,iCol2,iCol3) + if(!m_pPainter) return true; + if(KviQString::equalCI(szColorMode, "HSV")) + m_pPainter->setPen(QColor(iCol1,iCol2,iCol3,QColor::Hsv)); + else + m_pPainter->setPen(QColor(iCol1,iCol2,iCol3,QColor::Rgb)); + + return true; +} +bool KviKvsObject_painter::functiondrawPie(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iSangle,iLena,iX,iY,iW,iH; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("start_angle",KVS_PT_INT,0,iSangle) + KVSO_PARAMETER("a_lenght",KVS_PT_INT,0,iLena) + KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) + KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) + KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) + KVSO_PARAMETERS_END(c) + QString function="$drawPie"; + KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) + if(m_pPainter) + m_pPainter->drawPie(iX,iY,iW,iH,iSangle,iLena); + return true; +} +bool KviKvsObject_painter::functiondrawPoint(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iX,iY; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) + KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) + KVSO_PARAMETERS_END(c) + QString function="$drawPoint"; + KVSO_2ARRAYPARAMETERS(pXOrArray,iY) + if(m_pPainter) + m_pPainter->drawPoint(iX,iY); + return true; +} +bool KviKvsObject_painter::functionfontDescent(KviKvsObjectFunctionCall * c) +{ + if(m_pPainter) + c->returnValue()->setInteger(m_pPainter->fontMetrics().descent()); + return true; +} + +bool KviKvsObject_painter::functionfontAscent(KviKvsObjectFunctionCall * c) +{ + if(m_pPainter) + c->returnValue()->setInteger(m_pPainter->fontMetrics().ascent()); + return true; + +} + +bool KviKvsObject_painter::functionfontMetricsWidth(KviKvsObjectFunctionCall * c) +{ + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if(m_pPainter) + c->returnValue()->setInteger(m_pPainter->fontMetrics().width(szText)); + return true; +} + +bool KviKvsObject_painter::functionfontMetricsHeight(KviKvsObjectFunctionCall * c) +{ + if(m_pPainter) + c->returnValue()->setInteger(m_pPainter->fontMetrics().height()); + return true; +} +bool KviKvsObject_painter::functionbegin(KviKvsObjectFunctionCall *c) +{ + KviKvsObject * pObject; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("paint_device",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if(!m_pPainter)return true; + if (!pObject) + { + c->warning(__tr2qs("Pixmap or Widget parameter is not an object")); + return true; + } + + QPaintDevice * pd = 0; + if(pObject->inherits("KviKvsObject_pixmap"))pd =((KviKvsObject_pixmap *)pObject)->getPixmap(); + else if (pObject->inherits("KviKvsObject_widget")) pd=((KviKvsObject_widget *)pObject)->widget(); + + if (!pd) + c->warning(__tr2qs("Widget or Pixmap required ")); + else { + attachDevice(pObject,pd); + // m_pPainter->setOpacity(0.4); + if (pObject->inherits("KviKvsObject_pixmap")) ((KviKvsObject_pixmap *)pObject)->pixmapChanged(); + } + return true; +} +void KviKvsObject_painter::attachDevice(KviKvsObject * o,QPaintDevice * p) +{ + if(!m_pPainter)return; + if(m_pDeviceObject)detachDevice(); + m_pDeviceObject = o; + // KviKvsObject_pixmap and KviKvsObject_widget object have this signal + // it is emitted BEFORE the real QPaintDevice is deleted, so we can eventually + // call m_pPainter->end() in time + + QObject::connect(m_pDeviceObject,SIGNAL(aboutToDie()),this,SLOT(detachDevice())); + m_pPainter->begin(p); +} + +void KviKvsObject_painter::detachDevice() +{ + if(!m_pDeviceObject)return; + if(!m_pPainter)return; + disconnect(m_pDeviceObject,SIGNAL(aboutToDie()),this,SLOT(detachDevice())); + m_pPainter->end(); + m_pDeviceObject = 0; +} + +bool KviKvsObject_painter::functionend(KviKvsObjectFunctionCall *c) +{ + detachDevice(); + return true; +} + +bool KviKvsObject_painter::functiondrawText(KviKvsObjectFunctionCall *c) +{ + QString szText,szMode; + kvs_int_t iX,iY,iLen; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x",KVS_PT_INT,0,iX) + KVSO_PARAMETER("y",KVS_PT_INT,0,iY) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETER("length",KVS_PT_INT,0,iLen) + KVSO_PARAMETER("mode",KVS_PT_STRING,KVS_PF_OPTIONAL,szMode) + KVSO_PARAMETERS_END(c) + if(!m_pPainter)return true; +#ifdef COMPILE_USE_QT4 + if (!szMode.isEmpty()){ + if(KviQString::equalCI(szMode,"RTL"))m_pPainter->setLayoutDirection(Qt::RightToLeft); + else if(KviQString::equalCI(szMode,"LTR"))m_pPainter->setLayoutDirection(Qt::LeftToRight); + else + { + c->warning(__tr2qs("Invalid mode '%Q'"),&szMode); + return true; + } + } + + m_pPainter->drawText(iX,iY,szText); +#else + if(KviQString::equalCI(szMode,"Auto")) m_pPainter->drawText(iX,iY,szText,iLen,QPainter::Auto); + else if(KviQString::equalCI(szMode,"RTL")) m_pPainter->drawText(iX,iY,szText,iLen,QPainter::RTL); + else if(KviQString::equalCI(szMode,"LTR"))m_pPainter->drawText(iX,iY,szText,iLen,QPainter::LTR); + else c->warning(__tr2qs("Invalid mode '%Q'"),&szMode); + +#endif + return true; +} + +bool KviKvsObject_painter::functiondrawPixmap(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iX,iY,iStartx,iStarty,iEndx,iEndy; + KviKvsObject *obj; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x",KVS_PT_INT,0,iX) + KVSO_PARAMETER("y",KVS_PT_INT,0,iY) + KVSO_PARAMETER("pixmap",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("start_x",KVS_PT_INT,0,iStartx) + KVSO_PARAMETER("start_y",KVS_PT_INT,0,iStarty) + KVSO_PARAMETER("end_x",KVS_PT_INT,0,iEndx) + KVSO_PARAMETER("end_y",KVS_PT_INT,0,iEndy) + KVSO_PARAMETERS_END(c) + obj=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if(!m_pPainter)return true; + if (!obj) + { + c->warning(__tr2qs("Pixmap parameter is not an object")); + return true; + } + if (!obj->inherits("KviKvsObject_pixmap")) + { + c->warning(__tr2qs("Pixmap object required")); + return true; + } + QPixmap * pm=((KviKvsObject_pixmap *)obj)->getPixmap(); + m_pPainter->drawPixmap(iX,iY,*((KviKvsObject_pixmap *)obj)->getPixmap(),iStartx,iStarty,iEndx,iEndy); + return true; +} + +bool KviKvsObject_painter::functionrotateMatrix(KviKvsObjectFunctionCall *c) +{ + kvs_real_t dAngle; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("angle",KVS_PT_DOUBLE,0,dAngle) + KVSO_PARAMETERS_END(c) + if(!m_pPainter)return true; + m_pMatrix.rotate(dAngle); + m_pPainter->setWorldMatrix( m_pMatrix,false ); + return true; +} +bool KviKvsObject_painter::functiontranslateMatrix(KviKvsObjectFunctionCall *c) +{ + kvs_real_t dXtrasl,dYtrasl; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("trasl_x",KVS_PT_DOUBLE,0,dXtrasl) + KVSO_PARAMETER("trasl_y",KVS_PT_DOUBLE,0,dYtrasl) + KVSO_PARAMETERS_END(c) + if(!m_pPainter)return true; + QWMatrix tmpMatrix; + tmpMatrix.translate(dXtrasl,dYtrasl); + tmpMatrix = m_pMatrix * tmpMatrix; + m_pPainter->setWorldMatrix( tmpMatrix ); + m_pMatrix=tmpMatrix; + return true; +} +bool KviKvsObject_painter::functionshearMatrix(KviKvsObjectFunctionCall *c) +{ + kvs_real_t dShearh,dShearv; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("shear_h",KVS_PT_DOUBLE,0,dShearh) + KVSO_PARAMETER("shear_v",KVS_PT_DOUBLE,0,dShearv) + KVSO_PARAMETERS_END(c) + if(!m_pPainter)return true; + m_pMatrix.shear(dShearh,dShearv); + m_pPainter->setWorldMatrix(m_pMatrix); + return true; +} +bool KviKvsObject_painter::functionscaleMatrix(KviKvsObjectFunctionCall *c) +{ + kvs_real_t dScalex,dScaley; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("scale_x",KVS_PT_DOUBLE,0,dScalex) + KVSO_PARAMETER("scale_y",KVS_PT_DOUBLE,0,dScaley) + KVSO_PARAMETERS_END(c) + if(!m_pPainter)return true; + m_pMatrix.scale(dScalex,dScaley); + m_pPainter->setWorldMatrix(m_pMatrix); + return true; +} +bool KviKvsObject_painter::functionresetMatrix(KviKvsObjectFunctionCall *c) + +{ + if(!m_pPainter)return true; + m_pMatrix.reset(); + m_pPainter->setWorldMatrix( m_pMatrix ); + return true; +} + +#ifdef COMPILE_USE_QT4 +bool KviKvsObject_painter::functionsetOpacity(KviKvsObjectFunctionCall *c) +{ + if(!m_pPainter)return true; + kvs_real_t dOpacity; + + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("opacity_factor",KVS_PT_DOUBLE,0,dOpacity) + KVSO_PARAMETERS_END(c) + m_pPainter->setOpacity(dOpacity); + return true; +} +bool KviKvsObject_painter::functionsetTextAntialiasing(KviKvsObjectFunctionCall *c) +{ + if(!m_pPainter)return true; + + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + m_pPainter->setRenderHint(QPainter::TextAntialiasing,bEnabled); + return true; +} +bool KviKvsObject_painter::functionsetAntialiasing(KviKvsObjectFunctionCall *c) +{ + if(!m_pPainter)return true; + + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + m_pPainter->setRenderHint(QPainter::Antialiasing,bEnabled); + return true; +} +bool KviKvsObject_painter::functionsetSmoothPixmapTransform(KviKvsObjectFunctionCall *c) +{ + if(!m_pPainter)return true; + + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + m_pPainter->setRenderHint(QPainter::SmoothPixmapTransform,bEnabled); + return true; +} +#endif + + + +#include "m_class_painter.moc" diff --git a/src/modules/objects/class_painter.h b/src/modules/objects/class_painter.h new file mode 100644 index 00000000..2ee8a5bb --- /dev/null +++ b/src/modules/objects/class_painter.h @@ -0,0 +1,96 @@ +#ifndef _CLASS_PAINTER_H_ +#define _CLASS_PAINTER_H_ +//mdm: +// Painter : class_painter.h +// Creation date : Fri Mar 18 14:30:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 +#include +#include "kvi_string.h" + + +#include "object_macros.h" + + +class KviKvsObject_painter : public KviKvsObject +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_painter) +protected: + QPainter * m_pPainter; + QWMatrix m_pMatrix; +public: + bool functionSetFont(KviKvsObjectFunctionCall *c); + bool functionSetFontSize(KviKvsObjectFunctionCall *c); + + bool functionfontAscent(KviKvsObjectFunctionCall *c); + bool functionfontDescent(KviKvsObjectFunctionCall *c); + bool functionfontMetricsWidth(KviKvsObjectFunctionCall *c); + bool functionfontMetricsHeight(KviKvsObjectFunctionCall *c); + bool functionsetBrush(KviKvsObjectFunctionCall *c); + bool functionsetPen(KviKvsObjectFunctionCall *c); + bool functionsetBackGroundMode(KviKvsObjectFunctionCall *c); + + bool functiondrawRect(KviKvsObjectFunctionCall *c); + bool functiondrawWinFocusRect(KviKvsObjectFunctionCall *c); + bool functiondrawLine(KviKvsObjectFunctionCall *c); + bool functiondrawRoundRect(KviKvsObjectFunctionCall *c); + bool functiondrawPoint(KviKvsObjectFunctionCall *c); + bool functiondrawArc(KviKvsObjectFunctionCall *c); + bool functiondrawChord(KviKvsObjectFunctionCall *c); + bool functiondrawPie(KviKvsObjectFunctionCall *c); + bool functiondrawEllipse(KviKvsObjectFunctionCall *c); + + bool functiondrawText(KviKvsObjectFunctionCall *c); + bool functiondrawPixmap(KviKvsObjectFunctionCall *c); + + + bool functionbegin(KviKvsObjectFunctionCall *c); + bool functionend(KviKvsObjectFunctionCall *c); + + bool functionscaleMatrix(KviKvsObjectFunctionCall *c); + bool functionshearMatrix(KviKvsObjectFunctionCall *c); + bool functionrotateMatrix(KviKvsObjectFunctionCall *c); + bool functionresetMatrix(KviKvsObjectFunctionCall *c); + bool functiontranslateMatrix(KviKvsObjectFunctionCall *c); + +#ifdef COMPILE_USE_QT4 + bool functionsetOpacity(KviKvsObjectFunctionCall *c); + bool functionsetSmoothPixmapTransform(KviKvsObjectFunctionCall *c); + bool functionsetTextAntialiasing(KviKvsObjectFunctionCall *c); + bool functionsetAntialiasing(KviKvsObjectFunctionCall *c); +#endif + + + +protected: + void attachDevice(KviKvsObject * o,QPaintDevice * p); +protected slots: + void detachDevice(); +private: + KviKvsObject * m_pDeviceObject; +}; +#endif // !_CLASS_PAINTER_H_ + + + diff --git a/src/modules/objects/class_pixmap.cpp b/src/modules/objects/class_pixmap.cpp new file mode 100644 index 00000000..48aeb1e8 --- /dev/null +++ b/src/modules/objects/class_pixmap.cpp @@ -0,0 +1,317 @@ +//mdm: +// Painter : class_pixmap.h +// Creation date : Fri Mar 18 14:30:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// Lucia Papini (^ashura^) English Translation. +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 "class_pixmap.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include + +/* + @doc: pixmap + @keyterms: + pixmap object class + @title: + pixmap class + @type: + class + @short: + This class provide a pixmap. + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + The pixmap class is an off-screen, pixel-based paint device. + @functions: + !fn: $fill(,,) + Fills the pixmap with the widget's background color or pixmap.[br] + Note that x_offset, y_offest are offsets in the widget. + !fn: $resize(,) + Resizes the pixmap to w width and h height. Set wh or hg to 0, to have a null pixmap. + !fn: $scale(,) + Scales the pixmap by sx horizontally and sy vertically. + !fn: $rotate() + Rotates the pixmap by a degrees. + !fn: $load() + Load a pixmap from the . + !fn: $height() + Return the height of the pixmap. + !fn: $width() + Return the width of the pixmap. + +*/ + + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_pixmap,"pixmap","object") + + KVSO_REGISTER_HANDLER(KviKvsObject_pixmap,"fill",functionfill) + KVSO_REGISTER_HANDLER(KviKvsObject_pixmap,"resize",functionresize) + KVSO_REGISTER_HANDLER(KviKvsObject_pixmap,"load",functionload) + KVSO_REGISTER_HANDLER(KviKvsObject_pixmap,"height",functionheight) + KVSO_REGISTER_HANDLER(KviKvsObject_pixmap,"width",functionwidth) + KVSO_REGISTER_HANDLER(KviKvsObject_pixmap,"setOpacity",functionsetOpacity) + KVSO_REGISTER_HANDLER(KviKvsObject_pixmap,"scale",functionscale) + KVSO_REGISTER_HANDLER(KviKvsObject_pixmap,"rotate",functionrotate) + +KVSO_END_REGISTERCLASS(KviKvsObject_pixmap) + + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_pixmap,KviKvsObject) + m_pPixmap=new QPixmap(); + m_pImage=new QImage(); + bPixmapModified=false; + bImageModified=false; +KVSO_END_CONSTRUCTOR(KviKvsObject_pixmap) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_pixmap) + + emit aboutToDie(); + delete m_pPixmap; + if (m_pImage) delete m_pImage; + +KVSO_END_CONSTRUCTOR(KviKvsObject_pixmap) + + +bool KviKvsObject_pixmap::functionfill(KviKvsObjectFunctionCall *c) +{ + KviKvsObject *ob; + kvs_int_t iXoffset,iYoffset; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("x_offset",KVS_PT_INT,0,iXoffset) + KVSO_PARAMETER("y_offset",KVS_PT_INT,0,iYoffset) + KVSO_PARAMETERS_END(c) + + ob=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!ob) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if(!ob->object()->isWidgetType()) + { + c->warning(__tr2qs("Widget object required")); + return true; + } + bPixmapModified=true; + m_pPixmap->fill(((QWidget *)(ob->object())),iXoffset,iYoffset); + return true; +} + +bool KviKvsObject_pixmap::functionscale(KviKvsObjectFunctionCall *c) +{ + kvs_real_t uScaleX,uScaleY; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("sx",KVS_PT_REAL,0,uScaleX) + KVSO_PARAMETER("sy",KVS_PT_REAL,0,uScaleY) + KVSO_PARAMETERS_END(c) + #ifdef COMPILE_USE_QT4 + *m_pPixmap = m_pPixmap->scaled((m_pPixmap->width() * uScaleX), (m_pPixmap->height() * uScaleX)); + #else + QWMatrix wm; + wm.scale(uScaleX, uScaleY); + *m_pPixmap = m_pPixmap->xForm(wm); + #endif + bPixmapModified=true; + return true; +} + +bool KviKvsObject_pixmap::functionrotate(KviKvsObjectFunctionCall *c) +{ + kvs_real_t uDegrees; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("a",KVS_PT_REAL,0,uDegrees) + KVSO_PARAMETERS_END(c) + #ifdef COMPILE_USE_QT4 + QMatrix m; + m.rotate(uDegrees); + *m_pPixmap = m_pPixmap->transformed(m); + #else + QWMatrix wm; + wm.rotate(uDegrees); + *m_pPixmap = m_pPixmap->xForm(wm); + #endif + bPixmapModified=true; + return true; +} + +bool KviKvsObject_pixmap::functionresize(KviKvsObjectFunctionCall *c) +{ + kvs_int_t uWidth,uHeight; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("width",KVS_PT_UNSIGNEDINTEGER,0,uWidth) + KVSO_PARAMETER("height",KVS_PT_UNSIGNEDINTEGER,0,uHeight) + KVSO_PARAMETERS_END(c) + m_pPixmap->resize(uWidth,uHeight); + bPixmapModified=true; + return true; +} + + +bool KviKvsObject_pixmap::functionload(KviKvsObjectFunctionCall *c) +{ + QString szFile; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("file",KVS_PT_STRING,0,szFile) + KVSO_PARAMETERS_END(c) + + if(!QFile::exists(szFile)) + { + c->warning(__tr2qs("I can't find the specified file %Q."),&szFile); + return true; + } + m_pPixmap->load(szFile); + bPixmapModified=true; + return true; +} +bool KviKvsObject_pixmap::functionheight(KviKvsObjectFunctionCall *c) +{ + c->returnValue()->setInteger(m_pPixmap->height()); + return true; +} +bool KviKvsObject_pixmap::functionwidth(KviKvsObjectFunctionCall *c) +{ + c->returnValue()->setInteger(m_pPixmap->width()); + return true; +} +bool KviKvsObject_pixmap::functionsetOpacity(KviKvsObjectFunctionCall *c) +{ + if(!m_pPixmap)return true; + kvs_real_t dOpacity; + kvs_uint_t uXoffset,uYoffset; + kvs_uint_t uWidth,uHeight; + + KviKvsObject * pObDest; + kvs_hobject_t hObject; + + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("opacity_factor",KVS_PT_DOUBLE,0,dOpacity) + KVSO_PARAMETER("destination",KVS_PT_HOBJECT,0,hObject) + + KVSO_PARAMETER("x_offset",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,uXoffset) + KVSO_PARAMETER("y_offset",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,uYoffset) + KVSO_PARAMETER("width",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,uWidth) + KVSO_PARAMETER("height",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,uHeight) + KVSO_PARAMETERS_END(c) + pObDest=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + + if (!pObDest) + { + c->warning(__tr2qs("Destination parameter is not an object")); + return true; + } + + if(!pObDest->inherits("KviKvsObject_pixmap")) + { + c->warning(__tr2qs("Destination must be a pixmap object")); + return true; + } + QImage *buffer=((KviKvsObject_pixmap *)pObDest)->getImage(); + ((KviKvsObject_pixmap *)pObDest)->imageChanged(); + if (bPixmapModified) { + *m_pImage=m_pPixmap->convertToImage(); + } + if (uWidth>buffer->width() || uHeight>buffer->height()) + { + c->warning(__tr2qs("Area dimensions are out of destination size ")); + return true; + } + if (!uWidth){ + if(m_pImage->width()>buffer->width()) + { + c->warning(__tr2qs("Pixmap dimensions are out of destination size ")); + return true; + } + } + + if (!uHeight) + { + if(m_pImage->height()>buffer->height()) + { + c->warning(__tr2qs("Pixmap dimensions are out of destination size ")); + return true; + } + } + + +if(uXoffset+uWidth>m_pImage->width()) + { + c->warning(__tr2qs("Offset width area is out of pixmap size ")); + return true; + } + if( uYoffset+uHeight>m_pImage->height()) + { + c->warning(__tr2qs("Offset height area is out of pixmap size ")); + return true; + } + + buffer->setAlphaBuffer(true); + int iHedge=uHeight?uHeight:m_pImage->height(); + int iWedge=uWidth?uWidth:m_pImage->width(); + + for(int y = uYoffset;yscanLine(y); + QRgb * src = (QRgb *)m_pImage->scanLine(y); + src += uXoffset; + QRgb * end; + end = src + iWedge; + while(src < end) + { + *dst = qRgba( + (int)(qRed(*src)), + (int)(qGreen(*src)), + (int)(qBlue(*src)), + (int)(qAlpha(*src)*dOpacity) + ); + src++; + dst++; + } + } + return true; +} + + +QPixmap * KviKvsObject_pixmap::getPixmap() +{ + if (bImageModified) { + m_pPixmap->convertFromImage(*m_pImage); + bImageModified=false; + } + return m_pPixmap; +} +QImage * KviKvsObject_pixmap::getImage() +{ + if (bPixmapModified) { + *m_pImage=m_pPixmap->convertToImage(); + //debug ("image info2 %d and %d",test.width(),test.height()); + + bPixmapModified=false; + } + + return m_pImage; +} + +#include "m_class_pixmap.moc" diff --git a/src/modules/objects/class_pixmap.h b/src/modules/objects/class_pixmap.h new file mode 100644 index 00000000..22d1b95d --- /dev/null +++ b/src/modules/objects/class_pixmap.h @@ -0,0 +1,72 @@ +#ifndef _CLASS_PIXMAP_H_ +#define _CLASS_PIXMAP_H_ +//vim: ts=8 +// Pixmap : class_pixmap.h +// Creation date : Thu Sep 21 04:43:01 CEST 2000 by Krzysztof Godlewski +// +// This pixmap is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 +#include +#ifdef COMPILE_USE_QT4 + #include +#else + #include +#endif +#include "kvi_string.h" + + +#include "object_macros.h" + + +class KviKvsObject_pixmap : public KviKvsObject +{ + Q_OBJECT +// Q_PROPERTY(QPixmap pixmap READ getPixmap) +public: + KVSO_DECLARE_OBJECT(KviKvsObject_pixmap); + QPixmap * getPixmap(); + QImage * getImage(); + void pixmapChanged(){bPixmapModified=true;} + void imageChanged(){bImageModified=true;} + + QPixmap * pixmap(){ return m_pPixmap; } +protected: + QPixmap * m_pPixmap; + QImage * m_pImage; + bool bImageModified; + bool bPixmapModified; +signals: + void aboutToDie(); + +protected: + bool functionfill(KviKvsObjectFunctionCall *c); + bool functionresize(KviKvsObjectFunctionCall *c); + bool functionscale(KviKvsObjectFunctionCall *c); + bool functionrotate(KviKvsObjectFunctionCall *c); + bool functionload(KviKvsObjectFunctionCall *c); + bool functionheight(KviKvsObjectFunctionCall *c); + bool functionwidth(KviKvsObjectFunctionCall *c); + bool functionsetOpacity(KviKvsObjectFunctionCall *c); + + }; + +#endif // !_CLASS_PIXMAP_H_ diff --git a/src/modules/objects/class_popupmenu.cpp b/src/modules/objects/class_popupmenu.cpp new file mode 100644 index 00000000..a3db5339 --- /dev/null +++ b/src/modules/objects/class_popupmenu.cpp @@ -0,0 +1,361 @@ +//mdm : +// File : class_popupmenu.cpp +// Creation date : Mon Feb 01 21:30:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// Lucia Papini (^ashura^) English Translation. +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 "class_popupmenu.h" +#include "kvi_error.h" + +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_iconmanager.h" + + +/* + @doc: popupmenu + @keyterms: + popupmenu object class, + @title: + popupmenu class + @type: + class + @short: + Provides a popup menu. + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + This widget can be used to display a popup menu.Technically, a popup menu consists of a list of menu items.[br] + You add items with insertItem(). An item is either a string. In addition, items can have an optional icon drawn on the very left side.[br] + @functions: + !fn: $insertItem(,[icon_id:string]) + Inserts menu items into a popup menu with optional icon and return the popup identifier. + !fn: $insertWidget()[br] + Inserts widget items int a popup menu and return the popup identifier.[br] + The widget is treats as a separator; this means that the item is not selectable and you can, for example, simply insert a label if you need a popup menu with a title. + !fn: $insertHandle(,,[icon]) + Inserts a submenu with optional icon into the popup menu. + !fn: $exec([,,]) + If called without paramaters show the popup menu at the current pointer position.[br] + With the optional parameters show the popup menu at the coordinate x,y widget parameter relative. + !fn: $removeItem() + Removes the menu item that has the identifier id. + !fn: $removeItemAt() + Removes the menu item at position index. + !fn: $insertSeparator() + Inserts a separator at position index.[br] + If the index is negative the separator becomes the last menu item. + !fn: $activatedEvent() + This function is called when a menu item and return the the item id.[br] + The default implementation emits the [classfnc]$activated[/classfnc]() signal. + !fn: $highligthtedEvent() + This function is called when a menu item is highlighted and return the item id.[br] + The default implementation emits the [classfnc]$highlighted[/classfnc]() signal. + @signals: + !sg: $activated() + This signal is emitted by the default implementation of [classfnc]$activatedEvent[/classfnc](). + !sg: $highlighted() + This signal is emitted by the default implementation of [classfnc]$highlightedEvent[/classfnc](). + [br] + |-EXAMPLE POPUP MENU-|[br] + |--Start: + # First of all we create an array wich will be used to create random colors.[br] + %Hex[]=$array(0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)[br] + [br] + class (ws,widget)[br] + {[br] + #In the constructor we create everything that belong to the single widget.[br] + constructor[br] + {[br] + #Geometry of the widget and setting-up of popupmenu [br] + $$->$setGeometry(%X,%Y,100,100)[br] + $$->%lay=$new(layout,$$)[br] + #Here we generate a cicle to create our labels inside the widget.[br] + %i=0[br] + while (%i<10)[br] + {[br] + $$->%label=$new(label,$$)[br] + $$->%label->$settext("Another class by N\&G")[br] + #We set our foreground's coulor using the hex arrey in random way.[br] + %color=%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)][br] + $$->%label->$setforegroundcolor(%color)[br] + $$->%label->$setautoresize(1)[br] + #We add the label to the widget's popupmenu.[br] + $$->%lay->$addwidget($$->%label,%i,0)[br] + %i++;[br] + }[br] + #We make the popupmenu relative to this widget: this is merely demonstrative.[br] + #because it creates 25 identical popups.[br] + $$->%Popupmenu=$new(popupmenu,$$)[br] + #we create the label widget wich will be used as popup's title[br] + $$->%Popuptitle=$new(label)[br] + $$->%Popuptitle->$settext("Windows Options")[br] + $$->%Popuptitle->$setAlignment(Center)[br] + #and we add it.[br] + %A=$$->%Popuptitle[br] + $$->%Popupmenu->$insertwidget(%A)[br] + #Here we keep the various IDs in the arrays[br] + %Tile[%I]=$$->%Popupmenu->$insertItem("Tile",118)[br] + %Cascade[%I]=$$->%Popupmenu->$insertItem("Cascade",115)[br] + $$->%Popupmenu->$insertSeparator(3)[br] + %Closeactw[%I]=$$->%Popupmenu->$insertItem("Close Active Window",08)[br] + %Closeallw[%I]=$$->%Popupmenu->$insertItem("Close All Window",58)[br] + $$->$show()[br] + privateimpl($$->%Popupmenu,activatedEvent)[br] + {[br] + %id=$0[br] + %i = 0[br] + #with this cicle we control wich of the items has been called comparing the id given back by the event with our arrays created before;[br] + while (%i<20)[br] + {[br] + if (%id == %Tile[%i]) return %Workspace->$tile()[br] + if (%id == %Cascade[%i]) return %Workspace->$cascade()[br] + if (%id == %Closeactw[%i]) return %Workspace->$closeactivewindow()[br] + if (%id == %Closeallw[%i]) return %Workspace->$closeallwindows()[br] + %i ++[br] + }[br] + }[br] + }[br] + #we activate the popup pushing the right mouse button on the widget[br] + mousepressevent[br] + {[br] + if ($0 == 1) $$->%Popupmenu->$exec()[br] + }[br] + }[br] + %Workspace=$new(workspace)[br] + %Workspace->$resize(640,480)[br] + %I=0[br] + %Cicle=1[br] + while (%I<20)[br] + {[br] + %X=$rand(500)[br] + %Y=$rand(480)[br] + %Widget=$new(ws,%Workspace)[br] + %I++[br] + }[br] + #Let's show! + %Workspace->$show[br] + |--End.[br][br] +*/ + +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,"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) + KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"activatedEvent", functionactivatedEvent) + +KVSO_END_REGISTERCLASS(KviKvsObject_popupmenu) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_popupmenu,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_popupmenu) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_popupmenu) + +KVSO_END_CONSTRUCTOR(KviKvsObject_popupmenu) + +bool KviKvsObject_popupmenu::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + setObject(new KviTalPopupMenu(parentScriptWidget(), name()), true); + connect(widget(),SIGNAL(activated(int)),this,SLOT(slotactivated(int))); + connect(widget(),SIGNAL(highlighted(int)),this,SLOT(slothighlighted(int))); + return true; +} + +bool KviKvsObject_popupmenu::functioninsertItem(KviKvsObjectFunctionCall *c) +{ + QString szItem,szIcon; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szItem) + KVSO_PARAMETER("icon_id",KVS_PT_STRING,KVS_PF_OPTIONAL,szIcon) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + QPixmap *pix = 0; + int id=0; + if(!szIcon.isEmpty()) + { + pix = g_pIconManager->getImage(szIcon); + if (pix) id=((KviTalPopupMenu *)widget())->insertItem(*pix,szItem); + else c->warning(__tr2qs("pix '%Q' doesn't exists"),&szIcon); + + } + else + id=((KviTalPopupMenu *)widget())->insertItem(szItem); + c->returnValue()->setInteger(id); + return true; +} +bool KviKvsObject_popupmenu::functioninsertWidget(KviKvsObjectFunctionCall *c) +{ + KviKvsObject *pObject; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!pObject) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!pObject->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!pObject->object()->isWidgetType()) + { + c->warning(__tr2qs("Can't add a non-widget object")); + return TRUE; + } + if (widget()) ((KviTalPopupMenu *)widget())->insertItem(((KviTalPopupMenu *)(pObject->object()))); + return true; +} +bool KviKvsObject_popupmenu::functioninsertHandle(KviKvsObjectFunctionCall *c) +{ + KviKvsObject *ob; + QString szLabel,szIcon; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text_label",KVS_PT_STRING,0,szLabel) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("icon_id",KVS_PT_STRING,KVS_PF_OPTIONAL,szIcon) + KVSO_PARAMETERS_END(c) + ob=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if(!ob->object()->inherits("KviKvsObject_popupmenu")) + { + c->warning(__tr2qs("Can't add a non - popupmenu object")); + return TRUE; + } + if(!widget())return true; + QPixmap *pix = 0; + int id=0; + if(!szIcon.isEmpty()) + { + pix = g_pIconManager->getImage(szIcon); + if (pix) id=((KviTalPopupMenu *)widget())->insertItem(*pix,szLabel,((KviTalPopupMenu *)(ob->object()))); + else c->warning(__tr2qs("pix '%Q' doesn't exists"),&szIcon); + + } + else + id=((KviTalPopupMenu *)widget())->insertItem(szLabel,((KviTalPopupMenu *)(ob->object()))); + c->returnValue()->setInteger(id); + return true; +} +bool KviKvsObject_popupmenu::functionexec(KviKvsObjectFunctionCall *c) +{ + if(!c->params()->count()) + { + ((KviTalPopupMenu *)widget())->exec(QCursor::pos()); + return true; + } + + KviKvsObject *pObject; + kvs_uint_t iX,iY; + QString szLabel,szIcon; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("x",KVS_PT_UNSIGNEDINTEGER,0,iX) + KVSO_PARAMETER("y",KVS_PT_UNSIGNEDINTEGER,0,iY) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!pObject) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!pObject->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!pObject->object()->isWidgetType()) + { + c->warning(__tr2qs("Doesn't a widget object")); + return true; + } + + ((KviTalPopupMenu *)widget())->exec(((QWidget *)(pObject->object()))->mapToGlobal(QPoint(iX,iY)) ); + + return true; +} +bool KviKvsObject_popupmenu::functionremoveItem(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uItem; + 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); + return true; +} + +bool KviKvsObject_popupmenu::functioninsertSeparator(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())->insertSeparator(uIndex); + return true; +} + +void KviKvsObject_popupmenu::slothighlighted(int i) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)i)); + callFunction(this,"highlightedEvent",¶ms); +} +bool KviKvsObject_popupmenu::functionhighlightedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("highlighted",c,c->params()); + return true; +} +void KviKvsObject_popupmenu::slotactivated(int i) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)i)); + callFunction(this,"activatedEvent",¶ms); +} +bool KviKvsObject_popupmenu::functionactivatedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("activated",c,c->params()); + return true; +} + + +#include "m_class_popupmenu.moc" diff --git a/src/modules/objects/class_popupmenu.h b/src/modules/objects/class_popupmenu.h new file mode 100644 index 00000000..e5960119 --- /dev/null +++ b/src/modules/objects/class_popupmenu.h @@ -0,0 +1,58 @@ +#ifndef _CLASS_POPUPMENU_H_ +#define _CLASS_POPUPMENU_H_ +//mdm: +// File : class_popupMenu.h +// Creation date : Mon Gen 27 14:30:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 "kvi_tal_popupmenu.h" +#include +#include "class_widget.h" +#include "object_macros.h" + +class KviKvsObject_popupmenu : public KviKvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_popupmenu) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool functioninsertItem(KviKvsObjectFunctionCall *c); + bool functioninsertWidget(KviKvsObjectFunctionCall *c); + bool functioninsertHandle(KviKvsObjectFunctionCall *c); + bool functionexec(KviKvsObjectFunctionCall *c); + bool functionremoveItem(KviKvsObjectFunctionCall *c); + bool functionremoveItemAt(KviKvsObjectFunctionCall *c); + bool functioninsertSeparator(KviKvsObjectFunctionCall *c); + bool functionactivatedEvent(KviKvsObjectFunctionCall *c); + bool functionhighlightedEvent(KviKvsObjectFunctionCall *c); + +protected slots: + void slotactivated(int); + void slothighlighted(int); +}; + +#endif // !_CLASS_POPUPMENU_H_ + diff --git a/src/modules/objects/class_process.cpp b/src/modules/objects/class_process.cpp new file mode 100644 index 00000000..81efaae4 --- /dev/null +++ b/src/modules/objects/class_process.cpp @@ -0,0 +1,317 @@ +//mdm: +// File : class_process.h +// Creation date : Thu Feb 1 14:39:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 "class_process.h" +#include "kvi_error.h" +#include "kvi_debug.h" +#include "kvi_settings.h" +#include "kvi_locale.h" +#include +#ifdef COMPILE_USE_QT4 +#include +#else +#include +#endif + +/* + @doc: process + @keyterms: + process object class, process + @title: + process class + @type: + class + @short: + A class to manage process. + @inherits: + [class]object[/class] + @description: + The Process class is used to start external programs and to communicate with them.[br] + !WARNING AT LAST YOU HAVE TO CLOSE THE PROCESS! + @functions: + !fn: $addArg() + With this command you give the process name (or more arguments) for comunication. + Es: see the next example. + !fn: $start() + Tries to run the process.[br] + Es: [br] + %process=$new(process);[br] + %process->$addArg("cmd.exe");[br] + %process->$start();[br] + !fn: $readStdout() + Reads the data that the process has written to standard output. + !fn: $readStderr() + Reads the data that the process has written to standard error. + Es:[br] + -------------------Start:[br] + class (test,object)[br] + {[br] + slotReadStdout()[br] + {[br] + %stdo = %Process->$readStdout()[br] + #%Aoutput->$append(%stdo);// coming soon in the new texteditor class[br] + %Aoutput->$settext(%stdo);[br] + }[br] + slotReadStderr()[br] + {[br] + %stderr= %Process->$readStderr()[br] + #%Aoutput->$append(%stderr);// coming soon in the new texteditor class[br] + %Aoutput->$settext(%stderr);[br] + }[br] + }[br] + + %tt=$new(test)[br] + %A=$new(widget)[br] + %A->$setGeometry(100,100,400,300)[br] + %layoutA=$new(layout,%A)[br] + %Ainput=$new(lineedit,%A)[br] + #%Aoutput=$new(textedit,%A)// coming soon in the new texteditor class[br] + %Aoutput=$new(label,%A)[br] + %bclosekill=$new(button,%A)[br] + %bclosekill->$settext("&CloseKill ")[br] + %bkill=$new(button,%A)[br] + %bkill->$settext("&Kill ")[br] + %bterminate=$new(button,%A)[br] + %bterminate->$settext("&Ask to Terminate ")[br] + %layoutA->$addwidget(%Ainput,0,0)[br] + %layoutA->$addwidget(%Aoutput,1,0)[br] + %layoutA->$addwidget(%bclosekill,3,0)[br] + %layoutA->$addwidget(%bkill,4,0,)[br] + %layoutA->$addwidget(%bterminate,5,0)[br] + + %Process=$new(process)[br] + %Process->$addArg("cmd.exe")[br] + %Process->$start();[br] + + connect %Process readyReadStdout %tt slotReadStdout[br] + connect %Process readyReadStderr %tt slotReadStderr[br] + privateimpl(%Ainput,returnPressedEvent)[br] + { + %command=%Ainput->$text() "\r\n"[br] + %Process->$writeToStdin(%command);[br] + %Ainput->$setText("");[br] + }[br] + + privateimpl(%bclosekill,mousepressevent)[br] + {[br] + %Process->$closekill();[br] + delete %A;[br] + }[br] + privateimpl(%bkill,mousepressevent)[br] + {[br] + %Process->$kill();[br] + delete %A;[br] + }[br] + privateimpl(%bterminate,mousepressevent)[br] + {[br] + %Process->$tryTerminate();[br] + delete %A;[br] + }[br] + %A->$show();[br] + --------------------End.[br] + !fn: $writeToStdin() + Whit this command you send a command to the process: + !fn: $closekill() + This tries to terminate the process the nice way.[br] + If the process is still running after 5 seconds, it terminates the process the hard way.[br] + (I think that this is the better way.)[br] + Es: + %Process->close_kill(); + !fn: $kill() + Kill the process in hard way.(Bad Idea) + !fn: $tryTerminate() + Tries to terminate the process.(It could be well but...) + !fn: $closeStdin() + Close the standard Input. + !fn: $isRunning() + Return 1 if the process is running, else return 0. + !fn: $normalExit() + Returns TRUE if the process has exited normally; otherwise returns FALSE. + !fn: $readyReadStdoutEvent() + This function is invoched by the process when there are new datas.[br] + The default implementation emits the [classfnc]$readyReadStdout[/classfnc]() signal. + !fn: $readyReadStderrEvent() + This function is invoched by the process when there are new error messages.[br] + The default implementation emits the [classfnc]$readyReadStderr[/classfnc]() signal. + + @signals: + !sg: $readyReadStdout() + This signal is emitted by the default implementation of [classfnc]$readyReadStdoutEvent[/classfnc]().[br] + If you reimplement that function you will have to emit the signal manually (if you still need it). + !sg: $readyReadStderr() + This signal is emitted by the default implementation of [classfnc]$readyReadStderrEvent[/classfnc](). +*/ + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_process,"process","object") + + KVSO_REGISTER_HANDLER(KviKvsObject_process,"addArg", functionaddArgument); + KVSO_REGISTER_HANDLER(KviKvsObject_process,"start", functionstartProcess); + KVSO_REGISTER_HANDLER(KviKvsObject_process,"readStdout", functionreadStdout); + KVSO_REGISTER_HANDLER(KviKvsObject_process,"readStderr", functionreadStderr); + KVSO_REGISTER_HANDLER(KviKvsObject_process,"writeToStdin", functionwriteToStdin); + KVSO_REGISTER_HANDLER(KviKvsObject_process,"closekill", functionclosekill); + KVSO_REGISTER_HANDLER(KviKvsObject_process,"kill", functionkill); + KVSO_REGISTER_HANDLER(KviKvsObject_process,"tryTerminate", functiontryTerminate); + KVSO_REGISTER_HANDLER(KviKvsObject_process,"closeStdin", functioncloseStdin); + KVSO_REGISTER_HANDLER(KviKvsObject_process,"isRunning",functionisRunning); + KVSO_REGISTER_HANDLER(KviKvsObject_process,"normalExit",functionnormalExit); + + // Events + KVSO_REGISTER_HANDLER(KviKvsObject_process,"readyReadStdoutEvent",functionreadyReadStdoutEvent); + KVSO_REGISTER_HANDLER(KviKvsObject_process,"readyReadStderrEvent",functionreadyReadStderrEvent); + + KVSO_END_REGISTERCLASS(KviKvsObject_process) + + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_process,KviKvsObject) + +#ifdef COMPILE_USE_QT4 + m_pProcess = new Q3Process(); +#else + m_pProcess = new QProcess(); +#endif + connect(m_pProcess,SIGNAL(readyReadStdout()),this,SLOT(slotReadStdout())); + connect(m_pProcess,SIGNAL(readyReadStderr()),this,SLOT(slotReadStderr())); + +KVSO_END_CONSTRUCTOR(KviKvsObject_process) + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_process) + + delete m_pProcess; + +KVSO_END_CONSTRUCTOR(KviKvsObject_process) + + + +bool KviKvsObject_process::functionaddArgument(KviKvsObjectFunctionCall *c) +{ + + QString szArgument; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("argument",KVS_PT_NONEMPTYSTRING,0,szArgument) + KVSO_PARAMETERS_END(c) + if (m_pProcess) m_pProcess->addArgument(szArgument); + return true; +} + +//->Start the process. +bool KviKvsObject_process::functionstartProcess(KviKvsObjectFunctionCall *c) +{ + + if(!(m_pProcess->start())) + c->warning( __tr2qs("Process could not be starded.")); + return true; +} +//-->Read the standard output. +bool KviKvsObject_process::functionreadStderr(KviKvsObjectFunctionCall *c) +{ + QString ng_Process =m_pProcess->readStderr(); + c->returnValue()->setString(ng_Process); + return true; +} + +//-->Read the standard error. +bool KviKvsObject_process::functionreadStdout(KviKvsObjectFunctionCall *c) +{ + QString ng_Process =m_pProcess->readStdout(); + c->returnValue()->setString(ng_Process); + return true; +} +//-->Signals and slot to manage reading output and error from the process. +bool KviKvsObject_process::functionreadyReadStdoutEvent(KviKvsObjectFunctionCall *c) +{ + + emitSignal("readyReadStdout",c); + return true; + +} + +bool KviKvsObject_process::functionreadyReadStderrEvent(KviKvsObjectFunctionCall *c) +{ + + emitSignal("readyReadStderr",c); + return true; + +} +bool KviKvsObject_process::functionwriteToStdin(KviKvsObjectFunctionCall *c) +{ + + QString szCommand; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("command",KVS_PT_STRING,0,szCommand) + KVSO_PARAMETERS_END(c) + if (m_pProcess) m_pProcess->writeToStdin(szCommand); + + return true; +} +//-->The 3 Closing process functions +bool KviKvsObject_process::functionclosekill(KviKvsObjectFunctionCall *c) +{ + //I try to to terminate the process the nice way.... + m_pProcess->tryTerminate(); + //If the process is still running after 5 seconds, I'll terminate the process in the hard way. + QTimer::singleShot( 5000, m_pProcess, SLOT( kill() ) ); + return true; +} +bool KviKvsObject_process::functionkill(KviKvsObjectFunctionCall *c) +{ + m_pProcess->kill(); + return true; +} +bool KviKvsObject_process::functiontryTerminate(KviKvsObjectFunctionCall *c) +{ + m_pProcess->tryTerminate(); + return true; +} +//-->Close the standard input. +bool KviKvsObject_process::functioncloseStdin(KviKvsObjectFunctionCall *c) +{ + + m_pProcess->closeStdin(); + return true; +} +//->Returns if the process still runnig +bool KviKvsObject_process::functionisRunning(KviKvsObjectFunctionCall *c) +{ + c->returnValue()->setBoolean(m_pProcess->isRunning()); + return true; +} +//->Returns if the process exited. +bool KviKvsObject_process::functionnormalExit(KviKvsObjectFunctionCall *c) +{ + c->returnValue()->setBoolean(m_pProcess->normalExit()); + return true; +} + +void KviKvsObject_process::slotReadStdout() +{ + KviKvsVariantList *params=0; + callFunction(this,"readyReadStdoutEvent",params); +} + +void KviKvsObject_process::slotReadStderr() +{ + KviKvsVariantList *params=0; + callFunction(this,"readyReadStderrEvent",params); +} + +#include "m_class_process.moc" diff --git a/src/modules/objects/class_process.h b/src/modules/objects/class_process.h new file mode 100644 index 00000000..70842950 --- /dev/null +++ b/src/modules/objects/class_process.h @@ -0,0 +1,74 @@ +#ifndef _CLASS_PROCESS_H_ +#define _CLASS_PROCESS_H_ +//mdm: +// File : class_process.h +// Creation date : Thu Feb 1 14:39:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 +#include "class_widget.h" + + +#include "object_macros.h" +#ifdef COMPILE_USE_QT4 +#include +#else +#include +#endif + + +class KviKvsObject_process : public KviKvsObject +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_process) +protected: + +#ifdef COMPILE_USE_QT4 + Q3Process * m_pProcess; +#else + QProcess * m_pProcess; +#endif + +public: + + bool functionaddArgument(KviKvsObjectFunctionCall *c); + bool functionstartProcess(KviKvsObjectFunctionCall *c); + bool functionreadStdout(KviKvsObjectFunctionCall *c); + bool functionreadStderr(KviKvsObjectFunctionCall *c); + bool functionwriteToStdin(KviKvsObjectFunctionCall *c); + bool functionclosekill(KviKvsObjectFunctionCall *c); + bool functioncloseStdin(KviKvsObjectFunctionCall *c); + bool functionkill(KviKvsObjectFunctionCall *c); + bool functiontryTerminate(KviKvsObjectFunctionCall *c); + bool functionnormalExit(KviKvsObjectFunctionCall *c); + bool functionisRunning(KviKvsObjectFunctionCall *c); + + bool functionreadyReadStdoutEvent(KviKvsObjectFunctionCall *c); + bool functionreadyReadStderrEvent(KviKvsObjectFunctionCall *c); + +protected slots: + void slotReadStdout(); + void slotReadStderr(); +}; + + +#endif // !_CLASS_PROCESS_H_ diff --git a/src/modules/objects/class_progressbar.cpp b/src/modules/objects/class_progressbar.cpp new file mode 100644 index 00000000..12fc5b39 --- /dev/null +++ b/src/modules/objects/class_progressbar.cpp @@ -0,0 +1,162 @@ +// +// File : class_progressbar.cpp +// Creation date : Fri Jan 28 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 "class_progressbar.h" +#include "kvi_error.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_iconmanager.h" +#ifdef COMPILE_USE_QT4 +#include +#define KVI_PROGRESS_BAR Q3ProgressBar +#else +#include +#define KVI_PROGRESS_BAR QProgressBar +#endif + +/* + @doc: progressbar + @keyterms: + progressbar object class, + @title: + progressbar class + @type: + class + @short: + Provides a horizontal progress bar. + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + This widget can be used to display a horizontal progress bar. + @functions: + !fn: $setProgress() + Set the amount of steps completed. + See also [classfnc]$settotalSteps[/classfnc]() + !fn: $settotalSteps() + The progress bar uses the concept of steps; you give it the total number of steps + and the number of steps completed so far and it will display the percentage of steps that have been completed. + See also [classfnc]$setProgress[/classfnc]() + !fn: $reset() + Reset the progress bar. + !fn: $setCenterIndicator() + Sets whether the indicator string should be centered to on. + See also [classfnc]$isCenterIndicator[/classfnc]() + !fn: $isCenterIndicator() + This property holds whether the indicator string should be centered. + See also [classfnc]$setCenterIndicator[/classfnc]() + !fn: $setPercentageVisible() + Sets whether the current progress value is displayed. + See also [classfnc]$isPercentageVisible[/classfnc]() + !fn: $ispercentageVisible() + This property holds whether the current progress value is displayed. + See also [classfnc]$setPercentageVisible[/classfnc]() +*/ + +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) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_progressbar,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_progressbar) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_progressbar) + +KVSO_END_CONSTRUCTOR(KviKvsObject_progressbar) + +bool KviKvsObject_progressbar::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + #ifdef COMPILE_USE_QT4 + Q3ProgressBar *pbar=new Q3ProgressBar(parentScriptWidget()); + pbar->setObjectName(name()); + setObject(pbar,true); + #else + setObject(new QProgressBar(parentScriptWidget(), name()), true); + #endif +return true; +} + +bool KviKvsObject_progressbar::functionSetProgress(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t iProgress; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("step_value",KVS_PT_UNSIGNEDINTEGER,0,iProgress) + KVSO_PARAMETERS_END(c) + if (widget()) ((KVI_PROGRESS_BAR *)widget())->setProgress(iProgress); + return true; +} +bool KviKvsObject_progressbar::functionSetTotalSteps(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t iSteps; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("total_steps",KVS_PT_UNSIGNEDINTEGER,0,iSteps) + KVSO_PARAMETERS_END(c) + if (widget()) ((KVI_PROGRESS_BAR *)widget())->setTotalSteps(iSteps); + return true; +} + +bool KviKvsObject_progressbar::functionReset(KviKvsObjectFunctionCall *c) +{ + if (widget()) ((KVI_PROGRESS_BAR *)widget())->reset(); + return true; +} + +bool KviKvsObject_progressbar::functionSetCenterIndicator(KviKvsObjectFunctionCall *c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bFlag) + KVSO_PARAMETERS_END(c) + if(widget()) ((KVI_PROGRESS_BAR *)widget())->setCenterIndicator(bFlag); + return true; +} +bool KviKvsObject_progressbar::functionCenterIndicator(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setBoolean(((KVI_PROGRESS_BAR *)widget())->centerIndicator()); + return true; +} + +bool KviKvsObject_progressbar::functionSetPercentageVisible(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((KVI_PROGRESS_BAR *)widget())->setPercentageVisible(bEnabled); + return true; +} +bool KviKvsObject_progressbar::functionPercentageVisible(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setBoolean(((KVI_PROGRESS_BAR *)widget())->percentageVisible()); + return true; +} diff --git a/src/modules/objects/class_progressbar.h b/src/modules/objects/class_progressbar.h new file mode 100644 index 00000000..44c4eac8 --- /dev/null +++ b/src/modules/objects/class_progressbar.h @@ -0,0 +1,51 @@ +#ifndef _CLASS_PROGRESSBAR_H_ + +#define _CLASS_PROGRESSBAR_H_ +// +// File : class_progressbar.h +// Creation date : Fri Jan 28 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 +#include "class_widget.h" +#include "object_macros.h" + +class KviKvsObject_progressbar : public KviKvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KviKvsObject_progressbar) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool functionSetProgress(KviKvsObjectFunctionCall *c); + bool functionSetTotalSteps(KviKvsObjectFunctionCall *c); + bool functionReset(KviKvsObjectFunctionCall *c); + bool functionSetPercentageVisible(KviKvsObjectFunctionCall *c); + bool functionSetCenterIndicator(KviKvsObjectFunctionCall *c); + bool functionCenterIndicator(KviKvsObjectFunctionCall *c); + bool functionPercentageVisible(KviKvsObjectFunctionCall *c); +}; + + +#endif //!_CLASS_PROGRESSBAR_H_ + diff --git a/src/modules/objects/class_radiobutton.cpp b/src/modules/objects/class_radiobutton.cpp new file mode 100644 index 00000000..08211e12 --- /dev/null +++ b/src/modules/objects/class_radiobutton.cpp @@ -0,0 +1,138 @@ +// +// File : class_radiobutton.cpp +// Creation date : Thu Feb 08 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 "class_radiobutton.h" +#include "kvi_error.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_iconmanager.h" + +/* + @doc: radiobutton + @keyterms: + radiobutton widget class + @title: + radiobutton class + @type: + class + @short: + A radiobutton class + @inherits: + [class]widget[/class] + @description: + The RadioButton widget provides a radio button with a text or pixmap label. + @functions: + !fn: $settext() + Sets the text that will appear in the radiobutton. + !fn: $isChecked() + Returns 1 (TRUE) if the radio button is checked; otherwise returns 0 (FALSE). + !fn: $setChecked() + Sets whether the radio button is checked to check. + !fn: $setPixmap() + Sets the pixmap shown on the radiobutton..See the [doc:image_id]image identifier[/doc] documentation for the explaination + of the parameter. + !fn: $toggleEvent() + Called by KVIrc when the radibutton state is toggled. + The default implementation emits the toggled() signal. + !sg: $toggled() + This signal is emitted by the default implementation of [classfnc]$toggleEvent[/classfnc]().[br] + + +*/ + + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_radiobutton,"radiobutton","widget") + + KVSO_REGISTER_HANDLER(KviKvsObject_radiobutton,"setText", functionSetText) + KVSO_REGISTER_HANDLER(KviKvsObject_radiobutton,"setChecked", functionSetChecked) + KVSO_REGISTER_HANDLER(KviKvsObject_radiobutton,"isChecked", functionIsChecked) + KVSO_REGISTER_HANDLER(KviKvsObject_radiobutton,"setImage", functionSetImage) + KVSO_REGISTER_HANDLER(KviKvsObject_radiobutton,"toggleEvent",function_toggleEvent) + +KVSO_END_REGISTERCLASS(KviKvsObject_radiobutton) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_radiobutton,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_radiobutton) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_radiobutton) + +KVSO_END_CONSTRUCTOR(KviKvsObject_radiobutton) + +bool KviKvsObject_radiobutton::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + setObject(new QRadioButton(parentScriptWidget(),name()),true); + connect(widget(),SIGNAL(toggled(bool)),this,SLOT(toggled(bool))); + return true; +} +bool KviKvsObject_radiobutton::functionSetText(KviKvsObjectFunctionCall *c) +{ + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QRadioButton *)widget())->setText(szText); + return true; +} +bool KviKvsObject_radiobutton::functionIsChecked(KviKvsObjectFunctionCall *c) +{ + if(widget()) c->returnValue()->setBoolean(((QRadioButton *)widget())->isChecked()); + return true; +} + +bool KviKvsObject_radiobutton::functionSetChecked(KviKvsObjectFunctionCall *c) +{ + bool bChecked; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bChecked",KVS_PT_BOOL,0,bChecked) + KVSO_PARAMETERS_END(c) + if(widget()) ((QRadioButton *)widget())->setChecked(bChecked); + return true; +} +bool KviKvsObject_radiobutton::functionSetImage(KviKvsObjectFunctionCall *c) +{ + QString icon; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("icon_id",KVS_PT_STRING,0,icon) + KVSO_PARAMETERS_END(c) + if (!widget()) return true; + QPixmap * pix = g_pIconManager->getImage(icon); + if(pix)widget()->setIcon(*pix); + return true; +} +bool KviKvsObject_radiobutton::function_toggleEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("toggled",c,c->params()); + return true; +} + +void KviKvsObject_radiobutton::toggled(bool b) +{ + KviKvsVariantList params(new KviKvsVariant(b)); + callFunction(this,"toggleEvent",¶ms); +} + + +#include "m_class_radiobutton.moc" diff --git a/src/modules/objects/class_radiobutton.h b/src/modules/objects/class_radiobutton.h new file mode 100644 index 00000000..127af8cd --- /dev/null +++ b/src/modules/objects/class_radiobutton.h @@ -0,0 +1,51 @@ +#ifndef _CLASS_RADIOBUTTON_H_ +#define _CLASS_RADIOBUTTON_H_ +//mdm: +// File : class_radiobutton.h +// Creation date :Thu Feb 08 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 +#include "class_widget.h" + + +#include "object_macros.h" + +class KviKvsObject_radiobutton : public KviKvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_radiobutton) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool functionSetText(KviKvsObjectFunctionCall *c); + bool functionIsChecked(KviKvsObjectFunctionCall *c); + bool functionSetChecked(KviKvsObjectFunctionCall *c); + bool functionSetImage(KviKvsObjectFunctionCall *c); + bool function_toggleEvent(KviKvsObjectFunctionCall *c); +protected slots: + void toggled(bool b); + +}; + +#endif //!_CLASS_RADIOBUTTON_H_ diff --git a/src/modules/objects/class_slider.cpp b/src/modules/objects/class_slider.cpp new file mode 100644 index 00000000..603e4c9a --- /dev/null +++ b/src/modules/objects/class_slider.cpp @@ -0,0 +1,287 @@ +//mdm : +// File : class_Slider.cpp +// Creation date : Mon Gen 27 21:30:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 "class_slider.h" +#include "kvi_error.h" + +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_iconmanager.h" + + +/* +@doc: slider + @keyterms: + slider object class + @title: + slider class + @type: + class + @short: + The slider widget provides a vertical or horizontal slider. + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + The slider is the classic widget for controlling a bounded value.[br] + It lets the user move a slider along a horizontal or vertical groove [br] + and translates the slider's position into an integer value within the legal range.[/classfnc]() + @functions: + !fn: $setOrientation() + Sets the slider's orientation.[br] + Orientation value can be "Horizontal" or "Vertical". + !fn: $setTracking() + Sets whether slider tracking is enabled to enable.[br] + Value can be 1 or 0. + !fn: $setMaxValue() + Sets maximum value for slider's range. + !fn: $setMinValue() + Sets minimum value for slider's range. + !fn: $setLineStep() + Sets the line step to . + !fn: $setPageStep() + Sets the page step to . + !fn: $setTickmarks() + Sets the tickmark settings for this slider.[br] + Values are:[br] + NoMarks - do not draw any tickmarks.[br] + Both - draw tickmarks on both sides of the groove.[br] + Above - draw tickmarks above the (horizontal) slider[br] + Below - draw tickmarks below the (horizontal) slider[br] + Left - draw tickmarks to the left of the (vertical) slider[br] + Right - draw tickmarks to the right of the (vertical) slider + !fn: $setTickInterval() + Sets the interval between tickmarks. + !fn: $value() + Returns slider value. + !fn: $minValue() + Returns slider minValue. + !fn: $maxValue() + Returns slider maxValue. + !fn: $lineStep() + Returns slider lineStep value. + !fn: $pageStep() + Returns slider pageStep value. + !fn: $valueChangedEvent() + This function is called by the framework when the slider value is changed and return the new slider value as its argument.[br] + The default implementation emits the [classfnc]$valueChanged[/classfnc]() signal, + so it is easy to handle the values from many sliders without reimplementing + the [classfnc]$valueChangedEvent[/classfnc]() for every one.[br] + Note: If you reimplement this function to catch the slider value, you will have to emit the signal by yourself (if you still need it, obviously). + @signals: + !sg: $valueChanged() + This signal is emitted by the default implementation of [classfnc]valueChangedEvent[/classfnc]().[br] + If you reimplement that function you will have to emit the signal manually (if you still need it). + +*/ + + + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_slider,"slider","widget") + + + KVSO_REGISTER_HANDLER(KviKvsObject_slider,"setTracking", functionsetTracking); + KVSO_REGISTER_HANDLER(KviKvsObject_slider,"setValue", functionsetValue); + KVSO_REGISTER_HANDLER(KviKvsObject_slider,"setMinValue", functionsetMinValue); + KVSO_REGISTER_HANDLER(KviKvsObject_slider,"setMaxValue", functionsetMaxValue); + KVSO_REGISTER_HANDLER(KviKvsObject_slider,"setLineStep", functionsetLineStep); + KVSO_REGISTER_HANDLER(KviKvsObject_slider,"setPageStep", functionsetPageStep); + KVSO_REGISTER_HANDLER(KviKvsObject_slider,"setTickInterval", functionsetTickInterval); + KVSO_REGISTER_HANDLER(KviKvsObject_slider,"value",functionvalue); + KVSO_REGISTER_HANDLER(KviKvsObject_slider,"minValue", functionminValue); + KVSO_REGISTER_HANDLER(KviKvsObject_slider,"maxValue", functionmaxValue); + KVSO_REGISTER_HANDLER(KviKvsObject_slider,"lineStep", functionlineStep); + KVSO_REGISTER_HANDLER(KviKvsObject_slider,"pageStep", functionpageStep); + KVSO_REGISTER_HANDLER(KviKvsObject_slider,"setTickmarks", functionsetTickmarks); + KVSO_REGISTER_HANDLER(KviKvsObject_slider,"setOrientation", functionsetOrientation); + + + KVSO_REGISTER_HANDLER(KviKvsObject_slider,"valueChangedEvent", functionvalueChangedEvent); +KVSO_END_REGISTERCLASS(KviKvsObject_slider) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_slider,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_slider) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_slider) + +KVSO_END_CONSTRUCTOR(KviKvsObject_slider) + +bool KviKvsObject_slider::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + setObject(new QSlider(parentScriptWidget(), name()), true); + connect(widget(),SIGNAL(valueChanged(int)),this,SLOT(valueChanged(int))); + return true; +} + +bool KviKvsObject_slider::functionsetTracking(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QSlider *)widget())->setTracking(bEnabled); + return true; +} + + +bool KviKvsObject_slider::functionsetValue(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iValue; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("value",KVS_PT_INT,0,iValue) + KVSO_PARAMETERS_END(c) + if (widget()) ((QSlider *)widget())->setValue(iValue); + return true; +} +bool KviKvsObject_slider::functionsetMinValue(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iMinvalue; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("minimum_value",KVS_PT_INT,0,iMinvalue) + KVSO_PARAMETERS_END(c) + if (widget()) ((QSlider *)widget())->setMinValue(iMinvalue); + return true; +} +bool KviKvsObject_slider::functionsetMaxValue(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iMaxvalue; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("max_value",KVS_PT_INT,0,iMaxvalue) + KVSO_PARAMETERS_END(c) + if (widget()) ((QSlider *)widget())->setMaxValue(iMaxvalue); + return true; +} + +bool KviKvsObject_slider::functionsetLineStep(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iLinestep; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("line_step",KVS_PT_INT,0,iLinestep) + KVSO_PARAMETERS_END(c) + if (widget()) ((QSlider *)widget())->setLineStep(iLinestep); + return true; +} +bool KviKvsObject_slider::functionsetPageStep(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iPagestep; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("page_step",KVS_PT_INT,0,iPagestep) + KVSO_PARAMETERS_END(c) + if (widget()) ((QSlider *)widget())->setPageStep(iPagestep); + return true; +} + +bool KviKvsObject_slider::functionsetTickInterval(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iInterval; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("tick_interval",KVS_PT_INT,0,iInterval) + KVSO_PARAMETERS_END(c) + if (widget()) ((QSlider *)widget())->setTickInterval(iInterval); + return true; +} + +bool KviKvsObject_slider::functionvalue(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setInteger(((QSlider *)widget())->value()); + return true; +} + +bool KviKvsObject_slider::functionminValue(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setInteger(((QSlider *)widget())->minValue()); + return true; +} +bool KviKvsObject_slider::functionmaxValue(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setInteger(((QSlider *)widget())->maxValue()); + return true; +} +bool KviKvsObject_slider::functionlineStep(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setInteger(((QSlider *)widget())->lineStep()); + return true; +} + +bool KviKvsObject_slider::functionpageStep(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setInteger(((QSlider *)widget())->pageStep()); + return true; +} + + +bool KviKvsObject_slider::functionsetTickmarks(KviKvsObjectFunctionCall *c) +{ + + QString szTick; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("tick_marks",KVS_PT_STRING,0,szTick) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + if(KviQString::equalCI(szTick,"NoMarks")) + ((QSlider *)widget())->setTickmarks(QSlider::NoMarks); + else if(KviQString::equalCI(szTick,"Both")) + ((QSlider *)widget())->setTickmarks(QSlider::Both); + else if(KviQString::equalCI(szTick,"Above")) + ((QSlider *)widget())->setTickmarks(QSlider::Above); + else if(KviQString::equalCI(szTick,"Below")) + ((QSlider *)widget())->setTickmarks(QSlider::Below); + else if(KviQString::equalCI(szTick,"Left")) + ((QSlider *)widget())->setTickmarks(QSlider::Left); + else if(KviQString::equalCI(szTick,"Right")) + ((QSlider *)widget())->setTickmarks(QSlider::Right); + else c->warning( __tr2qs("Unknown tickmark '%Q'"),&szTick); + return true; +} +bool KviKvsObject_slider::functionsetOrientation(KviKvsObjectFunctionCall *c) +{ + + QString szOrientation; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("orientation",KVS_PT_STRING,0,szOrientation) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + if(KviQString::equalCI(szOrientation,"Horizontal")) + ((QSlider *)widget())->setOrientation(Qt::Horizontal); + else if(KviQString::equalCI(szOrientation,"Vertical")) + ((QSlider *)widget())->setOrientation(Qt::Vertical); + else c->warning( __tr2qs("Unknown orientation '%Q'"),&szOrientation); + return true; +} +bool KviKvsObject_slider::functionvalueChangedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("valueChanged",c,c->params()); + return true; +} + +void KviKvsObject_slider::valueChanged(int value) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)value)); + callFunction(this,"valueChangedEvent",¶ms); +} + + +#include "m_class_slider.moc" diff --git a/src/modules/objects/class_slider.h b/src/modules/objects/class_slider.h new file mode 100644 index 00000000..e2c8c397 --- /dev/null +++ b/src/modules/objects/class_slider.h @@ -0,0 +1,64 @@ +#ifndef _CLASS_SLIDER_H_ +#define _CLASS_SLIDER_H_ +//mdm: +// File : class_Slider.h +// Creation date : Mon Gen 27 14:30:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 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 +#include "class_widget.h" + + +#include "object_macros.h" + +class KviKvsObject_slider : public KviKvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_slider) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool functionsetTracking(KviKvsObjectFunctionCall *c); + bool functionsetValue(KviKvsObjectFunctionCall *c); + bool functionsetMinValue(KviKvsObjectFunctionCall *c); + bool functionsetMaxValue(KviKvsObjectFunctionCall *c); + bool functionsetLineStep(KviKvsObjectFunctionCall *c); + bool functionsetPageStep(KviKvsObjectFunctionCall *c); + bool functionsetTickInterval(KviKvsObjectFunctionCall *c); + bool functionvalue(KviKvsObjectFunctionCall *c); + bool functionminValue(KviKvsObjectFunctionCall *c); + bool functionmaxValue(KviKvsObjectFunctionCall *c); + bool functionlineStep(KviKvsObjectFunctionCall *c); + bool functionpageStep(KviKvsObjectFunctionCall *c); + bool functionsetTickmarks(KviKvsObjectFunctionCall *c); + bool functionsetOrientation(KviKvsObjectFunctionCall *c); + bool functionvalueChangedEvent(KviKvsObjectFunctionCall *c); + +protected slots: + void valueChanged(int); +}; + + + +#endif // !_CLASS_SLIDER_H_ + diff --git a/src/modules/objects/class_socket.cpp b/src/modules/objects/class_socket.cpp new file mode 100644 index 00000000..f0afe3a5 --- /dev/null +++ b/src/modules/objects/class_socket.cpp @@ -0,0 +1,1331 @@ +// +// File : class_socket.cpp +// Creation date : Sun Nov 11 03:13:45 2001 GMT by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2001 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 "kvi_settings.h" +#include "kvi_qstring.h" + +#define _KVI_DEBUG_CHECK_RANGE_ +#include "kvi_debug.h" + + +#include "kvi_locale.h" +#include "kvi_error.h" +#include "kvi_netutils.h" +#include "kvi_dns.h" +#include "kvi_error.h" +#include "kvi_socket.h" +#include "kvi_malloc.h" +#include "kvi_memmove.h" +#include "kvi_databuffer.h" +#include "kvi_qcstring.h" + +#include "class_socket.h" + +//#include + +#define KVI_IN_BUFFER_ALLOC_CHUNK 4096 +#define KVI_READ_CHUNK 1024 +/* +static KviScriptObjectClass * g_pSocketClass = 0; + +static KviScriptObject * socketClassCreateInstance(KviScriptObjectClass * cls,KviScriptObject *par,const char * nam) +{ + return new KviScriptSocketObject(cls,par,nam); +} + +KviScriptSocketObject::KviScriptSocketObject(KviScriptObjectClass * cla,KviScriptObject * par,const char * nam) +: KviScriptObject(cla,par,nam) +{ + m_uConnectionId = 0; + m_sock = KVI_INVALID_SOCKET; + m_iStatus = KVI_SCRIPT_SOCKET_STATUS_DISCONNECTED; + m_uRemotePort = 0; + m_uSecondaryPort = 0; + m_pSn = 0; + m_pDns = 0; + m_pDelayTimer = 0; + m_uConnectTimeout = 60000; + m_pInBuffer = 0; + m_uInBufferLen = 0; + m_uInDataLen = 0; + m_pOutBuffer = new KviDataBuffer(); + m_pFlushTimer = new QTimer(); + m_bIpV6 = false; + m_uLocalPort = 0; + m_secondarySock = KVI_INVALID_SOCKET; + connect(m_pFlushTimer,SIGNAL(timeout()),this,SLOT(tryFlush())); +} + +KviScriptSocketObject::~KviScriptSocketObject() +{ + delete m_pOutBuffer; + delete m_pFlushTimer; + + if(m_pInBuffer)kvi_free(m_pInBuffer); + if(m_pDelayTimer)delete m_pDelayTimer; + if(m_pDns)delete m_pDns; + if(m_pSn)delete m_pSn; + if(m_sock != KVI_INVALID_SOCKET)kvi_socket_close(m_sock); + if(m_secondarySock != KVI_INVALID_SOCKET)kvi_socket_close(m_secondarySock); +} + +void KviScriptSocketObject::reset() +{ + m_uConnectionId++; // this is the only place where this is incremented! + if(m_pDelayTimer) + { + delete m_pDelayTimer; + m_pDelayTimer = 0; + } + if(m_pDns) + { + delete m_pDns; + m_pDns = 0; + } + if(m_pSn) + { + delete m_pSn; + m_pSn = 0; + } + if(m_sock != KVI_INVALID_SOCKET) + { + kvi_socket_close(m_sock); + m_sock = KVI_INVALID_SOCKET; + } + if(m_pInBuffer) + { + kvi_free(m_pInBuffer); + m_pInBuffer = 0; + } + if(m_secondarySock) + { + kvi_socket_close(m_secondarySock); + m_secondarySock = KVI_INVALID_SOCKET; + } + m_uSecondaryPort = 0; + m_szSecondaryIp.clear(); + delete m_pOutBuffer; + if(m_pFlushTimer->isActive())m_pFlushTimer->stop(); + m_pOutBuffer = new KviDataBuffer(); + m_uInBufferLen = 0; + m_uInDataLen = 0; + m_iStatus = KVI_SCRIPT_SOCKET_STATUS_DISCONNECTED; + m_uRemotePort = 0; + m_szRemoteIp.clear(); + m_uLocalPort = 0; + m_szLocalIp.clear(); + m_bIpV6 = false; +} + +/* + @doc: socket + @keyterms: + socket object class + @title: + socket class + @type: + class + @short: + A Ipv4/Ipv6 TCP socket + @inherits: + [class]object[/class] + @description: + This class provides a standard TCP/IP socket functionality.[br] + It can be used either for connecting to a remote host or to listening for incoming connections.[br] + If the KVIrc executable has been compiled with the IPV6 protocol support , this socket also supports it.[br] + @functions: + !fn: $status() + Returns the status of the socket :[br] + 4=connected[br] + 3=listening[br] + 2=connecting[br] + 1=in dns call[br] + 0=disconnected + + !fn: $connectTimeout() + Returns the value of the connect attempt timeout in milliseconds.[br] + This is the timeout after that a connection attempt will be considered as failed if the remote + host is not responding. You can set it with [classfnc:socket]$setConnectTimeout[/classfnc](). + + !fn: $setConnectTimeout() + Sets the connect timeout for this socket. must be a positive value in milliseconds.[br] + The default timeout is 60000. + + !fn: $connect(,) + Attempts a connection to on port .[br] + can be a numeric internet address (either Ipv4 or Ipv6 (if supported)) or a hostname.[br] + If a hostname is used, a DNS lookup is performed (the socket enters the "dns call" state).[br] + This function returns 1 if the connect attempt can be succesfully initiated, + 0 otherwise.[br] In fact , this function returns 0 only if the supplied parameter + is invalid or the socket is in an incoherent state (already connected or listening): + for a newly created socket and with a valid number you can safely ignore + the return value.[br] + Please note that the connection is asynchronous: when this function returns + the socket is NOT connected: it has just initiated the connect attempt + and you will be notified of the attempt result by an asynchronous event call: + in case of failure , $connectFailedEvent() will be called , in case of + succes , $connectEvent() will be called. + + !fn: $listen([[,[,]]]) + Attempts to listen on the specified and .[br] + If is not passed it is assumed to be 0 , if is not passed , it is assumed to be + "any interface" (INADDR_ANY).[br] Port 0 means that the kernel should choose a "random" port to listen on.[br] + If the is recognized as IPV6 address , and IPV6 is supported , the socket listens + in IPV6 mode. If is an empty string and is 1 the socket listens + on "any ipv6 interface".[br] + This function returns '1' in case of success and '0' in case of failure.[br] + On some systems listening in the IPV6 namespace allows to accept also IPV4 connections (this includes + linux but not windows afaik).[br] + When an incoming connection will arrive , $incomingConnectionEvent() will be called. + + !fn: $accept() + This function can be called only from inside $incomingConnectionEvent().[br] + must be a newly created socket sub-class instance object.[br] + The passed object will be set up to handle the incoming connection and this object + will remain in listening state (unless you explicitly close it).[br] + This function returns '1' in case of success and '0' in case of failure. + + !fn: $connectEvent() + This function is called when a connection attempt has been succesfully completed. + The socket is actually connected to [classfnc:socket]$remoteIp[/classfnc]() on + [classfnc:socket]$remotePort[/classfnc](). You can start + writing data and you may expect [classfnc:socket]$dataAvailableEvent[/classfnc]() to be + triggered. + + !fn: $incomingConnectionEvent() + This function is called when an incoming connection arrives over a socket in listening state.[br] + You must call [classfnc:socket]$accept[/classfnc]() passing a newly created socket object + to accept and handle the connection.[br] If you don't call [classfnc:socket]$accept[/classfnc]() + the incoming connection will be automatically terminated. + + !fn: $connectFailedEvent() + This function is called when a connection attempt fails for some reason. contains + the error string.[br] + This function may be called only between a call to [classfnc:socket]$connect[/classfnc]() and + the [classfnc:socket]$connectEvent[/classfnc](). + + !fn: $disconnectEvent([error]) + This function is called when a connection is terminated either cleanly or because of an error.[br] + [error] is an empty string in case of a "clean" termination (connection closed by the remote host) + or is a message describing the socket error that caused the connection to be interrupted. + + !fn: $dataAvailableEvent() + This function is called when some data is available to be read: the parameter specifies + the length of the available data in bytes.[br] + You can use one of the $read* functions to obtain the data. + + !fn: $read() + Reads at most bytes of data from the socket. If is anything "outside" the + available data range ( < 0 or > available_data_length), this function + returns all the available data.[br] + Please note that this function can't deal withi binary data: NULL characters are transformed to + ASCII characters 255. + + !fn: $readHex() + Reads at most bytes of data from the socket. If is anything "outside" the + available data range ( < 0 or > available_data_length), this function + returns all the available data.[br] + Returns the data encoded as hexadecimal digit string: this function can deal with binary data too. + + !fn: $write() + Writes to the socket.[br] + This function can't deal with binary data (you can't send a NULL character)[br] + Please note that when this function finishes it does not mean that the data has reached the remote end.[br] + Basically it does not even mean that the data has been sent to the remote host.[br] + The data is enqueued for sending and will be sent as soon as possible.[br] + If you're going to [cmd]delete[/cmd] this object just after the $write call, you should + call [classfnc:socket]$close[/classfnc]() just before [cmd]delete[/cmd] to ensure the data delivery. + + !fn: $writeHex() + Writes to the socket.[br] + is expected to be a hexadecimal rappresentation of the bytes to be sent (two HEX characters + for each byte). This means that the length of string must be a multiple of 2.[br] + Returns the length of the actually decoded and sent data in bytes or -1 in case of error (the string + was not a valid hexadecimla rappresentation).[br] + Please note that when this function finishes it does not mean that the data has reached the remote end.[br] + Basically it does not even mean that the data has been sent to the remote host.[br] + The data is enqueued for sending and will be sent as soon as possible.[br] + If you're going to [cmd]delete[/cmd] this object just after the $writeHex call, you should + call [classfnc:socket]$close[/classfnc]() just before [cmd]delete[/cmd] to ensure the data delivery. + + !fn: $close() + Resets this socket state: kills any pending or active connection. After a close() call + the socket may be used for a new connection.[br] + If there is an active connection, there is a last attempt to flush the pending outgoing data.[br] + You don't need to call $close() if you [cmd]delete[/cmd] the socket: KVIrc will + reset the socket state automatically and free the memory. But if you want to ensure data delivery + after a $write call sequece and just before a [cmd]delete[/cmd], $close() is the only chance to do it. + + !fn: $remoteIp() + Returns the IP address of the remote end of this socket.[br] + The return value is meaningful only if the socket is in connected or connecting state. + + !fn: $setProtocol() + Let KVIrc use TCP jr UDP protocol + + !fn: $remotePort() + Returns the port of the remote end of this socket.[br] + The return value is meaningful only if the socket is in connected or connecting state. + + !fn: $localIp() + Returns the IP address of the local end of this socket.[br] + The return value is meaningful only if the socket is in connected , listening or connecting state. + + !fn: $localPort() + Returns the port of the local end of this socket.[br] + The return value is meaningful only if the socket is in connected , listening or connecting state. + +@examples: + [example] + #Server socket: listen 80 port and answer to requests (multi-threaded)[br] +[br] + class (webserver,socket) {[br] + constructor () {[br] + $$->$listen(80, "127.0.0.1")[br] + }[br] + incomingConnectionEvent()[br] + {[br] + %tmp = $new(socket)[br] + $$->$accept(%tmp)[br] + echo "Webserver incoming Conection from: %tmp->$remoteIp : %tmp->$remotePort"[br] + %tmp->$write("HTTP/1.1 200 OK\n\n

KVIrc Webserver

\n")[br] + %tmp->$close()[br] + delete %tmp[br] + }[br] + }[br] + [br] + #finally start webserver[br] + %WebS = $new(webserver)[br] + [br] + [/example] + [example] + #Client socket - go to google and grab request header[br] + class (httprequest,socket) {[br] + constructor () [br] + {[br] + # connect to the server[br] + $$->$connect("www.google.de",80)[br] + }[br] + destructor()[br] + {[br] + # if the socket is still open close it[br] + if($$->$status() == 4) $$->$close()[br] + }[br] + connectFailedEvent() [br] + {[br] + # the connection to the server failed[br] + echo "Connection failed: "$0[br] + delete $$[br] + }[br] + connectEvent() [br] + {[br] + # connection is complete[br] + # send a request to receive the headers only from http://www.google.de/[br] + $$->$write("HEAD / HTTP/1.1\r\nHost: www.google.de\r\nConnction: Close\r\nUser-Agent: KVIrc socket\r\n\r\n");[br] + }[br] + dataAvailableEvent() [br] + {[br] + # reading the received data[br] + %newdata = $$->$read($0)[br] + echo %newdata[br] + #close and delete the socket[br] + $$->$close()[br] + delete $$[br] + }[br] + disconnectEvent() [br] + {[br] + # connection has been closed[br] + echo "Connection closed"[br] + delete $$[br] + }[br] +}[br] + +#Creating the socket[br] +%Temp = $new(httprequest)[br] + [/example] +*/ + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_socket,"socket","object") + + KVSO_REGISTER_HANDLER(KviKvsObject_socket,"status",functionStatus) + KVSO_REGISTER_HANDLER(KviKvsObject_socket,"remotePort",functionRemotePort) + KVSO_REGISTER_HANDLER(KviKvsObject_socket,"remoteIp",functionRemoteIp) + KVSO_REGISTER_HANDLER(KviKvsObject_socket,"localIp",functionLocalIp) + KVSO_REGISTER_HANDLER(KviKvsObject_socket,"localPort",functionLocalPort) + KVSO_REGISTER_HANDLER(KviKvsObject_socket,"connect",functionConnect) + KVSO_REGISTER_HANDLER(KviKvsObject_socket,"connectTimeout",functionConnectTimeout) + KVSO_REGISTER_HANDLER(KviKvsObject_socket,"setConnectTimeout",functionSetConnectTimeout) + KVSO_REGISTER_HANDLER(KviKvsObject_socket,"close",functionClose) + KVSO_REGISTER_HANDLER(KviKvsObject_socket,"read",functionRead) + KVSO_REGISTER_HANDLER(KviKvsObject_socket,"readHex",functionReadHex) + KVSO_REGISTER_HANDLER(KviKvsObject_socket,"write",functionWrite) + KVSO_REGISTER_HANDLER(KviKvsObject_socket,"writeHex",functionWriteHex) + KVSO_REGISTER_HANDLER(KviKvsObject_socket,"setProtocol",functionSetProtocol) + KVSO_REGISTER_HANDLER(KviKvsObject_socket,"listen",functionListen) + KVSO_REGISTER_HANDLER(KviKvsObject_socket,"accept",functionAccept) + + KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KviKvsObject_socket,"connectEvent") + KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KviKvsObject_socket,"connectFailedEvent") + KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KviKvsObject_socket,"disconnectEvent") + KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KviKvsObject_socket,"dataAvailableEvent") + KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KviKvsObject_socket,"incomingConnectionEvent") + +KVSO_END_REGISTERCLASS(KviKvsObject_socket) + + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_socket,KviKvsObject) + + + m_bUdp = false; + m_uConnectionId = 0; + m_sock = KVI_INVALID_SOCKET; + m_iStatus = KVI_SCRIPT_SOCKET_STATUS_DISCONNECTED; + m_uRemotePort = 0; + m_uSecondaryPort = 0; + m_pSn = 0; + m_pDns = 0; + m_pDelayTimer = 0; + m_uConnectTimeout = 60000; + m_pInBuffer = 0; + m_uInBufferLen = 0; + m_uInDataLen = 0; + m_pOutBuffer = new KviDataBuffer(); + m_pFlushTimer = new QTimer(); + m_bIpV6 = false; + m_uLocalPort = 0; + m_secondarySock = KVI_INVALID_SOCKET; + connect(m_pFlushTimer,SIGNAL(timeout()),this,SLOT(tryFlush())); +KVSO_END_CONSTRUCTOR(KviKvsObject_socket) + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_socket) + delete m_pOutBuffer; + delete m_pFlushTimer; + + if(m_pInBuffer)kvi_free(m_pInBuffer); + if(m_pDelayTimer)delete m_pDelayTimer; + if(m_pDns)delete m_pDns; + if(m_pSn)delete m_pSn; + if(m_sock != KVI_INVALID_SOCKET)kvi_socket_close(m_sock); + if(m_secondarySock != KVI_INVALID_SOCKET)kvi_socket_close(m_secondarySock); +KVSO_END_DESTRUCTOR(KviKvsObject_socket) +//---------------------- + + +bool KviKvsObject_socket::functionStatus(KviKvsObjectFunctionCall *c) +{ + c->returnValue()->setInteger(m_iStatus); + return true; +} + +bool KviKvsObject_socket::functionClose(KviKvsObjectFunctionCall *c) +{ + if((m_pOutBuffer->size() != 0) && (m_iStatus == KVI_SCRIPT_SOCKET_STATUS_CONNECTED)) + tryFlush(); + + reset(); + return true; +} + +bool KviKvsObject_socket::functionConnectTimeout(KviKvsObjectFunctionCall *c) +{ + c->returnValue()->setInteger(m_uConnectTimeout); + return true; +} + +bool KviKvsObject_socket::functionSetConnectTimeout(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uTimeout; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("time_out",KVS_PT_UNSIGNEDINTEGER,0,uTimeout) + KVSO_PARAMETERS_END(c) + m_uConnectTimeout = uTimeout; + return true; +} + +bool KviKvsObject_socket::functionRemotePort(KviKvsObjectFunctionCall *c) +{ + c->returnValue()->setInteger(m_uRemotePort); + return true; +} + +bool KviKvsObject_socket::functionRemoteIp(KviKvsObjectFunctionCall *c) +{ + c->returnValue()->setString(m_szRemoteIp); + return true; +} + +bool KviKvsObject_socket::functionLocalPort(KviKvsObjectFunctionCall *c) +{ + c->returnValue()->setInteger(m_uLocalPort); + return true; +} + +bool KviKvsObject_socket::functionLocalIp(KviKvsObjectFunctionCall *c) +{ + c->returnValue()->setString(m_szLocalIp); + return true; +} + +bool KviKvsObject_socket::functionAccept(KviKvsObjectFunctionCall *c) +{ + KviKvsObject * pObject; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("object_socket",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETERS_END(c) + + pObject = KviKvsKernel::instance()->objectController()->lookupObject(hObject); + + if(!pObject) + { + c->warning(__tr2qs("No socket object specified")); + return true; + } + + if(!pObject->inherits("KviKvsObject_socket")) + { + c->warning(__tr2qs("Invalid socket object specified (it doesn't inherit from socket)")); + return true; + } + + if(m_secondarySock != KVI_INVALID_SOCKET) + { + ((KviKvsObject_socket *)pObject)->acceptConnection(m_secondarySock,m_uSecondaryPort,m_szSecondaryIp); + + m_secondarySock = KVI_INVALID_SOCKET; + m_uSecondaryPort = 0; + m_szSecondaryIp=""; + } else { + c->warning(__tr2qs("There is no connection to accept!")); + } + return true; +} + + +bool KviKvsObject_socket::functionSetProtocol(KviKvsObjectFunctionCall *c) +{ + QString m_szHex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("hex_string",KVS_PT_STRING,0,m_szHex) + KVSO_PARAMETERS_END(c) + + m_bUdp=KviQString::equalCI(m_szHex,"udp"); + return false; +} + +bool KviKvsObject_socket::functionWriteHex(KviKvsObjectFunctionCall *c) +{ + QString m_szHex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("hex_string",KVS_PT_STRING,0,m_szHex) + KVSO_PARAMETERS_END(c) + + if(m_szHex.length() > 0) + { + bool bOk; + QString szTmp; + szTmp=m_szHex.setNum(m_szHex.toInt(&bOk,16),16); + if(szTmp.length()>0) + { + KviQCString szData8 = szTmp.utf8(); + m_pOutBuffer->append((const unsigned char *)(szData8.data()),szData8.length()); + delayedFlush(0); + c->returnValue()->setInteger(szData8.length()); + } + } + + /* + if(pszData) + { + if(pszData->len() > 0) + { + char * ptr; + len = pszData->hexToBuffer(&ptr); + if(len > 0) + { + m_pOutBuffer->append((const unsigned char *)(ptr),len); + delayedFlush(0); + KviStr::freeBuffer(ptr); + } + } + } + buffer.append(KviStr::Format,"%d",len); +*/ + return true; +} + + + + + +bool KviKvsObject_socket::functionConnect(KviKvsObjectFunctionCall *c) +{ + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("remote_ip",KVS_PT_STRING,0,m_szRemoteIp) + KVSO_PARAMETER("remote_port",KVS_PT_UNSIGNEDINTEGER,0,m_uRemotePort) + KVSO_PARAMETERS_END(c) + debug ("Function connect"); + + + if (m_uRemotePort>65535) + { + c->warning(__tr2qs("Value %d for port is out of range (values allowed are from 0 to 65535"),m_uRemotePort); + return true; + } + if((m_sock != KVI_INVALID_SOCKET) || (m_iStatus != KVI_SCRIPT_SOCKET_STATUS_DISCONNECTED)) + { + c->warning(__tr2qs("Another connection in progress")); + c->returnValue()->setBoolean(true); + return true; + } + + +#ifdef COMPILE_IPV6_SUPPORT + if(kvi_isValidStringIp(m_szRemoteIp) || kvi_isValidStringIp_V6(m_szRemoteIp)) +#else + if(kvi_isValidStringIp(m_szRemoteIp)) +#endif + { + debug ("ok connecting"); + debug ("connectinhg on ip %s ",m_szRemoteIp.latin1()); + debug ("non so ip"); + m_iStatus = KVI_SCRIPT_SOCKET_STATUS_CONNECTING; + delayedConnect(); + } else { + debug ("connectinhg on ip %s port %d",m_szRemoteIp.latin1(),m_uRemotePort); + m_iStatus = KVI_SCRIPT_SOCKET_STATUS_DNS; + delayedLookupRemoteIp(); + } + c->returnValue()->setBoolean(true); + return true; +} + + + + + + +bool KviKvsObject_socket::functionListen(KviKvsObjectFunctionCall *c) +{ + if((m_sock != KVI_INVALID_SOCKET) || (m_iStatus != KVI_SCRIPT_SOCKET_STATUS_DISCONNECTED)) + { + c->warning(__tr2qs("Another connection in progress")); + c->returnValue()->setBoolean(false); + return true; + } + kvs_uint_t uLocalPort; + QString m_szLocalIp; + bool m_bIpV6; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("local_port",KVS_PT_UNSIGNEDINTEGER,0,uLocalPort) + KVSO_PARAMETER("local_ip",KVS_PT_STRING,KVS_PF_OPTIONAL,m_szLocalIp) + KVSO_PARAMETER("bool_ipV6",KVS_PT_BOOLEAN,KVS_PF_OPTIONAL,m_bIpV6) + KVSO_PARAMETERS_END(c) + m_uLocalPort=uLocalPort; + +#ifndef COMPILE_IPV6_SUPPORT + if(m_bIpV6) + { + c->warning(__tr2qs("No IPV6 support in this executable")); + c->returnValue()->setBoolean(false); + reset(); + return true; + } +#endif + + bool bGotIp = false; + + if(!m_szLocalIp.isEmpty()) + { + + // Check the address type + if(kvi_isValidStringIp(m_szLocalIp))bGotIp = true; + else { +#ifdef COMPILE_IPV6_SUPPORT + if(kvi_isValidStringIp_V6(m_szLocalIp)) + { + bGotIp = true; + m_bIpV6 = true; + } else { +#else + c->warning(__tr2qs("Invalid IP address specified ('%Q')"),&m_szLocalIp); + c->returnValue()->setBoolean(false); + reset(); + return true; +#endif +#ifdef COMPILE_IPV6_SUPPORT + } +#endif + } + } + + +#ifdef COMPILE_IPV6_SUPPORT + m_sock = kvi_socket_create(m_bIpV6 ? KVI_SOCKET_PF_INET6 : KVI_SOCKET_PF_INET, + m_bUdp ? KVI_SOCKET_TYPE_DGRAM : KVI_SOCKET_TYPE_STREAM,KVI_SOCKET_PROTO_TCP); +#else + m_sock = kvi_socket_create(KVI_SOCKET_PF_INET,m_bUdp ? KVI_SOCKET_TYPE_DGRAM : KVI_SOCKET_TYPE_STREAM,KVI_SOCKET_PROTO_TCP); +#endif + + if(m_sock == KVI_INVALID_SOCKET) + { + c->warning(__tr2qs("Socket creation failed")); + c->returnValue()->setBoolean(false); + reset(); + return true; + } + + if(!m_szLocalIp.isEmpty()) + { +#ifdef COMPILE_IPV6_SUPPORT + KviSockaddr sa(m_szLocalIp,m_uLocalPort,m_bIpV6,m_bUdp); +#else + KviSockaddr sa(m_szLocalIp,m_uLocalPort,false,m_bUdp); +#endif + if(!sa.socketAddress()) + { + c->warning(__tr2qs("Invalid socket address")); + reset(); + c->returnValue()->setBoolean(false); + return true; + } + + if(!kvi_socket_bind(m_sock,sa.socketAddress(),((int)(sa.addressLength())))) + { + c->warning(__tr2qs("Bind failure")); + reset(); + c->returnValue()->setBoolean(false); + return true; + } + } else { +#ifdef COMPILE_IPV6_SUPPORT + KviSockaddr sa(m_uLocalPort,m_bIpV6,m_bUdp); +#else + KviSockaddr sa(m_uLocalPort,false,m_bUdp); +#endif + if(!sa.socketAddress()) + { + c->warning(__tr2qs("Invalid socket address")); + reset(); + c->returnValue()->setBoolean(false); + return true; + } + + if(!kvi_socket_bind(m_sock,sa.socketAddress(),((int)(sa.addressLength())))) + { + c->warning(__tr2qs("Bind failure")); + reset(); + c->returnValue()->setBoolean(false); + return true; + } + } + + + if(!kvi_socket_listen(m_sock,5)) + { + c->warning(__tr2qs("Listen failure")); + reset(); + c->returnValue()->setBoolean(false); + return true; + } + + + // Reread the port in case we're binding to a random one (0) + +#ifdef COMPILE_IPV6_SUPPORT + KviSockaddr sareal(0,m_bIpV6,m_bUdp); +#else + KviSockaddr sareal(0,false,m_bUdp); +#endif + + int size = (int)sareal.addressLength(); + + if(kvi_socket_getsockname(m_sock,sareal.socketAddress(),&size)) + { + m_uLocalPort = sareal.port(); + sareal.getStringAddress(m_szLocalIp); + } + + // and setup the READ notifier... + m_pSn = new QSocketNotifier(m_sock,QSocketNotifier::Read); + QObject::connect(m_pSn,SIGNAL(activated(int)),this,SLOT(incomingConnection(int))); + m_pSn->setEnabled(true); + + m_iStatus = KVI_SCRIPT_SOCKET_STATUS_LISTENING; + + c->returnValue()->setBoolean(true); + return true; +} + +void KviKvsObject_socket::incomingConnection(int) +{ +#ifdef COMPILE_IPV6_SUPPORT + struct sockaddr_in6 hostSockAddr6; +#endif + struct sockaddr_in hostSockAddr; + + int size = sizeof(hostSockAddr); + struct sockaddr * addr = (struct sockaddr *)&hostSockAddr; + +#ifdef COMPILE_IPV6_SUPPORT + if(m_bIpV6) + { + addr = (struct sockaddr *)&hostSockAddr6; + size = sizeof(hostSockAddr6); + } +#endif + + // Incoming connection + m_secondarySock = kvi_socket_accept(m_sock,addr,&size); + if(m_secondarySock != KVI_INVALID_SOCKET) + { + // Connected +#ifdef COMPILE_IPV6_SUPPORT + if(m_bIpV6) + { + m_uSecondaryPort = ntohs(((struct sockaddr_in6 *)addr)->sin6_port); + if(!kvi_binaryIpToStringIp_V6(((struct sockaddr_in6 *)addr)->sin6_addr,m_szSecondaryIp)) + m_szSecondaryIp = __tr("unknown"); + } else { +#endif + m_uSecondaryPort = ntohs(((struct sockaddr_in *)addr)->sin_port); + if(!kvi_binaryIpToStringIp(((struct sockaddr_in *)addr)->sin_addr,m_szSecondaryIp)) + m_szSecondaryIp = __tr("unknown"); +#ifdef COMPILE_IPV6_SUPPORT + } +#endif + KviKvsVariantList *params=0; + callFunction(this,"incomingConnectionEvent",params); + if(m_secondarySock != KVI_INVALID_SOCKET) + { + kvi_socket_close(m_secondarySock); + m_secondarySock = KVI_INVALID_SOCKET; + m_uSecondaryPort = 0; + m_szSecondaryIp=""; + } + + } // else..huh ?... wait for the next notifier call +} + +void KviKvsObject_socket::acceptConnection(kvi_socket_t s,kvi_u32_t uPort,const char * szIp) +{ + reset(); + m_sock = s; + m_uRemotePort = uPort; + m_szRemoteIp = szIp; +#ifdef COMPILE_IPV6_SUPPORT + KviSockaddr sareal(0,m_bIpV6,m_bUdp); +#else + KviSockaddr sareal(0,false,m_bUdp); +#endif + + int size = (int)sareal.addressLength(); + + if(kvi_socket_getsockname(m_sock,sareal.socketAddress(),&size)) + { + m_uLocalPort = sareal.port(); + sareal.getStringAddress(m_szLocalIp); + } + + m_iStatus = KVI_SCRIPT_SOCKET_STATUS_CONNECTED; + + m_pSn = new QSocketNotifier((int)m_sock,QSocketNotifier::Read); + QObject::connect(m_pSn,SIGNAL(activated(int)),this,SLOT(readNotifierFired(int))); + m_pSn->setEnabled(true); +} + +void KviKvsObject_socket::delayedConnect() +{ + if(m_pDelayTimer)delete m_pDelayTimer; + m_pDelayTimer = new QTimer(); + connect(m_pDelayTimer,SIGNAL(timeout()),this,SLOT(doConnect())); + m_pDelayTimer->start(0,true); +} + +void KviKvsObject_socket::doConnect() +{ + debug ("doConnect function"); + if(m_pDelayTimer)delete m_pDelayTimer; + m_pDelayTimer = 0; + + + KviSockaddr sa(m_szRemoteIp,m_uRemotePort,!kvi_isValidStringIp(m_szRemoteIp),m_bUdp); + + if(!sa.socketAddress()) + { + unsigned int uOldConnectionId = m_uConnectionId; + QString ipAddressError=__tr2qs("Invalid ip address "); + + ipAddressError.append(m_szRemoteIp); + + KviKvsVariantList params; + QString tmp; + KviQString::sprintf(tmp,__tr2qs("Invalid ip address (%Q)"),&m_szRemoteIp); + params.append(new KviKvsVariant(tmp)); + callFunction(this,"connectFailedEvent",¶ms); + /* callEventFunction("connectFailedEvent",0,new KviParameterList( + new KviStr(KviStr::Format,__tr("Invalid ip address (%s)"),m_szRemoteIp.ptr()))); + */ if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! + return; + } +debug ("Socket created"); + + // create the socket +#ifdef COMPILE_IPV6_SUPPORT + m_bIpV6 = sa.isIpV6(); + m_sock = kvi_socket_create(sa.isIpV6() ? KVI_SOCKET_PF_INET6 : KVI_SOCKET_PF_INET,m_bUdp ? KVI_SOCKET_TYPE_DGRAM : KVI_SOCKET_TYPE_STREAM,KVI_SOCKET_PROTO_TCP); +#else + m_bIpV6 = false; + m_sock = kvi_socket_create(KVI_SOCKET_PF_INET,m_bUdp ? KVI_SOCKET_TYPE_DGRAM : KVI_SOCKET_TYPE_STREAM,KVI_SOCKET_PROTO_TCP); +#endif + + if(m_sock == KVI_INVALID_SOCKET) + { + unsigned int uOldConnectionId = m_uConnectionId; + callFunction(this,"connectFailedEvent",new KviKvsVariantList( + new KviKvsVariant(__tr2qs("Failed to create the socket")))); + if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! + return; + } + debug ("Valid socket"); + + if(!kvi_socket_setNonBlocking(m_sock)) + { + unsigned int uOldConnectionId = m_uConnectionId; + + callFunction(this,"connectFailedEvent",new KviKvsVariantList( + new KviKvsVariant(__tr2qs("Failed to setup a nonblocking socket")))); + if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! + return; + } + + if(!kvi_socket_connect(m_sock,sa.socketAddress(),((int)(sa.addressLength())))) + { + int err = kvi_socket_error(); + if(!kvi_socket_recoverableConnectError(err)) + { + // Ops... + int sockError=err; + if(sockError==0) + { + // Zero error ?...let's look closer + int iSize=sizeof(int); + if(!kvi_socket_getsockopt(m_sock,SOL_SOCKET,SO_ERROR, + (void *)&sockError,&iSize))sockError=0; + } + unsigned int uOldConnectionId = m_uConnectionId; + QString callBackError=__tr2qs("Connect failure: "); + + callBackError.append((KviError::getDescription(KviError::translateSystemError(sockError)).utf8().data())); + callFunction(this,"connectFailedEvent",new KviKvsVariantList( + new KviKvsVariant(callBackError))); + +/* callEventFunction("connectFailedEvent",0,new KviParameterList( + new KviStr(KviStr::Format,__tr("Connect failure: %s"),KviError::getDescription(KviError::translateSystemError(sockError)).utf8().data()))); +*/ if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! + return; + } + } + debug ("Socket connected"); + m_pDelayTimer = new QTimer(); + connect(m_pDelayTimer,SIGNAL(timeout()),this,SLOT(connectTimeout())); + m_pDelayTimer->start(m_uConnectTimeout,true); + + m_pSn = new QSocketNotifier((int)m_sock,QSocketNotifier::Write); + QObject::connect(m_pSn,SIGNAL(activated(int)),this,SLOT(writeNotifierFired(int))); + m_pSn->setEnabled(true); +} + +void KviKvsObject_socket::connectTimeout() +{ + unsigned int uOldConnectionId = m_uConnectionId; + + callFunction(this,"connectFailedEvent",new KviKvsVariantList( + new KviKvsVariant(__tr2qs("Connect attempt timed out")))); + if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! +} + +void KviKvsObject_socket::delayedLookupRemoteIp() +{ + if(m_pDelayTimer)delete m_pDelayTimer; + m_pDelayTimer = new QTimer(); + connect(m_pDelayTimer,SIGNAL(timeout()),this,SLOT(lookupRemoteIp())); + m_pDelayTimer->start(0,true); +} + +void KviKvsObject_socket::lookupRemoteIp() +{ + debug ("Resolve dns"); + if(m_pDelayTimer)delete m_pDelayTimer; + m_pDelayTimer = 0; + if(m_pDns)delete m_pDns; + m_pDns = new KviDns(); + connect(m_pDns,SIGNAL(lookupDone(KviDns *)),this,SLOT(lookupDone(KviDns *))); + if(!m_pDns->lookup(m_szRemoteIp,KviDns::Any)) + { + unsigned int uOldConnectionId = m_uConnectionId; + + callFunction(this,"connectFailedEvent",new KviKvsVariantList( + new KviKvsVariant(__tr2qs("Can't start the DNS thread")))); + if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! + } +} + +void KviKvsObject_socket::lookupDone(KviDns *pDns) +{ + + if(pDns->state() != KviDns::Success) + { + unsigned int uOldConnectionId = m_uConnectionId; + + callFunction(this,"connectFailedEvent",new KviKvsVariantList( + new KviKvsVariant(KviError::getDescription(pDns->error())))); + + if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! + return; + } + m_szRemoteIp = pDns->firstIpAddress(); + debug ("Dns resolved in %s",m_szRemoteIp.latin1()); + + delete m_pDns; + m_pDns = 0; + doConnect(); +} + +void KviKvsObject_socket::writeNotifierFired(int) +{ + debug ("Here in the writeNotifierFired"); + if(m_pSn) + { + delete m_pSn; + m_pSn = 0; + } + if(m_pDelayTimer) + { + delete m_pDelayTimer; + m_pDelayTimer = 0; + } + + // Check for errors... + int sockError; + int iSize=sizeof(int); + if(!kvi_socket_getsockopt(m_sock,SOL_SOCKET,SO_ERROR,(void *)&sockError,&iSize))sockError = -1; + //sockError = 0; + if(sockError != 0) + { + //debug("Failed here %d",sockError); + //failed + if(sockError > 0)sockError = KviError::translateSystemError(sockError); + else sockError = KviError_unknownError; //Error 0 ? + unsigned int uOldConnectionId = m_uConnectionId; + callFunction(this,"connectFailedEvent",new KviKvsVariantList( + new KviKvsVariant(KviError::getDescription(sockError)))); + if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! + } else { + // Succesfully connected + // create the correct read notifier now... + m_pSn = new QSocketNotifier((int)m_sock,QSocketNotifier::Read); + QObject::connect(m_pSn,SIGNAL(activated(int)),this,SLOT(readNotifierFired(int))); + m_pSn->setEnabled(true); + +#ifdef COMPILE_IPV6_SUPPORT + KviSockaddr sareal(0,m_bIpV6,m_bUdp); +#else + KviSockaddr sareal(0,false,m_bUdp); +#endif + int size = (int)sareal.addressLength(); + if(kvi_socket_getsockname(m_sock,sareal.socketAddress(),&size)) + { + m_uLocalPort = sareal.port(); + sareal.getStringAddress(m_szLocalIp); + } + unsigned int uOldConnectionId = m_uConnectionId; + KviKvsVariantList *params=0; + callFunction(this,"connectEvent",params); + if(m_uConnectionId == uOldConnectionId) + m_iStatus = KVI_SCRIPT_SOCKET_STATUS_CONNECTED; + // else the connection has been already changed! + } +} + +void KviKvsObject_socket::readNotifierFired(int) +{ + debug ("here in the readNotifierFired"); + //read data + if((m_uInBufferLen - m_uInDataLen) < KVI_READ_CHUNK) + { + m_uInBufferLen += KVI_IN_BUFFER_ALLOC_CHUNK; + m_pInBuffer = (char *)kvi_realloc(m_pInBuffer,m_uInBufferLen); + } + + int readLength = kvi_socket_recv(m_sock,m_pInBuffer + m_uInDataLen,KVI_READ_CHUNK); + + if(readLength <= 0) + { + if(readLength==0) + { + unsigned int uOldConnectionId = m_uConnectionId; + KviKvsVariantList *params=0; + callFunction(this,"disconnectEvent",params); + if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! + return; + } else { + //check for transmission errors + int err = kvi_socket_error(); +#ifdef COMPILE_ON_WINDOWS + if((err != EAGAIN) && (err != EINTR) && (err != WSAEWOULDBLOCK)) +#else + if((err != EAGAIN) && (err != EINTR)) +#endif + { + unsigned int uOldConnectionId = m_uConnectionId; + if(err > 0) + + { + // QString error=KviError::translateSystemError(err); + callFunction(this,"disconnectEvent",new KviKvsVariantList( + new KviKvsVariant((kvs_int_t)KviError::translateSystemError(err)))); + } else { + callFunction(this,"disconnectEvent",new KviKvsVariantList( + new KviKvsVariant(KviError::getDescription(KviError_remoteEndClosedConnection)))); + + } + if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! + return; + } //else transient error...wait again... + } + return; // can do nothing + } + // readLength > 0 + m_uInDataLen += readLength; + + //KviStr * s = new KviStr(); + QString s; + s.setNum(m_uInDataLen); + + + unsigned int uOldConnectionId = m_uConnectionId; + callFunction(this,"dataAvailableEvent",new KviKvsVariantList(new KviKvsVariant(s))); + if(m_uConnectionId == uOldConnectionId) + { + if(m_uInDataLen > (4096 * 1024)) // too much data in buffer (not reading) + { + callFunction(this,"disconnectEvent",new KviKvsVariantList( + new KviKvsVariant(__tr2qs("Too much unprocessed incoming data (you've left this socket unmanaged ?)")))); + reset(); + } + } +} + +void KviKvsObject_socket::eatInData(unsigned int uLen) +{ + if(uLen > m_uInDataLen)uLen = m_uInDataLen; + + m_uInDataLen -= uLen; + + if(m_uInDataLen > 0) + { + kvi_memmove(m_pInBuffer,m_pInBuffer + uLen,m_uInDataLen); + } + + unsigned int uSpace = m_uInBufferLen - m_uInDataLen; + + if(uSpace > KVI_IN_BUFFER_ALLOC_CHUNK) + { + m_uInBufferLen -= KVI_IN_BUFFER_ALLOC_CHUNK; + m_pInBuffer = (char *)kvi_realloc(m_pInBuffer,m_uInBufferLen); + } +} + +void KviKvsObject_socket::delayedFlush(unsigned int uTimeout) +{ + if(m_pFlushTimer->isActive())m_pFlushTimer->stop(); + m_pFlushTimer->start(uTimeout); +} + +void KviKvsObject_socket::tryFlush() +{ + if(m_pFlushTimer->isActive())m_pFlushTimer->stop(); + + if(m_pOutBuffer->size() == 0) + { + return; + } + + int result = kvi_socket_send(m_sock,m_pOutBuffer->data(),m_pOutBuffer->size()); + + if(result >= 0) + { + if(result == m_pOutBuffer->size()) + { + m_pOutBuffer->clear(); + } else { + if(result > 0)m_pOutBuffer->remove(result); + delayedFlush(500); + } + } else { + // Oops...error ? + int err = kvi_socket_error(); +#ifdef COMPILE_ON_WINDOWS + if((err == EAGAIN) || (err == EINTR) || (err = WSAEWOULDBLOCK)) +#else + if((err == EAGAIN)||(err == EINTR)) +#endif + { + // Transient error...partial send as before... + // Async continue... + delayedFlush(500); + return; + } else { + // Disconnected... :( + unsigned int uOldConnectionId = m_uConnectionId; + callFunction(this,"disconnectEvent",0,new KviKvsVariantList( + new KviKvsVariant(KviError::getDescription(KviError::translateSystemError(err))))); + if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! + return; + } + } +} +void KviKvsObject_socket::reset() +{ + m_uConnectionId++; // this is the only place where this is incremented! + if(m_pDelayTimer) + { + delete m_pDelayTimer; + m_pDelayTimer = 0; + } + if(m_pDns) + { + delete m_pDns; + m_pDns = 0; + } + if(m_pSn) + { + delete m_pSn; + m_pSn = 0; + } + if(m_sock != KVI_INVALID_SOCKET) + { + kvi_socket_close(m_sock); + m_sock = KVI_INVALID_SOCKET; + } + if(m_pInBuffer) + { + kvi_free(m_pInBuffer); + m_pInBuffer = 0; + } + if(m_secondarySock) + { + kvi_socket_close(m_secondarySock); + m_secondarySock = KVI_INVALID_SOCKET; + } + m_uSecondaryPort = 0; + m_szSecondaryIp=""; + delete m_pOutBuffer; + if(m_pFlushTimer->isActive())m_pFlushTimer->stop(); + m_pOutBuffer = new KviDataBuffer(); + m_uInBufferLen = 0; + m_uInDataLen = 0; + m_iStatus = KVI_SCRIPT_SOCKET_STATUS_DISCONNECTED; + m_uRemotePort = 0; + m_szRemoteIp=""; + m_uLocalPort = 0; + m_szLocalIp=""; + m_bIpV6 = false; +} +unsigned int KviKvsObject_socket::readGetLength(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uLen; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("length",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,uLen) + KVSO_PARAMETERS_END(c) + if (uLen>m_uInDataLen || !uLen) return m_uInDataLen; + else return uLen; + } + +bool KviKvsObject_socket::functionRead(KviKvsObjectFunctionCall *c) +{ + unsigned int uLen = readGetLength(c); + + if(uLen > 0) + { + // convert NULLS to char 255 + for(unsigned int i = 0;i < uLen;i++) + { + if(!m_pInBuffer[i])m_pInBuffer[i] = (char)(255); + } + QString tmpBuffer = QString::fromUtf8(m_pInBuffer,uLen); + c->returnValue()->setString(tmpBuffer); + + eatInData(uLen); + } + return true; +} + +bool KviKvsObject_socket::functionReadHex(KviKvsObjectFunctionCall *c) +{ + //??? funzioner� + unsigned int uLen = readGetLength(c); + bool bOk; + if(uLen > 0) + { + QString szTmp; + szTmp =m_pInBuffer; + szTmp.toInt(&bOk,16); + c->returnValue()->setString(szTmp); + eatInData(uLen); + } + return true; +} + +bool KviKvsObject_socket::functionWrite(KviKvsObjectFunctionCall *c) +{ + QString szData; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("szData",KVS_PT_STRING,0,szData) + KVSO_PARAMETERS_END(c) + +KviQCString szData8 = szData.utf8(); + if(szData8.length() > 0) + { + m_pOutBuffer->append((const unsigned char*)szData8.data(),szData8.length()); + delayedFlush(0); + } + return true; +} + + + +//-------------- + +#include "m_class_socket.moc" diff --git a/src/modules/objects/class_socket.h b/src/modules/objects/class_socket.h new file mode 100644 index 00000000..7ed2e421 --- /dev/null +++ b/src/modules/objects/class_socket.h @@ -0,0 +1,185 @@ +#ifndef _CLASS_SOCKET_H_ +#define _CLASS_SOCKET_H_ +// +// File : class_socket.h +// Creation date : Sun Nov 11 03:13:46 2001 GMT by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2001 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 "kvi_socket.h" + + + +#include "kvi_pointerlist.h" +#include +#include + +#define KVI_SCRIPT_SOCKET_STATUS_DISCONNECTED 0 +#define KVI_SCRIPT_SOCKET_STATUS_DNS 1 +#define KVI_SCRIPT_SOCKET_STATUS_CONNECTING 2 +#define KVI_SCRIPT_SOCKET_STATUS_LISTENING 3 +#define KVI_SCRIPT_SOCKET_STATUS_CONNECTED 4 + +class KviDns; +class KviDataBuffer; +/* +class KviScriptSocketObject : public KviScriptObject +{ + Q_OBJECT +public: + KviScriptSocketObject(KviScriptObjectClass * cla,KviScriptObject * par,const char * nam); + virtual ~KviScriptSocketObject(); +protected: + kvi_socket_t m_sock; + int m_iStatus; + KviStr m_szRemoteIp; + unsigned short int m_uRemotePort; + KviStr m_szLocalIp; + unsigned short int m_uLocalPort; + unsigned int m_uConnectTimeout; + QSocketNotifier * m_pSn; + KviDns * m_pDns; + QTimer * m_pDelayTimer; + char * m_pInBuffer; + unsigned int m_uInBufferLen; + unsigned int m_uInDataLen; + bool m_bIpV6; + unsigned int m_uConnectionId; + + KviDataBuffer * m_pOutBuffer; + QTimer * m_pFlushTimer; + + kvi_socket_t m_secondarySock; + unsigned short int m_uSecondaryPort; + KviStr m_szSecondaryIp; +protected: + bool functionStatus(KviCommand *c,KviParameterList * params,KviStr &buffer); + bool functionRemotePort(KviCommand *c,KviParameterList * params,KviStr &buffer); + bool functionRemoteIp(KviCommand *c,KviParameterList * params,KviStr &buffer); + bool functionLocalPort(KviCommand *c,KviParameterList * params,KviStr &buffer); + bool functionLocalIp(KviCommand *c,KviParameterList * params,KviStr &buffer); + bool functionConnect(KviCommand *c,KviParameterList * params,KviStr &buffer); + bool functionSetConnectTimeout(KviCommand *c,KviParameterList * params,KviStr &buffer); + bool functionConnectTimeout(KviCommand *c,KviParameterList * params,KviStr &buffer); + bool functionClose(KviCommand *c,KviParameterList * params,KviStr &buffer); + bool functionRead(KviCommand *c,KviParameterList * params,KviStr &buffer); + bool functionReadHex(KviCommand *c,KviParameterList * params,KviStr &buffer); + bool functionWrite(KviCommand *c,KviParameterList * params,KviStr &buffer); + bool functionWriteHex(KviCommand *c,KviParameterList * params,KviStr &buffer); + bool functionListen(KviCommand *c,KviParameterList * params,KviStr &buffer); + bool functionAccept(KviCommand *c,KviParameterList * params,KviStr &buffer); + + void delayedConnect(); + void delayedLookupRemoteIp(); + void delayedFlush(unsigned int uTimeout); + + void eatInData(unsigned int uLen); + unsigned int readGetLength(KviParameterList * params); + + void acceptConnection(kvi_socket_t s,unsigned short int uPort,const char * szIp); + + void reset(); +protected slots: + void doConnect(); + void lookupRemoteIp(); + void lookupDone(KviDns * pDns); + void connectTimeout(); + void writeNotifierFired(int); + void readNotifierFired(int); + void tryFlush(); + void incomingConnection(int); +public: + static void registerSelf(); + static void unregisterSelf(); +}; +*/ +//=============================================================== +#include "object_macros.h" + + +class KviKvsObject_socket : public KviKvsObject +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_socket) +protected: + bool m_bUdp; + kvi_socket_t m_sock; + int m_iStatus; + QString m_szRemoteIp; +// unsigned short int m_uRemotePort; + QString m_szLocalIp; + kvi_u32_t m_uLocalPort; + unsigned int m_uConnectTimeout; + QSocketNotifier * m_pSn; + KviDns * m_pDns; + QTimer * m_pDelayTimer; + char * m_pInBuffer; + unsigned int m_uInBufferLen; + unsigned int m_uInDataLen; + bool m_bIpV6; + unsigned int m_uConnectionId; + kvs_uint_t m_uRemotePort; + KviDataBuffer * m_pOutBuffer; + QTimer * m_pFlushTimer; + + kvi_socket_t m_secondarySock; + kvi_u32_t m_uSecondaryPort; + QString m_szSecondaryIp; +protected: + bool functionStatus(KviKvsObjectFunctionCall *c); + bool functionRemotePort(KviKvsObjectFunctionCall *c); + bool functionRemoteIp(KviKvsObjectFunctionCall *c); + bool functionLocalPort(KviKvsObjectFunctionCall *c); + bool functionLocalIp(KviKvsObjectFunctionCall *c); + bool functionConnect(KviKvsObjectFunctionCall *c); + bool functionSetConnectTimeout(KviKvsObjectFunctionCall *c); + bool functionConnectTimeout(KviKvsObjectFunctionCall *c); + + bool functionClose(KviKvsObjectFunctionCall *c); + bool functionRead(KviKvsObjectFunctionCall *c); + bool functionReadHex(KviKvsObjectFunctionCall *c); + bool functionWrite(KviKvsObjectFunctionCall *c); + bool functionWriteHex(KviKvsObjectFunctionCall *c); + + bool functionSetProtocol(KviKvsObjectFunctionCall *c); + + bool functionListen(KviKvsObjectFunctionCall *c); + bool functionAccept(KviKvsObjectFunctionCall *c); + + void delayedConnect(); + void delayedLookupRemoteIp(); + void delayedFlush(unsigned int uTimeout); + + void eatInData(unsigned int uLen); + unsigned int readGetLength(KviKvsObjectFunctionCall * params); + + void acceptConnection(kvi_socket_t s,kvi_u32_t uPort,const char * szIp); + + void reset(); +protected slots: + void doConnect(); + void lookupRemoteIp(); + void lookupDone(KviDns * pDns); + void connectTimeout(); + void writeNotifierFired(int); + void readNotifierFired(int); + void tryFlush(); + void incomingConnection(int); +}; +#endif //_CLASS_SOCKET_H_ diff --git a/src/modules/objects/class_spinbox.cpp b/src/modules/objects/class_spinbox.cpp new file mode 100644 index 00000000..f87a3a51 --- /dev/null +++ b/src/modules/objects/class_spinbox.cpp @@ -0,0 +1,265 @@ +// +// File : class_progressbar.cpp +// Creation date : Fri Jan 30 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 +#include "class_spinbox.h" +#include "kvi_error.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_iconmanager.h" + +/* + @doc: spinbox + @keyterms: + spinbox object class, + @title: + spinbox class + @type: + class + @short: + Provides a simple spin button. + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + This widget allows the user to choose a value either by clicking the up/down buttons + to increase/decrease the value currently displayed or by typing the value directly into the spin box. + @functions: + !fn: $setValue() + Sets the value of the spin box.[br] + See also [classfnc]$value[/classfnc]() + !fn: $setMinValue() + Sets the minimum value of the spin box. + See also [classfnc]$MinValue[/classfnc]() + !fn: $setMaxValue() + Sets the maximum value of the spin box.[br] + See also [classfnc]$maxValue[/classfnc]() + !fn: $setLineStep() + Sets the line step: when the user uses the arrows to change the spin box's value the value will be + incremented/decremented by the amount of the line step. + See also [classfnc]$lineStep[/classfnc]() + !fn: $setSpecialValueText() + Sets the special-value text. + If set, the spin box will display this text instead of a numeric value whenever the current value is equal to [classfnc]$minValue[/classfnc](). + See also [classfnc]$setSpecialValueText[/classfnc]() + !fn: $setPrefix() + This property holds the spin box's prefix.[br] + The prefix is prepended to the start of the displayed value.[br] + Typical use is to display a unit of measurement or a currency symbol. + See also [classfnc]$setSuffix[/classfnc]() + !fn: $setSuffix(); + This property holds the suffix of the spin box.[br] + The suffix is appended to the end of the displayed value.[br] + See also [classfnc]$setPrefix[/classfnc]() + !fn: $value() + Returns the value of the spin box. + See also [classfnc]$setValue[/classfnc]() + !fn: $minValue + Returns the minimum value of the spin box. + See also [classfnc]$setMinValue[/classfnc]() + !fn: $maxValue + Returns the maximum value of the spin box. + See also [classfnc]$setMaxValue[/classfnc]() + !fn: $lineStep() + Return the linestep. + !fn: $specialValueText() + Returns the special-value text. + See also [classfnc]$setSpecialValueText[/classfnc]() + !fn: $valueChangedEvent() + This function is called by the framework when the spinbox value is changed and return the new slider value as its argument.[br] + The default implementation emits the [classfnc]$valueChanged[/classfnc]() signal, + so it is easy to handle the values from many spinboxes without reimplementing + the [classfnc]$valueChangedEvent[/classfnc]() for every one.[br] + Note: If you reimplement this function to catch the spinbox value, you will have to emit the signal by yourself (if you still need it, obviously). + @signals: + !sg: $valueChanged() + This signal is emitted by the default implementation of [classfnc]valueChangedEvent[/classfnc]().[br] + If you reimplement that function you will have to emit the signal manually (if you still need it). +*/ + + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_spinbox,"spinbox","widget") + + + + KVSO_REGISTER_HANDLER(KviKvsObject_spinbox,"setValue", functionsetValue); + KVSO_REGISTER_HANDLER(KviKvsObject_spinbox,"setMinValue", functionsetMinValue); + KVSO_REGISTER_HANDLER(KviKvsObject_spinbox,"setMaxValue", functionsetMaxValue); + KVSO_REGISTER_HANDLER(KviKvsObject_spinbox,"setLineStep", functionsetLineStep); + KVSO_REGISTER_HANDLER(KviKvsObject_spinbox,"setSpecialValueText", functionsetSpecialValueText); + KVSO_REGISTER_HANDLER(KviKvsObject_spinbox,"value",functionvalue); + KVSO_REGISTER_HANDLER(KviKvsObject_spinbox,"minValue", functionminValue); + KVSO_REGISTER_HANDLER(KviKvsObject_spinbox,"maxValue", functionmaxValue); + KVSO_REGISTER_HANDLER(KviKvsObject_spinbox,"lineStep", functionlineStep); + KVSO_REGISTER_HANDLER(KviKvsObject_spinbox,"specialValueText", functionspecialValueText); + + KVSO_REGISTER_HANDLER(KviKvsObject_spinbox,"setPrefix", functionsetPrefix); + KVSO_REGISTER_HANDLER(KviKvsObject_spinbox,"setSuffix", functionsetSuffix); + + + KVSO_REGISTER_HANDLER(KviKvsObject_spinbox,"valueChangedEvent", functionvalueChangedEvent); +KVSO_END_REGISTERCLASS(KviKvsObject_spinbox) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_spinbox,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_spinbox) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_spinbox) + +KVSO_END_CONSTRUCTOR(KviKvsObject_spinbox) + +bool KviKvsObject_spinbox::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + setObject(new QSpinBox(parentScriptWidget(), name()), true); + connect(widget(),SIGNAL(valueChanged(int)),this,SLOT(valueChanged(int))); + return true; +} + + + +bool KviKvsObject_spinbox::functionsetValue(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iValue; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("value",KVS_PT_INT,0,iValue) + KVSO_PARAMETERS_END(c) + if (widget()) ((QSpinBox *)widget())->setValue(iValue); + return true; +} +bool KviKvsObject_spinbox::functionsetMinValue(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iMinvalue; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("min_value",KVS_PT_INT,0,iMinvalue) + KVSO_PARAMETERS_END(c) + if (widget()) ((QSpinBox *)widget())->setMinValue(iMinvalue); + return true; +} +bool KviKvsObject_spinbox::functionsetMaxValue(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iMaxvalue; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("max_value",KVS_PT_INT,0,iMaxvalue) + KVSO_PARAMETERS_END(c) + if (widget()) ((QSpinBox *)widget())->setMaxValue(iMaxvalue); + return true; +} + +bool KviKvsObject_spinbox::functionsetLineStep(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iLinestep; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("line_step",KVS_PT_INT,0,iLinestep) + KVSO_PARAMETERS_END(c) + if (widget()) ((QSpinBox *)widget())->setLineStep(iLinestep); + return true; +} + + +bool KviKvsObject_spinbox::functionvalue(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setInteger(((QSpinBox *)widget())->value()); + return true; +} + +bool KviKvsObject_spinbox::functionminValue(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setInteger(((QSpinBox *)widget())->minValue()); + return true; +} +bool KviKvsObject_spinbox::functionmaxValue(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setInteger(((QSpinBox *)widget())->maxValue()); + return true; +} +bool KviKvsObject_spinbox::functionlineStep(KviKvsObjectFunctionCall *c) +{ + if (widget()) + { + #ifdef COMPILE_USE_QT4 + c->returnValue()->setInteger(((QSpinBox *)widget())->singleStep()); + #else + c->returnValue()->setInteger(((QSpinBox *)widget())->lineStep()); + #endif + } + + return true; +} + + +bool KviKvsObject_spinbox::functionspecialValueText(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setString(((QSpinBox *)widget())->specialValueText()); + return true; +} + + +bool KviKvsObject_spinbox::functionsetSpecialValueText(KviKvsObjectFunctionCall *c) +{ + + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QSpinBox *)widget())->setSpecialValueText(szText); + return true; +} +bool KviKvsObject_spinbox::functionsetPrefix(KviKvsObjectFunctionCall *c) +{ + + QString szPrefix; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szPrefix) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QSpinBox *)widget())->setPrefix(szPrefix); + return true; +} +bool KviKvsObject_spinbox::functionsetSuffix(KviKvsObjectFunctionCall *c) +{ + + QString szSuffix; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szSuffix) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QSpinBox *)widget())->setSuffix(szSuffix); + return true; +} + +bool KviKvsObject_spinbox::functionvalueChangedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("valueChanged",c,c->params()); + return true; +} + +void KviKvsObject_spinbox::valueChanged(int value) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)value)); + callFunction(this,"valueChangedEvent",¶ms); +} + +#include "m_class_spinbox.moc" diff --git a/src/modules/objects/class_spinbox.h b/src/modules/objects/class_spinbox.h new file mode 100644 index 00000000..d5a6ee94 --- /dev/null +++ b/src/modules/objects/class_spinbox.h @@ -0,0 +1,64 @@ +#ifndef _CLASS_SPINBOX_H_ +#define _CLASS_SPINBOX_H_ +// +// File : class_progressbar.h +// Creation date : Fri Jan 30 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 +#include "class_widget.h" + +#include "object_macros.h" + +class KviKvsObject_spinbox : public KviKvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_spinbox) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool functionsetTracking(KviKvsObjectFunctionCall *c); + + bool functionsetValue(KviKvsObjectFunctionCall *c); + bool functionsetMinValue(KviKvsObjectFunctionCall *c); + bool functionsetMaxValue(KviKvsObjectFunctionCall *c); + bool functionsetLineStep(KviKvsObjectFunctionCall *c); + bool functionsetPrefix(KviKvsObjectFunctionCall *c); + bool functionsetSuffix(KviKvsObjectFunctionCall *c); + bool functionvalue(KviKvsObjectFunctionCall *c); + bool functionminValue(KviKvsObjectFunctionCall *c); + bool functionmaxValue(KviKvsObjectFunctionCall *c); + bool functionlineStep(KviKvsObjectFunctionCall *c); + bool functionsetSpecialValueText(KviKvsObjectFunctionCall *c); + bool functionspecialValueText(KviKvsObjectFunctionCall *c); + + bool functionvalueChangedEvent(KviKvsObjectFunctionCall *c); + +protected slots: + void valueChanged(int); +}; + +#endif //!_CLASS_SPINBOX_H_ diff --git a/src/modules/objects/class_tabwidget.cpp b/src/modules/objects/class_tabwidget.cpp new file mode 100644 index 00000000..c5e97b60 --- /dev/null +++ b/src/modules/objects/class_tabwidget.cpp @@ -0,0 +1,541 @@ +//mdm: +// File : class_tabwidget.cpp +// Creation date : Fri Feb 11 10:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 "class_tabwidget.h" +#include "kvi_error.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_iconmanager.h" + +/* + @doc: tabwidget + @keyterms: + tabwidget object class, + @title: + tabwidget class + @type: + class + @short: + Provides a Tab Widget. + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + The tabwidget class provides a stack of tabbed widgets.[br] + Each tab is associated with a different widget (called a `page').[br] + Only the current tab's page is shown in the page area; all the others tabs pages are hidden.[br] + The user can show a different page by clicking on its tab.[br] + @functions: + !fn: $addTab(,,[]) + Adds another page to the tab view with the text label and optional icon. + !fn: $insertTab(,,) + Inserts another tab and page to the tab view with name and label-text specified.[br] + If index is not specified, the tab is simply appended.[br] + Otherwise the new tab is inserted at the specified position. + !fn: $setTabToolTip(,) + Sets the tab tool tip for the tabwidget to . + !fn: $removeTabToolTip() + Removes the tab tool tip for the tab. If the page does not have a tip, nothing happens. + !fn: $setTabLabel(, ) + Sets the tab label for to label. + !fn: $changeTab(,,[]) + Defines a new label, and optional icon, for the tab . + !fn: $setCurrentPage() + Sets the index position of the current tab page to . + !fn: $currentPageIndex() + Returns the current page index. + !fn: $label() + Retunrs the label to the . + !fn: $currentTabLabel() + Returns the label of the current tab. + !fn: $setMargin() + Sets the margin in this tab widget to . + !fn: $margin() + Returns the margin in this tab widget. + !fn: $removePage() + Remove the page . + !fn: $setTabPosition() + Sets TabPosition. Valid parameters are : Top, Bottom. + !fn: $count() + This property holds the number of tabs in the tab bar. + !fn: $currentChangedEvent() + This function is invoched when the current tab was changed.[br] + The default implementation emits the [classfnc]$currentChange[/classfnc]() signal. + @examples: + [example] + # First we'll create the main tabwidget. + %Tabwidget=$new(tabwidget) + %Tabwidget->$setToolTip("Example of TabWidget class") + %Tabwidget->$setMargin(30) + %Tabwidget->$setTabPosition(Top) + + # Now we'll create the new widgets and put they in to the main tabwidget. + %firsttab=$new(widget,%Tabwidget) + %secondtab=$new(widget,%Tabwidget) + + # Now we'll create the item to put in to tab's pages. + %layoutfirsttab=$new(layout,%firsttab) + %labelbt=$new(label,%firsttab) + %labelbt->$settext(Botton Tab) + %labeltt=$new(label,%firsttab) + %labeltt->$settext(Top Tab) + %buttontb=$new(button,%firsttab) + %buttontb->$settext("To &Botton") + %buttontt=$new(button,%firsttab) + %buttontt->$settext("To &Top") + + # Now we'll give a layout to all items. + # This also allows to use privateimpl without making buttons global variables + %layoutfirsttab->$addwidget(%labelbt,0,0) + %layoutfirsttab->$addwidget(%labeltt,0,1) + %layoutfirsttab->$addwidget(%buttontb,1,0) + %layoutfirsttab->$addwidget(%buttontt,1,1) + + # Add the page to the main tab. + %Tabwidget->$addTab(%firsttab,Top&Button,33) + + # Implementing the action to do when the user click the buttons. + privateimpl(%buttontb,mousepressevent) + { + %Tabwidget->$setTabPosition(Bottom) + } + privateimpl(%buttontt,mousepressevent) + { + %Tabwidget->$setTabPosition(Top) + } + + # We do the same work with the second tab's page. + %layoutsecondtab=$new(layout,%secondtab) + %labelwp=$new(label,%secondtab) + %labelwp->$settext("Enjoy the new Class provided by") + %layoutsecondtab->$addwidget(%labelwp,0,0) + %labelwp->$setalignment("Center") + %labelgen=$new(label,%secondtab) + %labelgen->$settext(Grifisx \& Noldor) + %labelgen->$setalignment("Center") + %layoutsecondtab->$addwidget(%labelgen,1,0) + %Tabwidget->$addTab(%secondtab,&About,50) + + # Let's show our example. + %Tabwidget->$show() + [/example] + @signals: + !sg: $currentChange() + This signal is emitted by the default implementation of [classfnc]$currentChangedEvent[/classfnc]().[br] + If you reimplement that function you will have to emit the signal manually (if you still need it).[br] +*/ + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_tabwidget,"tabwidget","widget") + + KVSO_REGISTER_HANDLER(KviKvsObject_tabwidget,"addTab", functionaddTab) + KVSO_REGISTER_HANDLER(KviKvsObject_tabwidget,"insertTab", functioninsertTab) + KVSO_REGISTER_HANDLER(KviKvsObject_tabwidget,"setTabToolTip", functionsetTabToolTip) + KVSO_REGISTER_HANDLER(KviKvsObject_tabwidget,"removeTabToolTip", functionremoveTabToolTip) + KVSO_REGISTER_HANDLER(KviKvsObject_tabwidget,"setTabLabel", functionsetTabLabel) + KVSO_REGISTER_HANDLER(KviKvsObject_tabwidget,"changeTab", functionchangeTab) + KVSO_REGISTER_HANDLER(KviKvsObject_tabwidget,"setCurrentPage", functionsetCurrentPage) + KVSO_REGISTER_HANDLER(KviKvsObject_tabwidget,"currentPageIndex", functioncurrentPageIndex) + KVSO_REGISTER_HANDLER(KviKvsObject_tabwidget,"label", functiontabLabel) + KVSO_REGISTER_HANDLER(KviKvsObject_tabwidget,"currentTabLabel", functioncurrentTabLabel) + + KVSO_REGISTER_HANDLER(KviKvsObject_tabwidget,"setMargin", functionsetMargin); + KVSO_REGISTER_HANDLER(KviKvsObject_tabwidget,"margin", functionmargin) + KVSO_REGISTER_HANDLER(KviKvsObject_tabwidget,"count", functioncount) + KVSO_REGISTER_HANDLER(KviKvsObject_tabwidget,"removePage", functionremovePage) + KVSO_REGISTER_HANDLER(KviKvsObject_tabwidget,"setTabPosition", functionsetTabPosition) + + // events + KVSO_REGISTER_HANDLER(KviKvsObject_tabwidget,"currentChangedEvent", functionCurrentChangedEvent) + + + +KVSO_END_REGISTERCLASS(KviKvsObject_tabwidget) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_tabwidget,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_tabwidget) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_tabwidget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_tabwidget) + +bool KviKvsObject_tabwidget::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + setObject(new QTabWidget(parentScriptWidget(), name()), true); + connect(widget(),SIGNAL(currentChanged(int)),this,SLOT(slotcurrentChanged(int))); + return true; +} +bool KviKvsObject_tabwidget::functionaddTab(KviKvsObjectFunctionCall *c) +{ + KviKvsObject *ob; + QString szLabel,szIcon; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("label",KVS_PT_STRING,0,szLabel) + KVSO_PARAMETER("icon_id",KVS_PT_STRING,KVS_PF_OPTIONAL,szIcon) + KVSO_PARAMETERS_END(c) + ob=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if(!widget())return true; + if (!ob) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!ob->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!ob->object()->isWidgetType()) + { + c->warning(__tr2qs("Can't add a non-widget object")); + return true; + } + QPixmap * pix = g_pIconManager->getImage(szIcon); + + if(pix){ +#ifdef COMPILE_USE_QT4 + ((QTabWidget *)widget())->addTab(((QWidget *)(ob->object())),QIconSet(*pix),szLabel); +#else + ((QTabWidget *)widget())->addTab(((QWidget *)(ob->object())),QIconSet(*pix,QIconSet::Small),szLabel); +#endif + } + else((QTabWidget *)widget())->addTab(((QWidget *)(ob->object())),szLabel); + return true; +} + +bool KviKvsObject_tabwidget::functioninsertTab(KviKvsObjectFunctionCall *c) +{ + KviKvsObject *ob; + QString szLabel,szIcon; + kvs_uint_t uIndex; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("tab_widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("label",KVS_PT_STRING,0,szLabel) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETER("icon_id",KVS_PT_STRING,KVS_PF_OPTIONAL,szIcon) + KVSO_PARAMETERS_END(c) + ob=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if(!widget())return true; + if (!ob) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!ob->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!ob->object()->isWidgetType()) + { + c->warning(__tr2qs("Can't add a non-widget object")); + return true; + } + QPixmap * pix = g_pIconManager->getImage(szIcon); + if(pix){ + #ifdef COMPILE_USE_QT4 + ((QTabWidget *)widget())->insertTab( ((QWidget *)(ob->object())),QIconSet(*pix),szLabel,uIndex); + #else + ((QTabWidget *)widget())->insertTab(((QWidget *)(ob->object())),QIconSet(*pix,QIconSet::Small),szLabel,uIndex); + #endif + } + else ((QTabWidget *)widget())->insertTab(((QWidget *)(ob->object())),szLabel,uIndex); + return true; +} + +bool KviKvsObject_tabwidget::functionsetCurrentPage(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + if (widget()) ((QTabWidget *)widget())->setCurrentPage(uIndex); + return true; +} +bool KviKvsObject_tabwidget::functionsetTabToolTip(KviKvsObjectFunctionCall *c) +{ + KviKvsObject *ob; + QString szTooltip; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("tab_widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("tooltip",KVS_PT_STRING,0,szTooltip) + KVSO_PARAMETERS_END(c) + ob=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if(!widget())return true; + if (!ob) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!ob->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!ob->object()->isWidgetType()) + { + c->warning(__tr2qs("Not a widget object")); + return true; + } + int ctrl = ((QTabWidget *)widget())->indexOf (((QWidget *)(ob->object()))); + if (ctrl == -1) + { + c->warning(__tr2qs("Can't find the tab ")); + return true; + } + ((QTabWidget *)widget())->setTabToolTip(((QWidget *)(ob->object())),szTooltip); + return true; +} +bool KviKvsObject_tabwidget::functionremoveTabToolTip(KviKvsObjectFunctionCall *c) +{ + KviKvsObject *ob; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("tab_widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETERS_END(c) + ob=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!ob) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!ob->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!widget()) return true; + if(!ob->object()->isWidgetType()) + { + c->warning(__tr2qs("Not a widget object")); + return true; + } + if (((QTabWidget *)widget())->indexOf (((QWidget *)(ob->object()))) == -1) + { + c->warning(__tr2qs("Can't find the tab ")); + return true; + } + ((QTabWidget *)widget())->removeTabToolTip(((QWidget *)(ob->object()))); + return true; +} + +bool KviKvsObject_tabwidget::functionsetTabLabel(KviKvsObjectFunctionCall *c) +{ + KviKvsObject *ob; + QString szLabel; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("tab_widget",KVS_PT_HOBJECT,0, hObject) + KVSO_PARAMETER("tooltip",KVS_PT_STRING,0,szLabel) + KVSO_PARAMETERS_END(c) + ob=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!ob) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!ob->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!widget())return true; + if(!ob->object()->isWidgetType()) + { + c->warning(__tr2qs("Not a widget object")); + return true; + } + int ctrl = ((QTabWidget *)widget())->indexOf (((QWidget *)(ob->object()))); + if (ctrl == -1) + { + c->warning(__tr2qs("Can't find the tab ")); + return true; + } + ((QTabWidget *)widget())->setTabLabel(((QWidget *)(ob->object())),szLabel); + return true; +} +bool KviKvsObject_tabwidget::functioncurrentPageIndex(KviKvsObjectFunctionCall *c) +{ + int index=((QTabWidget *)widget())->currentPageIndex(); + if (widget()) c->returnValue()->setInteger(index); + return true; +} +bool KviKvsObject_tabwidget::functiontabLabel(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_INT,0,uIndex) + KVSO_PARAMETERS_END(c) + if (!widget()) return true; + QString label=((QTabWidget *)widget())->label(uIndex); + c->returnValue()->setString(label); + return true; +} +bool KviKvsObject_tabwidget::functionsetMargin(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iMargin; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("margin",KVS_PT_INT,0,iMargin) + KVSO_PARAMETERS_END(c) + if (widget()) ((QTabWidget *)widget())->setMargin(iMargin); + return true; +} +bool KviKvsObject_tabwidget::functionmargin(KviKvsObjectFunctionCall *c) +{ + + if (widget()) c->returnValue()->setInteger(((QTabWidget *)widget())->margin()); + return true; +} + +bool KviKvsObject_tabwidget::functioncount(KviKvsObjectFunctionCall *c) +{ + if (!widget()) return true; + int count = ((QTabWidget *)widget())->count(); + c->returnValue()->setInteger(count); + return true; +} + +bool KviKvsObject_tabwidget::functioncurrentTabLabel(KviKvsObjectFunctionCall *c) +{ + if (widget()) + { + int i= ((QTabWidget *)widget())->currentPageIndex(); + QString label=((QTabWidget *)widget())->label(i); + c->returnValue()->setString(label); + } + return true; +} +bool KviKvsObject_tabwidget::functionremovePage(KviKvsObjectFunctionCall *c) +{ + KviKvsObject *ob; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("tab_widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETERS_END(c) + ob=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if(!widget())return true; + if (!ob) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!ob->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!ob->object()->isWidgetType()) + { + c->warning(__tr2qs("Not a widget object")); + return true; + } + int ctrl = ((QTabWidget *)widget())->indexOf (((QWidget *)(ob->object()))); + if (ctrl == -1) + { + c->warning(__tr2qs("Can't find the tab ")); + return true; + } + ((QTabWidget *)widget())->removePage(((QWidget *)(ob->object()))); + return true; +} + +bool KviKvsObject_tabwidget::functionchangeTab(KviKvsObjectFunctionCall *c) +{ + KviKvsObject *ob; + QString szLabel,szIcon; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("tab_widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("label",KVS_PT_STRING,0,szLabel) + KVSO_PARAMETER("icon_id",KVS_PT_STRING,KVS_PF_OPTIONAL,szIcon) + KVSO_PARAMETERS_END(c) + ob=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!ob) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!ob->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!widget())return true; + if(!ob->object()->isWidgetType()) + { + c->warning(__tr2qs("Not a widget object")); + return true; + } + int ctrl = ((QTabWidget *)widget())->indexOf (((QWidget *)(ob->object()))); + if (ctrl == -1) + { + c->warning(__tr2qs("Can't find the tab ")); + return true; + } + QPixmap * pix = g_pIconManager->getImage(szIcon); + if(pix){ + #ifdef COMPILE_USE_QT4 + ((QTabWidget *)widget())->changeTab(((QWidget *)(ob->object())),QIconSet(*pix),szLabel); + #else + ((QTabWidget *)widget())->changeTab(((QWidget *)(ob->object())),QIconSet(*pix,QIconSet::Small),szLabel); + #endif + } + else ((QTabWidget *)widget())->changeTab(((QWidget *)(ob->object())),szLabel); + return true; +} +bool KviKvsObject_tabwidget::functionsetTabPosition(KviKvsObjectFunctionCall *c) +{ + QString szPos; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("tab_position",KVS_PT_STRING,0,szPos) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + if(KviQString::equalCI(szPos,"Top")) + ((QTabWidget *)widget())->setTabPosition(QTabWidget::Top); + else if(KviQString::equalCI(szPos,"Bottom")) + ((QTabWidget *)widget())->setTabPosition(QTabWidget::Bottom); + else c->warning( __tr2qs("Unknown position 'Q%'"),&szPos); + return true; +} + + + +bool KviKvsObject_tabwidget::functionCurrentChangedEvent(KviKvsObjectFunctionCall *c) +{ + + emitSignal("valueChanged",c,c->params()); + return true; +} + +void KviKvsObject_tabwidget::slotCurrentChanged(int value) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)value)); + callFunction(this,"currentChangedEvent",¶ms); +} + +#include "m_class_tabwidget.moc" diff --git a/src/modules/objects/class_tabwidget.h b/src/modules/objects/class_tabwidget.h new file mode 100644 index 00000000..acc76d36 --- /dev/null +++ b/src/modules/objects/class_tabwidget.h @@ -0,0 +1,61 @@ +#ifndef _CLASS_TABWIDGET_H_ +#define _CLASS_TABWIDGET_H_ +//mdm: +// File : class_tabwidget.h +// Creation date : Fri Feb 11 10:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 +#include "class_widget.h" + +#include "object_macros.h" + +class KviKvsObject_tabwidget : public KviKvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_tabwidget) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool functionaddTab(KviKvsObjectFunctionCall *c); + bool functioninsertTab(KviKvsObjectFunctionCall *c); + bool functionsetTabToolTip(KviKvsObjectFunctionCall *c); + bool functionremoveTabToolTip(KviKvsObjectFunctionCall *c); + bool functionsetTabLabel(KviKvsObjectFunctionCall *c); + bool functionsetCurrentPage(KviKvsObjectFunctionCall *c); + bool functioncurrentPageIndex(KviKvsObjectFunctionCall *c); + bool functiontabLabel(KviKvsObjectFunctionCall *c); + bool functioncurrentTabLabel(KviKvsObjectFunctionCall *c); + bool functionsetMargin(KviKvsObjectFunctionCall *c); + bool functionmargin(KviKvsObjectFunctionCall *c); + bool functioncount(KviKvsObjectFunctionCall *c); + bool functionchangeTab(KviKvsObjectFunctionCall *c); + bool functionCurrentChangedEvent(KviKvsObjectFunctionCall *c); + bool functionremovePage(KviKvsObjectFunctionCall *c); + bool functionsetTabPosition(KviKvsObjectFunctionCall *c); + +protected slots: + void slotCurrentChanged(int); +}; + +#endif //!_CLASS_TABWIDGET_H_ diff --git a/src/modules/objects/class_tbrowser.cpp b/src/modules/objects/class_tbrowser.cpp new file mode 100644 index 00000000..67dce8cb --- /dev/null +++ b/src/modules/objects/class_tbrowser.cpp @@ -0,0 +1,143 @@ +//mdm: +// File : class_tbrowser.cpp +// Creation date : Fri Jan 28 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 +#include "class_tbrowser.h" +#include "kvi_error.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_iconmanager.h" + +/* + @doc: textbrowser + @keyterms: + textbrowser browser widget class, + @title: + textbrowser class + @type: + class + @short: + Provides a class that can display html pages. + @inherits: + [class]widget[/class] + @description: + Provides a class that can display html pages with hypertext navigation. + @functions: + !fn: $setSource() + With this you can display the page at szFile location (szFile include the path). + !fn: $backward() + Changes the document displayed to the previous document in the list of documents built by navigating links. + !fn: $forward() + Changes the document displayed to the next document in the list of documents built by navigating links. + !fn: $home() + Changes the document displayed to be the first document the browser displayed. + !fn: $reload() + Reloads the current set source. + !fn: $linkClickedEvent() + Triggered when a link is clicked by the user. The default implementation of this function + emits the "linkClicked" signal. + @signals: + !sg: $linkClicked() + This signal is emitted by the default implementation of the [classfnc]$linkClickedEvent[/classfnc]() function. +*/ + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_textbrowser,"textbrowser","multilineedit") + KVSO_REGISTER_HANDLER(KviKvsObject_textbrowser,"setSource",function_setSource) + KVSO_REGISTER_HANDLER(KviKvsObject_textbrowser,"forward",function_forward) + KVSO_REGISTER_HANDLER(KviKvsObject_textbrowser,"backward",function_backward) + KVSO_REGISTER_HANDLER(KviKvsObject_textbrowser,"home",function_home) + KVSO_REGISTER_HANDLER(KviKvsObject_textbrowser,"reload",function_reload) + KVSO_REGISTER_HANDLER(KviKvsObject_textbrowser,"linkClickedEvent",function_linkClickedEvent) +KVSO_END_REGISTERCLASS(KviKvsObject_textbrowser) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_textbrowser,KviKvsObject_mledit) + +KVSO_END_CONSTRUCTOR(KviKvsObject_textbrowser) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_textbrowser) + +KVSO_END_CONSTRUCTOR(KviKvsObject_textbrowser) + +bool KviKvsObject_textbrowser::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + QTextBrowser * tb = new QTextBrowser(parentScriptWidget(), name()); + setObject(tb, true); + connect(tb,SIGNAL(anchorClicked(const QString &,const QString &)),this,SLOT(anchorClicked(const QString &,const QString &))); + return true; +} + +bool KviKvsObject_textbrowser::function_setSource(KviKvsObjectFunctionCall *c) +{ + QString szFile; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("file_name",KVS_PT_STRING,0,szFile) + KVSO_PARAMETERS_END(c) + if(!QFile::exists(szFile)) + { + c->warning(__tr2qs("I can't find the specified file '%Q'."),&szFile); + return true; + } + + if (widget()) ((QTextBrowser *)widget())->setSource(szFile); + return true; +} + +bool KviKvsObject_textbrowser::function_forward(KviKvsObjectFunctionCall *c) +{ + if (widget()) ((QTextBrowser *)widget())->forward(); + return true; +} + +bool KviKvsObject_textbrowser::function_backward(KviKvsObjectFunctionCall *c) +{ + if (widget()) ((QTextBrowser *)widget())->backward(); + return true; +} + +bool KviKvsObject_textbrowser::function_home(KviKvsObjectFunctionCall *c) +{ + if (widget()) ((QTextBrowser *)widget())->home(); + return true; +} + +bool KviKvsObject_textbrowser::function_reload(KviKvsObjectFunctionCall *c) +{ + if (widget()) ((QTextBrowser *)widget())->reload(); + return true; +} + +void KviKvsObject_textbrowser::anchorClicked(const QString &szName,const QString &szLink) +{ + KviKvsVariantList parms(new KviKvsVariant(szLink)); + callFunction(this,"linkClickedEvent",0,&parms); +} + +bool KviKvsObject_textbrowser::function_linkClickedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("linkClicked",c,c->params()); + return true; +} + +#include "m_class_tbrowser.moc" diff --git a/src/modules/objects/class_tbrowser.h b/src/modules/objects/class_tbrowser.h new file mode 100644 index 00000000..980bdc28 --- /dev/null +++ b/src/modules/objects/class_tbrowser.h @@ -0,0 +1,52 @@ +#ifndef _CLASS_TBROWSER_H_ +#define _CLASS_TBROWSER_H_ +//mdm: +// File : class_tbrowser.h +// Creation date : Fri Feb 28 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 +#include "class_widget.h" +#include +#include "class_multilineedit.h" +#include "object_macros.h" + +class KviKvsObject_textbrowser : public KviKvsObject_mledit +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_textbrowser) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool function_setSource(KviKvsObjectFunctionCall *c); + bool function_forward(KviKvsObjectFunctionCall *c); + bool function_backward(KviKvsObjectFunctionCall *c); + bool function_home(KviKvsObjectFunctionCall *c); + bool function_reload(KviKvsObjectFunctionCall *c); + bool function_linkClickedEvent(KviKvsObjectFunctionCall *c); +protected slots: + void anchorClicked(const QString &szName,const QString &szLink); +}; + +#endif //!_CLASS_TBROWSER_H_ diff --git a/src/modules/objects/class_toolbar.cpp b/src/modules/objects/class_toolbar.cpp new file mode 100644 index 00000000..ed280bd0 --- /dev/null +++ b/src/modules/objects/class_toolbar.cpp @@ -0,0 +1,156 @@ +//mdm: +// File : class_toolbar.cpp +// Creation date : Tue Feb 22 22:12:55 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 "class_toolbar.h" +#include "kvi_error.h" +#include "kvi_debug.h" +#include "kvi_tal_toolbar.h" +#include "kvi_tal_mainwindow.h" +#include "kvi_locale.h" +#include "kvi_iconmanager.h" +#include "class_mainwindow.h" + +/* + @doc: toolbar + @keyterms: + toolbar object class, + @title: + toolbar class + @type: + class + @short: + Provides a toolbar for mainwindow widget. + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + The toolbar class provides a movable panel containing widgets such as tool buttons. + @functions: + !fn: $addSeparator() + Adds a separator to the right/bottom of the toolbar. + !fn: $setLabel() + Sets the toolbar's label. + !fn: $label() + Returns the toolbar's label. + !fn: $setStretchableWidget() + Sets the to be expanded. + !fn: $clear() + Deletes all the toolbar's child widgets. + +*/ + + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_toolbar,"toolbar","object") + KVSO_REGISTER_HANDLER(KviKvsObject_toolbar,"addSeparator", functionaddSeparator) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbar,"setLabel", functionsetLabel) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbar,"label", functionlabel) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbar,"setStretchableWidget", functionsetStretchableWidget) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbar,"clear", functionclear) +KVSO_END_REGISTERCLASS(KviKvsObject_toolbar) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_toolbar,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_toolbar) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_toolbar) + +KVSO_END_CONSTRUCTOR(KviKvsObject_toolbar) + +bool KviKvsObject_toolbar::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + if (!parentObject()) + { + pContext->warning(__tr2qs("the toolbar cannot be a parent-widget!")); + return true; + } + if(parentObject()->inherits("KviKvsObject_mainwindow")) + { + setObject(new KviTalToolBar(name(), ((KviTalMainWindow *)parentScriptWidget())), true); + } + else + { + pContext->warning(__tr2qs("The parent-widget isn't a MainWindow.")); + } + + return true; +} + +bool KviKvsObject_toolbar::functionaddSeparator(KviKvsObjectFunctionCall *c) +{ + if(widget()) ((KviTalToolBar *)widget())->addSeparator(); + return true; +} +bool KviKvsObject_toolbar::functionsetLabel(KviKvsObjectFunctionCall *c) +{ + QString szLabel; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("label",KVS_PT_STRING,0,szLabel) + KVSO_PARAMETERS_END(c) + if (widget()) ((KviTalToolBar *)widget())->setLabel(szLabel); + return true; +} +bool KviKvsObject_toolbar::functionlabel(KviKvsObjectFunctionCall *c) +{ + if (widget()) c->returnValue()->setString(((KviTalToolBar *)widget())->label()); + return true; +} +bool KviKvsObject_toolbar::functionsetStretchableWidget(KviKvsObjectFunctionCall *c) +{ + KviKvsObject *ob; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETERS_END(c) + ob=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!widget()) return true; + if (!ob) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!ob->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!ob->object()->inherits("KviKvsObject_widget")) + { + c->warning(__tr2qs("Widget object required")); + return TRUE; + } +#ifndef COMPILE_USE_QT4 + // FIXME: no support for this in Qt4 ? + if(widget()) ((KviTalToolBar *)widget())->setStretchableWidget(((QWidget *)(ob->object()))); +#endif //!COMPILE_USE_QT4 + return true; +} +bool KviKvsObject_toolbar::functionclear(KviKvsObjectFunctionCall *c) +{ + if (widget()) + ((KviTalToolBar *)object())->clear(); + return true; +} + +#include "m_class_toolbar.moc" + diff --git a/src/modules/objects/class_toolbar.h b/src/modules/objects/class_toolbar.h new file mode 100644 index 00000000..1912e639 --- /dev/null +++ b/src/modules/objects/class_toolbar.h @@ -0,0 +1,50 @@ +#ifndef _CLASS_TOOLBAR_H_ +#define _CLASS_TOOLBAR_H_ +//mdm: +// File : class_toolbar.h +// Creation date : Tue Feb 22 22:12:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 "class_widget.h" +#include "object_macros.h" + +class KviKvsObject_toolbar : public KviKvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_toolbar) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool functionaddSeparator(KviKvsObjectFunctionCall *c); + bool functionsetLabel(KviKvsObjectFunctionCall *c); + bool functionlabel(KviKvsObjectFunctionCall *c); + bool functionsetStretchableWidget(KviKvsObjectFunctionCall *c); + bool functionclear(KviKvsObjectFunctionCall *c); +}; + + +#endif //!_CLASS_TOOLBAR_H_ diff --git a/src/modules/objects/class_toolbutton.cpp b/src/modules/objects/class_toolbutton.cpp new file mode 100644 index 00000000..032b0c60 --- /dev/null +++ b/src/modules/objects/class_toolbutton.cpp @@ -0,0 +1,341 @@ +//mdm: +// File : class_toolbutton.cpp +// Creation date : Wed Feb 23 16:39:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 "class_toolbutton.h" +#include "kvi_error.h" +#include "kvi_debug.h" + +#include "kvi_locale.h" +#include "kvi_iconmanager.h" +#include "kvi_tal_popupmenu.h" +/* + @doc: toolbutton + @keyterms: + toolbutton object class, + @title: + toolbutton class + @type: + class + @short: + Provides a toolbutton for toolbar widget. + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + The toolbutton class provides a quick-access button to commands or options, usually used inside a ToolBar. + @functions: + !fn:$setImage() + Sets the image for this button. + !fn:$setUsesBigPixmap() + Sets whether this toolbutton uses big pixmaps to enable. + !fn:$usesBigPixmap() + This property holds whether this toolbutton uses big pixmaps. + !fn:setUsesTextLabel() + Sets whether the toolbutton show a texlabel below the pixmap of the button. + !fn:$usesTextLabel() + Return 1 if the setUsesTextLabel is enabled, otherwise return 0. + !fn:$setTextLabel(,[tooltip:string]) + Sets the label of this button to and automatically sets it as a tool tip if is TRUE. + !fn: $textLabel() + Returns the label of tthe button. + !fn:$setAutoRaise() + Sets whether auto-raising is enabled. + !fn: $autoRaise() + Returns 1 if autoRaise is enabled, otherwise returns 0. + !fn:$setToggleButton() + Sets whether the tool button is a toggle button 1 enable, 0 disable. + !fn: $toggle() + Toggles the state of the tool button. + !fn:$setOn() + Sets whether the tool button is on to the bool value: 1 enable, 0 disable. + // findme + !fn:$setPopup () + !fn:$setPopupDelay () + Sets the time delay between pressing the button and the appearance of the associated popup menu in milliseconds to delay.[br] + A good value is 100. + !fn: $pupupDelay() + Returns the time delay between pressing the button and the appearance of the associated popup menu in milliseconds. + !fn:$openPopup() + Opens the associated popup menu. If there is no such menu, this function does nothing. + !fn:setTextPosition() + Sets the position of the tool button's textLabel in relation to the tool button's icon.[br] + Valid texpos values are:[br] + - BesideIcon : The text appears beside the icon.[br] + - BelowIcon : The text appears below the icon. + !fn: $textPosition() + Returns the position of the text label of this button. + !fn: $clickEvent() + This function is called when the toolbutton is clicked.[br] + You can reimplement it to handle the user click events.[br] + The default implementation emits the [classfnc]$clicked[/classfnc]() signal. + @signals: + !sg: $clicked() + This signal is emitted by the default implementation of [classfnc]$clickEvent[/classfnc]().[br] +*/ + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_toolbutton,"toolbutton","widget") + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"setImage", functionsetImage) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"setUsesBigPixmap", functionsetUsesBigPixmap) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"usesBigPixmap", functionusesBigPixmap) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"setUsesTextLabel", functionsetUsesTextLabel) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"usesTextLabel", functionusesTextLabel) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"setAutoRaise", function_setAutoRaise) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"autoRaise", function_autoRaise) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"setTextLabel", functionsetTextLabel) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"textLabel", functiontextLabel) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"setPopup", functionsetPopup) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"openPopup", functionopenPopup) + + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"setToggleButton", functionsetToggleButton) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"toggle", functiontoggle) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"setOn", functionsetOn) + + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"setPopupDelay", functionsetPopupDelay) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"popupDelay", functionpopupDelay) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"setTextPosition", functionsetTextPosition) + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"textPosition", functiontextPosition) + + KVSO_REGISTER_HANDLER(KviKvsObject_toolbutton,"clickEvent",function_clickEvent) +KVSO_END_REGISTERCLASS(KviKvsObject_toolbutton) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_toolbutton,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_toolbutton) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_toolbutton) + +KVSO_END_CONSTRUCTOR(KviKvsObject_toolbutton) + +bool KviKvsObject_toolbutton::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + setObject(new QToolButton(parentScriptWidget(), name()), true); + connect(widget(),SIGNAL(clicked()),this,SLOT(slotClicked())); + return true; +} + +bool KviKvsObject_toolbutton::functionsetImage(KviKvsObjectFunctionCall *c) +{ + QString icon; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("icon_id",KVS_PT_STRING,0,icon) + KVSO_PARAMETERS_END(c) + if (!widget()) return true; + QPixmap * pix = g_pIconManager->getImage(icon); + if(pix){ + #ifdef COMPILE_USE_QT4 + ((QToolButton *)widget())->setIconSet(QIconSet(*pix)); + #else + ((QToolButton *)widget())->setIconSet(QIconSet(*pix,QIconSet::Small)); + #endif + } + else + ((QToolButton *)widget())->setIconSet(QIconSet()); + return true; +} +bool KviKvsObject_toolbutton::functionsetUsesBigPixmap(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QToolButton *)widget())->setUsesBigPixmap(bEnabled); + return true; +} +bool KviKvsObject_toolbutton::functionusesBigPixmap(KviKvsObjectFunctionCall *c) +{ + if (widget()) + c->returnValue()->setBoolean(((QToolButton *)widget())->usesBigPixmap()); + return true; +} +bool KviKvsObject_toolbutton::functionsetUsesTextLabel(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QToolButton *)widget())->setUsesTextLabel(bEnabled); + return true; +} +bool KviKvsObject_toolbutton::functionusesTextLabel(KviKvsObjectFunctionCall *c) +{ + if (widget()) + c->returnValue()->setBoolean(((QToolButton *)widget())->usesTextLabel()); + return true; +} +bool KviKvsObject_toolbutton::function_setAutoRaise(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QToolButton *)widget())->setAutoRaise(bEnabled); + return true; +} +bool KviKvsObject_toolbutton::function_autoRaise(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setBoolean(((QToolButton *)widget())->autoRaise()); + return true; +} +bool KviKvsObject_toolbutton::functionsetOn(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QToolButton *)widget())->setOn(bEnabled); + return true; +} + +bool KviKvsObject_toolbutton::functionsetToggleButton(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QToolButton *)widget())->setToggleButton(bEnabled); + return true; +} +bool KviKvsObject_toolbutton::functiontoggle(KviKvsObjectFunctionCall *c) +{ + if (widget()) + ((QToolButton *)widget())->toggle(); + return true; +} + +bool KviKvsObject_toolbutton::functionsetTextLabel(KviKvsObjectFunctionCall *c) +{ + QString szLabel,szTip; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("label",KVS_PT_STRING,0,szLabel) + KVSO_PARAMETER("tooltip",KVS_PT_STRING,KVS_PF_OPTIONAL,szTip) + KVSO_PARAMETERS_END(c) + if(!widget()) return true; + + #ifdef COMPILE_USE_QT4 + ((QToolButton *)widget())->setText(szLabel); + if (!szTip.isEmpty()) ((QToolButton *)widget())->setToolTip(szTip); + #else + if (szTip.isEmpty()) ((QToolButton *)widget())->setTextLabel(szLabel); + else ((QToolButton *)widget())->setTextLabel(szLabel,szTip); + #endif + return true; +} +bool KviKvsObject_toolbutton::functiontextLabel(KviKvsObjectFunctionCall *c) +{ + if (widget()) + c->returnValue()->setString(((QToolButton *)widget())->textLabel()); + return true; +} +bool KviKvsObject_toolbutton::functionsetPopup(KviKvsObjectFunctionCall *c) +{ + KviKvsObject *ob; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETERS_END(c) + ob=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!ob) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!ob->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!ob->object()->inherits("KviKvsObject_popupmenu")) + { + c->warning(__tr2qs("Can't add a non - popupmenu object")); + return TRUE; + } + if(widget()) + ((QToolButton *)widget())->setPopup(((KviTalPopupMenu *)(ob->object()))); + return true; +} +bool KviKvsObject_toolbutton::functionopenPopup(KviKvsObjectFunctionCall *c) +{ + if(widget()) + ((QToolButton *)widget())->openPopup(); + return true; +} +bool KviKvsObject_toolbutton::functionsetPopupDelay(KviKvsObjectFunctionCall *c) +{ + kvs_int_t uDelay; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("delay",KVS_PT_UNSIGNEDINTEGER,0,uDelay) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QToolButton *)widget())->setPopupDelay(uDelay); + return true; +} +bool KviKvsObject_toolbutton::functionpopupDelay(KviKvsObjectFunctionCall *c) +{ + if (widget()) + c->returnValue()->setInteger(((QToolButton *)widget())->popupDelay()); + return true; +} +bool KviKvsObject_toolbutton::functionsetTextPosition(KviKvsObjectFunctionCall *c) +{ + QString szPos; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("position",KVS_PT_STRING,0,szPos) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + if(KviQString::equalCI(szPos,"BesideIcon")) + ((QToolButton *)widget())->setTextPosition(QToolButton::BesideIcon); + else if(KviQString::equalCI(szPos,"BelowIcon")) + ((QToolButton *)widget())->setTextPosition(QToolButton::BelowIcon); + else c->warning(__tr2qs("Unknown text position '%Q'"),&szPos); + return true; +} +bool KviKvsObject_toolbutton::functiontextPosition(KviKvsObjectFunctionCall *c) +{ + if(!widget()) return true; + QString szPos="BelowIcon"; + if ((((QToolButton *)widget())->textPosition())==(QToolButton::BesideIcon)) + szPos="BesideIcon"; + c->returnValue()->setString(szPos); + return true; +} +bool KviKvsObject_toolbutton::function_clickEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("clicked",c); + return true; +} + +void KviKvsObject_toolbutton::slotClicked() +{ + KviKvsVariantList *params=0; + callFunction(this,"clickEvent",params); +} + +#include "m_class_toolbutton.moc" + diff --git a/src/modules/objects/class_toolbutton.h b/src/modules/objects/class_toolbutton.h new file mode 100644 index 00000000..2cd4dfec --- /dev/null +++ b/src/modules/objects/class_toolbutton.h @@ -0,0 +1,69 @@ +#ifndef _CLASS_TOOLBUTTON_H_ +#define _CLASS_TOOLBUTTON_H_ + +//mdm: +// File : class_toolbutton.h +// Creation date : Wed Feb 23 16:39:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 +#include "class_widget.h" +#include "object_macros.h" + +class KviKvsObject_toolbutton : public KviKvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_toolbutton) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool functionsetImage(KviKvsObjectFunctionCall *c); + bool functionsetUsesBigPixmap(KviKvsObjectFunctionCall *c); + bool functionusesBigPixmap(KviKvsObjectFunctionCall *c); + bool functionsetUsesTextLabel(KviKvsObjectFunctionCall *c); + bool functionusesTextLabel(KviKvsObjectFunctionCall *c); + bool functionsetTextLabel(KviKvsObjectFunctionCall *c); + bool functiontextLabel(KviKvsObjectFunctionCall *c); + bool functionsetPopup(KviKvsObjectFunctionCall *c); + bool functionopenPopup(KviKvsObjectFunctionCall *c); + bool functionsetOn(KviKvsObjectFunctionCall *c); + bool functionsetToggleButton(KviKvsObjectFunctionCall *c); + bool functiontoggle(KviKvsObjectFunctionCall *c); + bool functionsetPopupDelay(KviKvsObjectFunctionCall *c); + bool functionpopupDelay(KviKvsObjectFunctionCall *c); + bool functionsetTextPosition(KviKvsObjectFunctionCall *c); + bool functiontextPosition(KviKvsObjectFunctionCall *c); + + bool function_setAutoRaise(KviKvsObjectFunctionCall *c); + bool function_autoRaise(KviKvsObjectFunctionCall *c); + bool function_clickEvent(KviKvsObjectFunctionCall *c); +signals: + void clicked(); +protected slots: + void slotClicked(); +}; + + +#endif //!_CLASS_TOOLBUTTON_H_ diff --git a/src/modules/objects/class_urllabel.cpp b/src/modules/objects/class_urllabel.cpp new file mode 100644 index 00000000..544153c2 --- /dev/null +++ b/src/modules/objects/class_urllabel.cpp @@ -0,0 +1,330 @@ +//vim: ts=8 +// File : class_urllabel.cpp +// Creation date : Thu Feb 18 1:27:44 CEST 2001 by Krzysztof Godlewski +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 Krzysztof Godlewski +// Copyright (C) 1999-2000 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 "class_urllabel.h" + +#include "kvi_debug.h" +#include "kvi_locale.h" +#include "kvi_error.h" + +#include "kvi_app.h" + +#include "kvi_window.h" +#include "kvi_kvs_script.h" +#ifdef COMPILE_USE_QT4 +#include +#define QT_LEFT_BUTTON Qt::LeftButton +#else +#define QT_LEFT_BUTTON QEvent::LeftButton +#endif +//#warning "Functions to change colors for different states" +//#warning "$setUnderline(), $underline()" + +//extern KviApp * g_pApp; +/*static KviScriptObjectClass * g_pUrlLabelClass = 0; + +static KviScriptObject * urlLabelClassCreateInstance(KviScriptObjectClass * c, + KviScriptObject * p, const char * n) +{ + return new KviScriptUrlLabelObject(c, p, n); +} + +KviScriptUrlLabelObject::KviScriptUrlLabelObject(KviScriptObjectClass * c, \ +KviScriptObject * p, const char *n) : KviScriptLabelObject(c, p, n) +{ + m_normalClr = QColor("black"); + m_enterClr = QColor("blue"); + m_activeClr = QColor("red"); + m_useSingleClick = true; +// ((QLabel *)widget())->setAutoResize(true); + //widget()->setCursor(Qt::pointingHandCursor); + //((KviScriptWidgetObject: * )p)->widget()->setCursor(Qt::pointingHandCursor); +} + +KviScriptUrlLabelObject::~KviScriptUrlLabelObject() +{ +} + +bool KviScriptUrlLabelObject::eventFilter(QObject * o, QEvent * e) +{ + QPalette pal = ((QLabel *)widget())->palette(); + + switch(e->type()) + { + case QEvent::Enter: + pal.setColor(QColorGroup::Foreground, m_enterClr); + break; + case QEvent::Leave: + // this doesn't work... + if(((QMouseEvent *)e)->state() & QEvent::LeftButton) + pal.setColor(QColorGroup::Foreground, \ + m_activeClr); + else + pal.setColor(QColorGroup::Foreground, \ + m_normalClr); + break; + case QEvent::MouseButtonRelease: + pal.setColor(QColorGroup::Foreground, m_enterClr); + // perform actions here + if(!m_lastClickWasDbl && !m_useSingleClick) + break; + if(!m_action.isEmpty()) + { + + } + break; + case QEvent::MouseButtonPress: + m_lastClickWasDbl = false; + if(!((QMouseEvent * )e)->button() & \ + QEvent::LeftButton || !m_useSingleClick) + break; + pal.setColor(QColorGroup::Foreground, m_activeClr); + break; + case QEvent::MouseButtonDblClick: + m_lastClickWasDbl = true; + if(m_useSingleClick) + break; + pal.setColor(QColorGroup::Foreground, m_activeClr); + break; + default: // make gcc happy + break; + } + + ((QLabel *)widget())->setPalette(pal); + + return false; +} +*/ +//#warning "Docs for urllabel" + +/* + @doc: urllabel + @keyterms: + display url, link + @title: + urllabel class + @type: + class + @short: + Displays an URI allowing to perform actions on click + @inherits: + [class]object[/class] + [class]widget[/class] + [class]label[/class] + @description: + This widget allows you to bind specific action on click. It can + open an url, or execute any KVI++ code. The text color reacts on + cursor movements and clicks. + @functions: + !fn: $setUrl() + Sets the url to be opened when the links is activated. The way + the label opens the url is defined in KVirc config dialog. + !fn: $url() + Returns the currently set url. + !fn: $setAction() + Sets the action to be performed when the link is triggered. It + can be any valid KVI++ code. Note that all KVirc commands must + be prefixed with a '/', just as if you typed them in the input + widget. + !fn: $action() + Returns currently set action string. + !fn: $setText() + Sets the label's text. Reimplemented from internal reasons. + !fn: $setCursorChange() + Tells the label wheather to change or not the shape of cursor, + when it is above the widget. Default is false. + !fn: $cursorChange() + Returns true if the cursor changes over the label, false if not. + !fn: $setUseSingleClick() + If is true, the label will react on single clicks, + otherwise only double clicks will trigger the link. + !fn: $useSingleClick() + Returns true if the label reacts on single clicks, false if it + reacts only on double clicks. +*/ + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_urlabel,"urllabel","label") + + KVSO_REGISTER_HANDLER(KviKvsObject_urlabel,"setUrl",functionsetUrl) + KVSO_REGISTER_HANDLER(KviKvsObject_urlabel,"url",functionurl) + KVSO_REGISTER_HANDLER(KviKvsObject_urlabel,"setAction",functionsetAction) + KVSO_REGISTER_HANDLER(KviKvsObject_urlabel,"action",functionaction) + KVSO_REGISTER_HANDLER(KviKvsObject_urlabel,"setText",functionsetText) + KVSO_REGISTER_HANDLER(KviKvsObject_urlabel,"setCursorChange",functionsetCursorChange) + KVSO_REGISTER_HANDLER(KviKvsObject_urlabel,"cursorChange",functioncursorChange) + KVSO_REGISTER_HANDLER(KviKvsObject_urlabel,"setUseSingleClick",functionsetUseSingleClick) + KVSO_REGISTER_HANDLER(KviKvsObject_urlabel,"useSingleClick",functionuseSingleClick) + +KVSO_END_REGISTERCLASS(KviKvsObject_urlabel) + + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_urlabel,KviKvsObject_label) + + m_normalClr = QColor("black"); + m_enterClr = QColor("blue"); + m_activeClr = QColor("red"); + m_useSingleClick = true; + +KVSO_END_CONSTRUCTOR(KviKvsObject_urlabel) + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_urlabel) + +KVSO_END_CONSTRUCTOR(KviKvsObject_urlabel) + +bool KviKvsObject_urlabel::eventFilter(QObject * o, QEvent * e) +{ + QPalette pal = ((QLabel *)widget())->palette(); + + switch(e->type()) + { + case QEvent::Enter: + pal.setColor(QColorGroup::Foreground, m_enterClr); + break; + case QEvent::Leave: + // this doesn't work... + if(((QMouseEvent *)e)->state() & QT_LEFT_BUTTON) + pal.setColor(QColorGroup::Foreground, \ + m_activeClr); + else + pal.setColor(QColorGroup::Foreground, \ + m_normalClr); + break; + case QEvent::MouseButtonRelease: + pal.setColor(QColorGroup::Foreground, m_enterClr); + // perform actions here + if(!m_lastClickWasDbl && !m_useSingleClick) + break; + if(!m_action.isEmpty()) + { + KviKvsScript kvs("commandline",m_action); + kvs.run(g_pActiveWindow,0,0/*,KviKvsScript::AssumeLocals*/); + + } else if(!m_url.isEmpty()) { + KviKvsScript kvs("commandline","openurl "+m_url); + kvs.run(g_pActiveWindow,0,0/*,KviKvsScript::AssumeLocals*/); + } + break; + case QEvent::MouseButtonPress: + m_lastClickWasDbl = false; + if(!((QMouseEvent * )e)->button() & \ + QT_LEFT_BUTTON || !m_useSingleClick) + break; + pal.setColor(QColorGroup::Foreground, m_activeClr); + break; + case QEvent::MouseButtonDblClick: + m_lastClickWasDbl = true; + if(m_useSingleClick) + break; + pal.setColor(QColorGroup::Foreground, m_activeClr); + break; + default: // make gcc happy + break; + } + + ((QLabel *)widget())->setPalette(pal); + + return false; +} +bool KviKvsObject_urlabel::functionsetUrl(KviKvsObjectFunctionCall *c) +{ + QString szUrl; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("url",KVS_PT_STRING,0,szUrl) + KVSO_PARAMETERS_END(c) + if(!widget()) return true; + if(szUrl.isEmpty()){ + c->error(__tr2qs("Not Enough Parameters")); + return false; + } + m_url = szUrl; + return true; +} +bool KviKvsObject_urlabel::functionurl(KviKvsObjectFunctionCall *c) +{ + c->returnValue()->setString(m_url); + return true; +} +bool KviKvsObject_urlabel::functionsetAction(KviKvsObjectFunctionCall *c) +{ + QString szAction; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("action",KVS_PT_STRING,0,szAction) + KVSO_PARAMETERS_END(c) + if(!widget()) return true; + if(szAction.isEmpty()){ + c->error(__tr2qs("Not Enough Parameters")); + return false; + } + m_action = szAction; + return true; +} +bool KviKvsObject_urlabel::functionsetText(KviKvsObjectFunctionCall *c) +{ + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if(!widget()) return true; + ((QLabel *)widget())->setText(szText); + ((QLabel *)widget())->setFixedSize(((QLabel *)widget())->sizeHint()); + return true; +} +bool KviKvsObject_urlabel::functionaction(KviKvsObjectFunctionCall *c) +{ + c->returnValue()->setString(m_action); + return true; +} +bool KviKvsObject_urlabel::functionsetCursorChange(KviKvsObjectFunctionCall *c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOLEAN,0,bFlag) + KVSO_PARAMETERS_END(c) + if(!widget()) + return true; + if(m_changeCursor = bFlag) + widget()->setCursor(Qt::pointingHandCursor); + else + widget()->setCursor(Qt::arrowCursor); + return true; +} +bool KviKvsObject_urlabel::functionsetUseSingleClick(KviKvsObjectFunctionCall *c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOLEAN,0,bFlag) + KVSO_PARAMETERS_END(c) + m_useSingleClick = bFlag; + return true; +} +bool KviKvsObject_urlabel::functionuseSingleClick(KviKvsObjectFunctionCall *c) +{ + c->returnValue()->setBoolean(m_useSingleClick); + return true; +} +bool KviKvsObject_urlabel::functioncursorChange(KviKvsObjectFunctionCall *c) +{ + c->returnValue()->setBoolean(m_changeCursor); + return true; +} diff --git a/src/modules/objects/class_urllabel.h b/src/modules/objects/class_urllabel.h new file mode 100644 index 00000000..b9ee35d6 --- /dev/null +++ b/src/modules/objects/class_urllabel.h @@ -0,0 +1,64 @@ +#ifndef _CLASS_URLLABEL_H_ +#define _CLASS_URLLABEL_H_ +//vim: ts=8 +// File : class_urllabel.h +// Creation date : Thu Feb 18 1:28:23 CEST 2001 by Krzysztof Godlewski +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 Krzysztof Godlewski +// Copyright (C) 1999-2000 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 "class_label.h" +#include "object_macros.h" + +class KviKvsObject_urlabel : public KviKvsObject_label +{ +public: + KVSO_DECLARE_OBJECT(KviKvsObject_urlabel) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool eventFilter(QObject *, QEvent *); + + bool functionsetUrl(KviKvsObjectFunctionCall *c); + bool functionsetAction(KviKvsObjectFunctionCall *c); + bool functionurl(KviKvsObjectFunctionCall *c); + bool functionaction(KviKvsObjectFunctionCall *c); + bool functionsetText(KviKvsObjectFunctionCall *c); + bool functionsetCursorChange(KviKvsObjectFunctionCall *c); + bool functioncursorChange(KviKvsObjectFunctionCall *c); + bool functionsetUseSingleClick(KviKvsObjectFunctionCall *c); + bool functionuseSingleClick(KviKvsObjectFunctionCall *c); + + QString m_url; + QString m_action; + + QColor m_normalClr; + QColor m_enterClr; + QColor m_activeClr; + + bool m_changeCursor; + bool m_useSingleClick; + + bool m_lastClickWasDbl; + +}; + +#endif // !_CLASS_URLLABEL_H_ diff --git a/src/modules/objects/class_vbox.cpp b/src/modules/objects/class_vbox.cpp new file mode 100644 index 00000000..477a5b69 --- /dev/null +++ b/src/modules/objects/class_vbox.cpp @@ -0,0 +1,128 @@ +// +// File : class_vbox.cpp +// Creation date : Wed Mar 01 2005 23:00:01 by Alessandro Carbone & Tonino Imbesi +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2002-2006 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. +// +#define _KVI_DEBUG_CHECK_RANGE_ +#include "kvi_debug.h" + +#include "kvi_locale.h" + +#include "class_vbox.h" + +/* + @doc: vbox + @keyterms: + vbox object class, child widgets + @title: + vbox class + @type: + class + @short: + Manages child widget vertical geometry + @inherits: + [class]object[/class] + @description: + The vbox class widget provides vertical geometry management for its child widgets. + @functions: + !fn: $setSpacing() + Sets the default spacing of the widgets in pixels + !fn: $setMargin() + Sets the dimension of the layout margin : the distance from the border to the outermost child widget edges. + !fn: $setStretchFactor(,) + Sets the stretch factor of widget to stretch. +*/ + + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_vbox,"vbox","widget") + KVSO_REGISTER_HANDLER(KviKvsObject_vbox,"setMargin", functionsetMargin) + KVSO_REGISTER_HANDLER(KviKvsObject_vbox,"setSpacing", functionsetSpacing) + KVSO_REGISTER_HANDLER(KviKvsObject_vbox,"setStretchFactor", functionsetStretchFactor ) +KVSO_END_REGISTERCLASS(KviKvsObject_vbox) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_vbox,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_vbox) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_vbox) + +KVSO_END_CONSTRUCTOR(KviKvsObject_vbox) + +bool KviKvsObject_vbox::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + setObject(new KviTalVBox(parentScriptWidget()), true); + return true; +} + +bool KviKvsObject_vbox::functionsetMargin(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iMargin; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("margin",KVS_PT_INT,0,iMargin) + KVSO_PARAMETERS_END(c) + if (widget()) ((KviTalVBox *)widget())->setMargin(iMargin); + return true; +} + +bool KviKvsObject_vbox::functionsetSpacing(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iSpacing; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("spacing",KVS_PT_INT,0,iSpacing) + KVSO_PARAMETERS_END(c) + if (widget()) ((KviTalVBox *)widget())->setSpacing(iSpacing); + return true; +} + +bool KviKvsObject_vbox::functionsetStretchFactor(KviKvsObjectFunctionCall *c) +{ + KviKvsObject * pObject; + kvs_hobject_t hObject; + kvs_uint_t uStretch; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("stretch",KVS_PT_UNSIGNEDINTEGER,0,uStretch) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if(!widget())return true; + if (!pObject) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!pObject->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!pObject->object()->isWidgetType()) + { + c->warning(__tr2qs("Can't add a non-widget object")); + return true; + } + + if(((KviKvsObject_widget *)pObject)->widget()->parentWidget() != widget()) + { + c->warning(__tr2qs("The widget must be a child of this vbox")); + return true; + } + ((KviTalVBox *)widget())->setStretchFactor(((QWidget *)(pObject->object())),uStretch); + return true; +} \ No newline at end of file diff --git a/src/modules/objects/class_vbox.h b/src/modules/objects/class_vbox.h new file mode 100644 index 00000000..d6b9d1cf --- /dev/null +++ b/src/modules/objects/class_vbox.h @@ -0,0 +1,45 @@ +#ifndef _CLASS_VBOX_H_ +#define _CLASS_VBOX_H_ +// +// File : class_vbox.h +// Creation date : Wed Mar 01 2005 23:00:01 by Alessandro Carbone & Tonino Imbesi +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2002-2006 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 "kvi_string.h" + +#include "class_widget.h" +#include "kvi_tal_vbox.h" +#include "object_macros.h" + +class KviKvsObject_vbox : public KviKvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KviKvsObject_vbox) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + bool functionsetMargin(KviKvsObjectFunctionCall *c); + bool functionsetSpacing(KviKvsObjectFunctionCall *c); + bool functionsetStretchFactor(KviKvsObjectFunctionCall *c); + +}; + + +#endif //_CLASS_HBOX_H_ diff --git a/src/modules/objects/class_widget.cpp b/src/modules/objects/class_widget.cpp new file mode 100644 index 00000000..d248c98b --- /dev/null +++ b/src/modules/objects/class_widget.cpp @@ -0,0 +1,1745 @@ +//============================================================================= +// +// File : class_widget.cpp +// Creation date : Mon Sep 11 16:35:32 CET 2000 by Krzysztof Godlewski +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 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 "kvi_malloc.h" +#include "kvi_debug.h" + +#include "kvi_error.h" +#include "kvi_locale.h" +#include "kvi_iconmanager.h" +#include "kvi_window.h" +#include "kvi_out.h" +#include "kvi_mirccntrl.h" +#include "kvi_app.h" +#include "kvi_string.h" +#include +#include +#include +#include +#include +#include +#include "class_widget.h" +#include "class_pixmap.h" + +#ifdef COMPILE_USE_QT4 + #include + #include +#else + #include +#endif + +#include +#include +#include +#include + +// FIX ME: WFLAGS +const char * const widgettypes_tbl[] = { + "TopLevel", + "Dialog", + "Popup", + "Desktop", + "Customize", + "Title", + "StaysOnTop", + "SysMenu", + "Minimize", + "Maximize", + "NoAutoErase" + }; +#ifdef COMPILE_USE_QT4 +const Qt::WidgetAttribute widgetattributes_cod[]= { + Qt::WA_OpaquePaintEvent, + Qt::WA_NoSystemBackground, + Qt::WA_PaintOnScreen, + Qt::WA_NoMousePropagation, +}; + +const char * const widgetattributes_tbl[] = { + "opaquePaintEvent", + "noSystemBackground", + "paintOnScreen", + "noMousePropagation", +}; +#define widgetattributes_num (sizeof(widgetattributes_tbl) / sizeof(widgetattributes_tbl[0])) + + +const Qt::WindowType widgettypes_cod[] = { +#else +const int widgettypes_cod[] = { +#endif + Qt::WType_TopLevel, + Qt::WType_Dialog, + Qt::WType_Popup, + Qt::WType_Desktop, + Qt::WStyle_Customize, + Qt::WStyle_Title, + Qt::WStyle_StaysOnTop, + Qt::WStyle_SysMenu, + Qt::WStyle_Minimize, + Qt::WStyle_Maximize, + Qt::WNoAutoErase +}; + + +#ifdef COMPILE_USE_QT4 + + #define QT_WIDGET_TABFOCUS Qt::TabFocus + #define QT_WIDGET_CLICKFOCUS Qt::ClickFocus + #define QT_WIDGET_STRONGFOCUS Qt::StrongFocus + #define QT_WIDGET_NOFOCUS Qt::NoFocus + +#else + #define QT_WIDGET_TABFOCUS QWidget::TabFocus + #define QT_WIDGET_CLICKFOCUS QWidget::ClickFocus + #define QT_WIDGET_STRONGFOCUS QWidget::StrongFocus + #define QT_WIDGET_NOFOCUS QWidget::NoFocus +#endif + + +#define widgettypes_num (sizeof(widgettypes_tbl) / sizeof(widgettypes_tbl[0])) + +/* + @doc: widget + @keyterms: + widget object class + @title: + widget class + @type: + class + @short: + Base class for all widgets + @inherits: + [class]object[/class] + @description: + This object class is the rappresentation of a widget. + All the other widget-type classes inherit from this one. + @functions: + !fn: $show() + Shows this widget and the children. + See also [classfnc]$hide[/classfnc]() and [classfnc]$isVisible[/classfnc]. + !fn: $hide() + Hides this widget (and conseguently all the children). + See also [classfnc]$show[/classfnc]() and [classfnc]$isVisible[/classfnc]. + !fn: $repaint() + Repaints the widget directly by calling [classfnc]$paintEvent[/classfnc]() immediately.[br] + If erase is TRUE, erases the widget before the $paintEvent() call. + !fn: $x() + Returns the x coordinate of the upper-left corner + of this widget relative to the parent widget, + or to the desktop if this widget is a toplevel one. + !fn: $y() + Returns the y coordinate of the uspper-left corner + of this widget relative to the parent widget, + or to the desktop if this widget is a toplevel one. + !fn: $width() + Returns the width of this widget in pixels. + !fn: $height() + Returns the height of this widget in pixels. + !fn: $geometry() + Returns the widget geometry in this form:[br] + x, y, width, height. + !fn: $setGeometry(,[,,]) + Sets the geometry of this widget. and are relative + to the parent widget or to the desktop (if this widget is + a toplevel one). All the parameters are in pixels. + !fn: $setMinimumWidth() + Sets the minimum width of this widget to . + The user will not be able to resize the widget to a smaller + value. This value is also used by the [class:layout]layout class[/class]. + !fn: $setMinimumHeight() + Sets the minimum height of this widget to . + The user will not be able to resize the widget to a smaller + value. This value is also used by the [class:layout]layout class[/class]. + !fn: $setMaximumWidth() + Sets the maximum width of this widget to . + The user will not be able to resize the widget to a bigger + value. This value is also used by the [class:layout]layout class[/class]. + !fn: $setMaximumHeight() + Sets the maximum height of this widget to . + The user will not be able to resize the widget to a bigger + value. This value is also used by the [class:layout]layout class[/class]. + !fn: $move([,]) + Moves this widget to the coordinate and relative to its + parent widget (or the desktop if this widget is a toplevel one). + This is equivalent to [classfnc]$setGeometry[/classfnc](,, + [classfnc]$width[/classfnc](),[classfnc]$height[/classfnc]()). + !fn: $resize(,[height]) + Changes the widget's width to and height to . + See also [classfnc]$setGeometry[/classfnc](). + !fn: $isEnabled() + Returns '1' if the widget is enabled , '0' otherwise. + See also [classfnc:widget]$setEnabled[/classfnc](). + !fn: $setEnabled() + Sets the widget state to enabled or disabled if is 1 or 0 respectively. + A disabled widget does not receive keyboard nor mouse input. + !fn: $setCaption() + Sets the caption of this widget to . + This is meaningful for toplevel widgets only. + !fn: $setToolTip() + Set the tooltip of this widget; the text can contain HTML formatting. + !fn: $window.caption() + Returns the caption text of this widget. + !fn: $isTopLevel() + Returns '1' if this widget is a toplevel (parentless) one, + '0' otherwise. + !fn: $isVisible() + Returns '1' if this widget is currently visible (read: is managed + by the window manager and displayed by the X server; the widget + may be hidden behind other widgets). If the widget is not visible + this function returns '0'. + See also [classfnc]$show[/classfnc]() and [classfnc]$hide[/classfnc](). + !fn: $raise() + Moves this widget to the top of the stack of the widgets relative + to its parent. See also [classfnc]$lower[/classfnc]. + !fn: $lower() + Moves this widget to the bottom of the stack of the widgets relative + to its parent. See also [classfnc]$raise[/classfnc] + !fn: $hasFocus() + Returns '1' if this widget has the keyboard focus. + See also [classfnc]$setFocus[/classfnc]. + !fn: $setFocus() + Sets this widget to be the one that receives keyboard events. + See also [classfnc]$hasFocus[/classfnc] + !fn: $parentWidget() + Returns the object id of the parent widget, or '0' if this + widget is a toplevel one. + !fn: $backgroundColor() + Returns the background color of this widget in hexadecimal + html-like format. For example , for a black bacground you will get + the string "000000" , for a red one , "FF0000", for a white one + "FFFFFF". See also [classfnc]$setBackgroundColor[/classfnc]() + !fn: $setBackgroundColor(,[geen:integer],[blue:integer]) + Sets the background color of this widget to :valid values are: + - hex string: must be a string with 6 hexadecimal digits (like the ones used to + specify colors in html pages). The first two digits specify + the RED component, the third and fourth digit specify the GREEN component + and the last two specify the BLUE component. + For example "FFFF00" means full red, full green and no blue that gives + a yellow color, "808000" designates a brown color (dark yellow), + "A000A0" is a kind of violet. + - array(red:integer,green:integer,blue:integer) + - red:integer,green:integer,blue:integer. + See also [classfnc]$foregroundColor[/classfnc]. + !fn: $setForegroundColor(,[geen:integer],[blue:integer]) + Sets the foreground color of this widget to :valid values are: + - hex string: must be a string with 6 hexadecimal digits (like the ones used to + specify colors in html pages). The first two digits specify + the RED component, the third and fourth digit specify the GREEN component + and the last two specify the BLUE component. + For example "FFFF00" means full red, full green and no blue that gives + a yellow color, "808000" designates a brown color (dark yellow), + "A000A0" is a kind of violet. + - array(red:integer,green:integer,blue:integer) + - red:integer,green:integer,blue:integer. + See also [classfnc]$foregroundColor[/classfnc]. + !fn: $foregroundColor() + Returns the foreground color of this widget in hexadecimal + html-like format. + See also [classfnc]$setForegroundColor[/classfnc]. + !fn: $setMouseTracking() + Enables or disables the mouse tracking if is '1' or '0' respectively. + When mouse tracking is enabled you will receive mouse move events + even if no button is pressed, otherwise you will receive it only + when a mouse button is being pressed (so after a mousePressEvent). + !fn: $mousePressEvent(