From c601b5a27f74b16158adafe429faefbe573e64a2 Mon Sep 17 00:00:00 2001 From: Szymon Tomasz Stefanek Date: Sat, 1 Jan 2011 20:19:56 +0000 Subject: The big rename for modules. Still some details remaining. git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5284 17fca916-40b9-46aa-a4ea-0a15b648b75c --- src/modules/objects/CMakeLists.txt | 148 +- src/modules/objects/KvsObject_button.cpp | 167 ++ src/modules/objects/KvsObject_button.h | 53 + src/modules/objects/KvsObject_buttonGroup.cpp | 106 ++ src/modules/objects/KvsObject_buttonGroup.h | 46 + src/modules/objects/KvsObject_checkBox.cpp | 136 ++ src/modules/objects/KvsObject_checkBox.h | 50 + src/modules/objects/KvsObject_comboBox.cpp | 366 ++++ src/modules/objects/KvsObject_comboBox.h | 74 + src/modules/objects/KvsObject_dateTimeEdit.cpp | 162 ++ src/modules/objects/KvsObject_dateTimeEdit.h | 56 + src/modules/objects/KvsObject_dialog.cpp | 91 + src/modules/objects/KvsObject_dialog.h | 43 + src/modules/objects/KvsObject_dockWindow.cpp | 181 ++ src/modules/objects/KvsObject_dockWindow.h | 44 + src/modules/objects/KvsObject_file.cpp | 648 +++++++ src/modules/objects/KvsObject_file.h | 74 + src/modules/objects/KvsObject_ftp.cpp | 327 ++++ src/modules/objects/KvsObject_ftp.h | 64 + src/modules/objects/KvsObject_groupBox.cpp | 335 ++++ src/modules/objects/KvsObject_groupBox.h | 63 + src/modules/objects/KvsObject_hBox.cpp | 202 ++ src/modules/objects/KvsObject_hBox.h | 49 + src/modules/objects/KvsObject_http.cpp | 561 ++++++ src/modules/objects/KvsObject_http.h | 89 + src/modules/objects/KvsObject_label.cpp | 361 ++++ src/modules/objects/KvsObject_label.h | 53 + src/modules/objects/KvsObject_layout.cpp | 317 ++++ src/modules/objects/KvsObject_layout.h | 53 + src/modules/objects/KvsObject_lcd.cpp | 191 ++ src/modules/objects/KvsObject_lcd.h | 52 + src/modules/objects/KvsObject_lineEdit.cpp | 543 ++++++ src/modules/objects/KvsObject_lineEdit.h | 90 + src/modules/objects/KvsObject_list.cpp | 342 ++++ src/modules/objects/KvsObject_list.h | 64 + src/modules/objects/KvsObject_listWidget.cpp | 680 +++++++ src/modules/objects/KvsObject_listWidget.h | 81 + src/modules/objects/KvsObject_mainWindow.cpp | 101 + src/modules/objects/KvsObject_mainWindow.h | 46 + src/modules/objects/KvsObject_memoryBuffer.cpp | 125 ++ src/modules/objects/KvsObject_memoryBuffer.h | 53 + src/modules/objects/KvsObject_menuBar.cpp | 77 + src/modules/objects/KvsObject_menuBar.h | 42 + src/modules/objects/KvsObject_multiLineEdit.cpp | 785 ++++++++ src/modules/objects/KvsObject_multiLineEdit.h | 93 + src/modules/objects/KvsObject_painter.cpp | 1738 ++++++++++++++++++ src/modules/objects/KvsObject_painter.h | 131 ++ src/modules/objects/KvsObject_pixmap.cpp | 360 ++++ src/modules/objects/KvsObject_pixmap.h | 76 + src/modules/objects/KvsObject_popupMenu.cpp | 398 ++++ src/modules/objects/KvsObject_popupMenu.h | 64 + src/modules/objects/KvsObject_process.cpp | 323 ++++ src/modules/objects/KvsObject_process.h | 69 + src/modules/objects/KvsObject_progressBar.cpp | 150 ++ src/modules/objects/KvsObject_progressBar.h | 51 + src/modules/objects/KvsObject_radioButton.cpp | 146 ++ src/modules/objects/KvsObject_radioButton.h | 51 + src/modules/objects/KvsObject_slider.cpp | 301 +++ src/modules/objects/KvsObject_slider.h | 64 + src/modules/objects/KvsObject_socket.cpp | 1297 +++++++++++++ src/modules/objects/KvsObject_socket.h | 113 ++ src/modules/objects/KvsObject_spinBox.cpp | 267 +++ src/modules/objects/KvsObject_spinBox.h | 64 + src/modules/objects/KvsObject_sql.cpp | 603 ++++++ src/modules/objects/KvsObject_sql.h | 79 + src/modules/objects/KvsObject_tabWidget.cpp | 456 +++++ src/modules/objects/KvsObject_tabWidget.h | 67 + src/modules/objects/KvsObject_tableWidget.cpp | 796 ++++++++ src/modules/objects/KvsObject_tableWidget.h | 116 ++ src/modules/objects/KvsObject_textBrowser.cpp | 155 ++ src/modules/objects/KvsObject_textBrowser.h | 53 + src/modules/objects/KvsObject_toolBar.cpp | 128 ++ src/modules/objects/KvsObject_toolBar.h | 48 + src/modules/objects/KvsObject_toolButton.cpp | 344 ++++ src/modules/objects/KvsObject_toolButton.h | 70 + src/modules/objects/KvsObject_trayIcon.cpp | 243 +++ src/modules/objects/KvsObject_trayIcon.h | 58 + src/modules/objects/KvsObject_treeWidget.cpp | 666 +++++++ src/modules/objects/KvsObject_treeWidget.h | 100 + src/modules/objects/KvsObject_treeWidgeteItem.cpp | 429 +++++ src/modules/objects/KvsObject_treeWidgeteItem.h | 78 + src/modules/objects/KvsObject_vBox.cpp | 209 +++ src/modules/objects/KvsObject_vBox.h | 49 + src/modules/objects/KvsObject_widget.cpp | 2030 +++++++++++++++++++++ src/modules/objects/KvsObject_widget.h | 145 ++ src/modules/objects/KvsObject_window.cpp | 158 ++ src/modules/objects/KvsObject_window.h | 65 + src/modules/objects/KvsObject_wizard.cpp | 386 ++++ src/modules/objects/KvsObject_wizard.h | 80 + src/modules/objects/KvsObject_workspace.cpp | 328 ++++ src/modules/objects/KvsObject_workspace.h | 57 + src/modules/objects/KvsObject_wrapper.cpp | 221 +++ src/modules/objects/KvsObject_wrapper.h | 51 + src/modules/objects/KvsObject_xmlreader.cpp | 375 ++++ src/modules/objects/KvsObject_xmlreader.h | 45 + src/modules/objects/class_button.cpp | 167 -- src/modules/objects/class_button.h | 53 - src/modules/objects/class_buttongroup.cpp | 106 -- src/modules/objects/class_buttongroup.h | 46 - src/modules/objects/class_checkbox.cpp | 136 -- src/modules/objects/class_checkbox.h | 50 - src/modules/objects/class_combobox.cpp | 366 ---- src/modules/objects/class_combobox.h | 74 - src/modules/objects/class_datetimeedit.cpp | 162 -- src/modules/objects/class_datetimeedit.h | 56 - src/modules/objects/class_dialog.cpp | 91 - src/modules/objects/class_dialog.h | 43 - src/modules/objects/class_dockwindow.cpp | 181 -- src/modules/objects/class_dockwindow.h | 44 - src/modules/objects/class_file.cpp | 648 ------- src/modules/objects/class_file.h | 74 - src/modules/objects/class_ftp.cpp | 327 ---- src/modules/objects/class_ftp.h | 64 - src/modules/objects/class_groupbox.cpp | 335 ---- src/modules/objects/class_groupbox.h | 63 - src/modules/objects/class_hbox.cpp | 202 -- src/modules/objects/class_hbox.h | 49 - src/modules/objects/class_http.cpp | 561 ------ src/modules/objects/class_http.h | 89 - src/modules/objects/class_label.cpp | 361 ---- src/modules/objects/class_label.h | 53 - src/modules/objects/class_layout.cpp | 317 ---- src/modules/objects/class_layout.h | 53 - src/modules/objects/class_lcd.cpp | 191 -- src/modules/objects/class_lcd.h | 52 - src/modules/objects/class_lineedit.cpp | 543 ------ src/modules/objects/class_lineedit.h | 90 - src/modules/objects/class_list.cpp | 342 ---- src/modules/objects/class_list.h | 64 - src/modules/objects/class_listwidget.cpp | 680 ------- src/modules/objects/class_listwidget.h | 81 - src/modules/objects/class_mainwindow.cpp | 101 - src/modules/objects/class_mainwindow.h | 46 - src/modules/objects/class_memorybuffer.cpp | 125 -- src/modules/objects/class_memorybuffer.h | 53 - src/modules/objects/class_menubar.cpp | 77 - src/modules/objects/class_menubar.h | 42 - src/modules/objects/class_multilineedit.cpp | 785 -------- src/modules/objects/class_multilineedit.h | 93 - src/modules/objects/class_painter.cpp | 1738 ------------------ src/modules/objects/class_painter.h | 131 -- src/modules/objects/class_pixmap.cpp | 360 ---- src/modules/objects/class_pixmap.h | 76 - src/modules/objects/class_popupmenu.cpp | 398 ---- src/modules/objects/class_popupmenu.h | 64 - src/modules/objects/class_process.cpp | 323 ---- src/modules/objects/class_process.h | 69 - src/modules/objects/class_progressbar.cpp | 150 -- src/modules/objects/class_progressbar.h | 51 - src/modules/objects/class_radiobutton.cpp | 146 -- src/modules/objects/class_radiobutton.h | 51 - src/modules/objects/class_slider.cpp | 301 --- src/modules/objects/class_slider.h | 64 - src/modules/objects/class_socket.cpp | 1297 ------------- src/modules/objects/class_socket.h | 113 -- src/modules/objects/class_spinbox.cpp | 267 --- src/modules/objects/class_spinbox.h | 64 - src/modules/objects/class_sql.cpp | 603 ------ src/modules/objects/class_sql.h | 79 - src/modules/objects/class_tablewidget.cpp | 796 -------- src/modules/objects/class_tablewidget.h | 116 -- src/modules/objects/class_tabwidget.cpp | 456 ----- src/modules/objects/class_tabwidget.h | 67 - src/modules/objects/class_tbrowser.cpp | 155 -- src/modules/objects/class_tbrowser.h | 52 - src/modules/objects/class_toolbar.cpp | 128 -- src/modules/objects/class_toolbar.h | 48 - src/modules/objects/class_toolbutton.cpp | 344 ---- src/modules/objects/class_toolbutton.h | 70 - src/modules/objects/class_trayicon.cpp | 243 --- src/modules/objects/class_trayicon.h | 58 - src/modules/objects/class_treewidget.cpp | 666 ------- src/modules/objects/class_treewidget.h | 100 - src/modules/objects/class_treewidgetitem.cpp | 429 ----- src/modules/objects/class_treewidgetitem.h | 78 - src/modules/objects/class_vbox.cpp | 209 --- src/modules/objects/class_vbox.h | 49 - src/modules/objects/class_widget.cpp | 2030 --------------------- src/modules/objects/class_widget.h | 145 -- src/modules/objects/class_window.cpp | 158 -- src/modules/objects/class_window.h | 65 - src/modules/objects/class_wizard.cpp | 386 ---- src/modules/objects/class_wizard.h | 80 - src/modules/objects/class_workspace.cpp | 328 ---- src/modules/objects/class_workspace.h | 57 - src/modules/objects/class_wrapper.cpp | 221 --- src/modules/objects/class_wrapper.h | 51 - src/modules/objects/class_xmlreader.cpp | 375 ---- src/modules/objects/class_xmlreader.h | 45 - src/modules/objects/libkviobjects.cpp | 284 +-- src/modules/objects/object_macros.h | 2 +- 191 files changed, 22704 insertions(+), 22703 deletions(-) create mode 100644 src/modules/objects/KvsObject_button.cpp create mode 100644 src/modules/objects/KvsObject_button.h create mode 100644 src/modules/objects/KvsObject_buttonGroup.cpp create mode 100644 src/modules/objects/KvsObject_buttonGroup.h create mode 100644 src/modules/objects/KvsObject_checkBox.cpp create mode 100644 src/modules/objects/KvsObject_checkBox.h create mode 100644 src/modules/objects/KvsObject_comboBox.cpp create mode 100644 src/modules/objects/KvsObject_comboBox.h create mode 100644 src/modules/objects/KvsObject_dateTimeEdit.cpp create mode 100644 src/modules/objects/KvsObject_dateTimeEdit.h create mode 100644 src/modules/objects/KvsObject_dialog.cpp create mode 100644 src/modules/objects/KvsObject_dialog.h create mode 100644 src/modules/objects/KvsObject_dockWindow.cpp create mode 100644 src/modules/objects/KvsObject_dockWindow.h create mode 100644 src/modules/objects/KvsObject_file.cpp create mode 100644 src/modules/objects/KvsObject_file.h create mode 100644 src/modules/objects/KvsObject_ftp.cpp create mode 100644 src/modules/objects/KvsObject_ftp.h create mode 100644 src/modules/objects/KvsObject_groupBox.cpp create mode 100644 src/modules/objects/KvsObject_groupBox.h create mode 100644 src/modules/objects/KvsObject_hBox.cpp create mode 100644 src/modules/objects/KvsObject_hBox.h create mode 100644 src/modules/objects/KvsObject_http.cpp create mode 100644 src/modules/objects/KvsObject_http.h create mode 100644 src/modules/objects/KvsObject_label.cpp create mode 100644 src/modules/objects/KvsObject_label.h create mode 100644 src/modules/objects/KvsObject_layout.cpp create mode 100644 src/modules/objects/KvsObject_layout.h create mode 100644 src/modules/objects/KvsObject_lcd.cpp create mode 100644 src/modules/objects/KvsObject_lcd.h create mode 100644 src/modules/objects/KvsObject_lineEdit.cpp create mode 100644 src/modules/objects/KvsObject_lineEdit.h create mode 100644 src/modules/objects/KvsObject_list.cpp create mode 100644 src/modules/objects/KvsObject_list.h create mode 100644 src/modules/objects/KvsObject_listWidget.cpp create mode 100644 src/modules/objects/KvsObject_listWidget.h create mode 100644 src/modules/objects/KvsObject_mainWindow.cpp create mode 100644 src/modules/objects/KvsObject_mainWindow.h create mode 100644 src/modules/objects/KvsObject_memoryBuffer.cpp create mode 100644 src/modules/objects/KvsObject_memoryBuffer.h create mode 100644 src/modules/objects/KvsObject_menuBar.cpp create mode 100644 src/modules/objects/KvsObject_menuBar.h create mode 100644 src/modules/objects/KvsObject_multiLineEdit.cpp create mode 100644 src/modules/objects/KvsObject_multiLineEdit.h create mode 100644 src/modules/objects/KvsObject_painter.cpp create mode 100644 src/modules/objects/KvsObject_painter.h create mode 100644 src/modules/objects/KvsObject_pixmap.cpp create mode 100644 src/modules/objects/KvsObject_pixmap.h create mode 100644 src/modules/objects/KvsObject_popupMenu.cpp create mode 100644 src/modules/objects/KvsObject_popupMenu.h create mode 100644 src/modules/objects/KvsObject_process.cpp create mode 100644 src/modules/objects/KvsObject_process.h create mode 100644 src/modules/objects/KvsObject_progressBar.cpp create mode 100644 src/modules/objects/KvsObject_progressBar.h create mode 100644 src/modules/objects/KvsObject_radioButton.cpp create mode 100644 src/modules/objects/KvsObject_radioButton.h create mode 100644 src/modules/objects/KvsObject_slider.cpp create mode 100644 src/modules/objects/KvsObject_slider.h create mode 100644 src/modules/objects/KvsObject_socket.cpp create mode 100644 src/modules/objects/KvsObject_socket.h create mode 100644 src/modules/objects/KvsObject_spinBox.cpp create mode 100644 src/modules/objects/KvsObject_spinBox.h create mode 100644 src/modules/objects/KvsObject_sql.cpp create mode 100644 src/modules/objects/KvsObject_sql.h create mode 100644 src/modules/objects/KvsObject_tabWidget.cpp create mode 100644 src/modules/objects/KvsObject_tabWidget.h create mode 100644 src/modules/objects/KvsObject_tableWidget.cpp create mode 100644 src/modules/objects/KvsObject_tableWidget.h create mode 100644 src/modules/objects/KvsObject_textBrowser.cpp create mode 100644 src/modules/objects/KvsObject_textBrowser.h create mode 100644 src/modules/objects/KvsObject_toolBar.cpp create mode 100644 src/modules/objects/KvsObject_toolBar.h create mode 100644 src/modules/objects/KvsObject_toolButton.cpp create mode 100644 src/modules/objects/KvsObject_toolButton.h create mode 100644 src/modules/objects/KvsObject_trayIcon.cpp create mode 100644 src/modules/objects/KvsObject_trayIcon.h create mode 100644 src/modules/objects/KvsObject_treeWidget.cpp create mode 100644 src/modules/objects/KvsObject_treeWidget.h create mode 100644 src/modules/objects/KvsObject_treeWidgeteItem.cpp create mode 100644 src/modules/objects/KvsObject_treeWidgeteItem.h create mode 100644 src/modules/objects/KvsObject_vBox.cpp create mode 100644 src/modules/objects/KvsObject_vBox.h create mode 100644 src/modules/objects/KvsObject_widget.cpp create mode 100644 src/modules/objects/KvsObject_widget.h create mode 100644 src/modules/objects/KvsObject_window.cpp create mode 100644 src/modules/objects/KvsObject_window.h create mode 100644 src/modules/objects/KvsObject_wizard.cpp create mode 100644 src/modules/objects/KvsObject_wizard.h create mode 100644 src/modules/objects/KvsObject_workspace.cpp create mode 100644 src/modules/objects/KvsObject_workspace.h create mode 100644 src/modules/objects/KvsObject_wrapper.cpp create mode 100644 src/modules/objects/KvsObject_wrapper.h create mode 100644 src/modules/objects/KvsObject_xmlreader.cpp create mode 100644 src/modules/objects/KvsObject_xmlreader.h delete mode 100644 src/modules/objects/class_button.cpp delete mode 100644 src/modules/objects/class_button.h delete mode 100644 src/modules/objects/class_buttongroup.cpp delete mode 100644 src/modules/objects/class_buttongroup.h delete mode 100644 src/modules/objects/class_checkbox.cpp delete mode 100644 src/modules/objects/class_checkbox.h delete mode 100644 src/modules/objects/class_combobox.cpp delete mode 100644 src/modules/objects/class_combobox.h delete mode 100644 src/modules/objects/class_datetimeedit.cpp delete mode 100644 src/modules/objects/class_datetimeedit.h delete mode 100644 src/modules/objects/class_dialog.cpp delete mode 100644 src/modules/objects/class_dialog.h delete mode 100644 src/modules/objects/class_dockwindow.cpp delete mode 100644 src/modules/objects/class_dockwindow.h delete mode 100644 src/modules/objects/class_file.cpp delete mode 100644 src/modules/objects/class_file.h delete mode 100644 src/modules/objects/class_ftp.cpp delete mode 100644 src/modules/objects/class_ftp.h delete mode 100644 src/modules/objects/class_groupbox.cpp delete mode 100644 src/modules/objects/class_groupbox.h delete mode 100644 src/modules/objects/class_hbox.cpp delete mode 100644 src/modules/objects/class_hbox.h delete mode 100644 src/modules/objects/class_http.cpp delete mode 100644 src/modules/objects/class_http.h delete mode 100644 src/modules/objects/class_label.cpp delete mode 100644 src/modules/objects/class_label.h delete mode 100644 src/modules/objects/class_layout.cpp delete mode 100644 src/modules/objects/class_layout.h delete mode 100644 src/modules/objects/class_lcd.cpp delete mode 100644 src/modules/objects/class_lcd.h delete mode 100644 src/modules/objects/class_lineedit.cpp delete mode 100644 src/modules/objects/class_lineedit.h delete mode 100644 src/modules/objects/class_list.cpp delete mode 100644 src/modules/objects/class_list.h delete mode 100644 src/modules/objects/class_listwidget.cpp delete mode 100644 src/modules/objects/class_listwidget.h delete mode 100644 src/modules/objects/class_mainwindow.cpp delete mode 100644 src/modules/objects/class_mainwindow.h delete mode 100644 src/modules/objects/class_memorybuffer.cpp delete mode 100644 src/modules/objects/class_memorybuffer.h delete mode 100644 src/modules/objects/class_menubar.cpp delete mode 100644 src/modules/objects/class_menubar.h delete mode 100644 src/modules/objects/class_multilineedit.cpp delete mode 100644 src/modules/objects/class_multilineedit.h delete mode 100644 src/modules/objects/class_painter.cpp delete mode 100644 src/modules/objects/class_painter.h delete mode 100644 src/modules/objects/class_pixmap.cpp delete mode 100644 src/modules/objects/class_pixmap.h delete mode 100644 src/modules/objects/class_popupmenu.cpp delete mode 100644 src/modules/objects/class_popupmenu.h delete mode 100644 src/modules/objects/class_process.cpp delete mode 100644 src/modules/objects/class_process.h delete mode 100644 src/modules/objects/class_progressbar.cpp delete mode 100644 src/modules/objects/class_progressbar.h delete mode 100644 src/modules/objects/class_radiobutton.cpp delete mode 100644 src/modules/objects/class_radiobutton.h delete mode 100644 src/modules/objects/class_slider.cpp delete mode 100644 src/modules/objects/class_slider.h delete mode 100644 src/modules/objects/class_socket.cpp delete mode 100644 src/modules/objects/class_socket.h delete mode 100644 src/modules/objects/class_spinbox.cpp delete mode 100644 src/modules/objects/class_spinbox.h delete mode 100644 src/modules/objects/class_sql.cpp delete mode 100644 src/modules/objects/class_sql.h delete mode 100644 src/modules/objects/class_tablewidget.cpp delete mode 100644 src/modules/objects/class_tablewidget.h delete mode 100644 src/modules/objects/class_tabwidget.cpp delete mode 100644 src/modules/objects/class_tabwidget.h delete mode 100644 src/modules/objects/class_tbrowser.cpp delete mode 100644 src/modules/objects/class_tbrowser.h delete mode 100644 src/modules/objects/class_toolbar.cpp delete mode 100644 src/modules/objects/class_toolbar.h delete mode 100644 src/modules/objects/class_toolbutton.cpp delete mode 100644 src/modules/objects/class_toolbutton.h delete mode 100644 src/modules/objects/class_trayicon.cpp delete mode 100644 src/modules/objects/class_trayicon.h delete mode 100644 src/modules/objects/class_treewidget.cpp delete mode 100644 src/modules/objects/class_treewidget.h delete mode 100644 src/modules/objects/class_treewidgetitem.cpp delete mode 100644 src/modules/objects/class_treewidgetitem.h delete mode 100644 src/modules/objects/class_vbox.cpp delete mode 100644 src/modules/objects/class_vbox.h delete mode 100644 src/modules/objects/class_widget.cpp delete mode 100644 src/modules/objects/class_widget.h delete mode 100644 src/modules/objects/class_window.cpp delete mode 100644 src/modules/objects/class_window.h delete mode 100644 src/modules/objects/class_wizard.cpp delete mode 100644 src/modules/objects/class_wizard.h delete mode 100644 src/modules/objects/class_workspace.cpp delete mode 100644 src/modules/objects/class_workspace.h delete mode 100644 src/modules/objects/class_wrapper.cpp delete mode 100644 src/modules/objects/class_wrapper.h delete mode 100644 src/modules/objects/class_xmlreader.cpp delete mode 100644 src/modules/objects/class_xmlreader.h (limited to 'src/modules/objects') diff --git a/src/modules/objects/CMakeLists.txt b/src/modules/objects/CMakeLists.txt index 694cde24c..da456fe1b 100644 --- a/src/modules/objects/CMakeLists.txt +++ b/src/modules/objects/CMakeLists.txt @@ -8,84 +8,84 @@ IF(WIN32) ENDIF() SET(kviobjects_MOC_HDRS - class_button.h - class_checkbox.h - class_combobox.h - class_datetimeedit.h - class_dockwindow.h - class_ftp.h - class_http.h - class_lineedit.h - class_listwidget.h - class_multilineedit.h - class_painter.h - class_pixmap.h - class_popupmenu.h - class_process.h - class_radiobutton.h - class_slider.h - class_socket.h - class_spinbox.h - class_tabwidget.h - class_tablewidget.h - class_trayicon.h - class_tbrowser.h - class_toolbutton.h - class_treewidget.h - class_widget.h - class_window.h - class_wizard.h + KvsObject_button.h + KvsObject_checkBox.h + KvsObject_comboBox.h + KvsObject_dateTimeEdit.h + KvsObject_dockWindow.h + KvsObject_ftp.h + KvsObject_http.h + KvsObject_lineEdit.h + KvsObject_listWidget.h + KvsObject_multiLineEdit.h + KvsObject_painter.h + KvsObject_pixmap.h + KvsObject_popupMenu.h + KvsObject_process.h + KvsObject_radioButton.h + KvsObject_slider.h + KvsObject_socket.h + KvsObject_spinBox.h + KvsObject_tabWidget.h + KvsObject_tableWidget.h + KvsObject_trayIcon.h + KvsObject_textBrowser.h + KvsObject_toolButton.h + KvsObject_treeWidget.h + KvsObject_widget.h + KvsObject_window.h + KvsObject_wizard.h ) SET(kviobjects_SRCS libkviobjects.cpp - class_button.cpp - class_buttongroup.cpp - class_checkbox.cpp - class_combobox.cpp - class_datetimeedit.cpp - class_dialog.cpp - class_dockwindow.cpp - class_file.cpp - class_ftp.cpp - class_groupbox.cpp - class_hbox.cpp - class_http.cpp - class_label.cpp - class_layout.cpp - class_lcd.cpp - class_lineedit.cpp - class_list.cpp - class_listwidget.cpp - class_mainwindow.cpp - class_memorybuffer.cpp - class_menubar.cpp - class_multilineedit.cpp - class_painter.cpp - class_pixmap.cpp - class_popupmenu.cpp - class_process.cpp - class_progressbar.cpp - class_radiobutton.cpp - class_slider.cpp - class_socket.cpp - class_spinbox.cpp - class_sql.cpp - class_tabwidget.cpp - class_tablewidget.cpp - class_trayicon.cpp - class_tbrowser.cpp - class_toolbar.cpp - class_toolbutton.cpp - class_treewidget.cpp - class_treewidgetitem.cpp - class_vbox.cpp - class_widget.cpp - class_window.cpp - class_wizard.cpp - class_workspace.cpp - class_wrapper.cpp - class_xmlreader.cpp + KvsObject_button.cpp + KvsObject_buttonGroup.cpp + KvsObject_checkBox.cpp + KvsObject_comboBox.cpp + KvsObject_dateTimeEdit.cpp + KvsObject_dialog.cpp + KvsObject_dockWindow.cpp + KvsObject_file.cpp + KvsObject_ftp.cpp + KvsObject_groupBox.cpp + KvsObject_hBox.cpp + KvsObject_http.cpp + KvsObject_label.cpp + KvsObject_layout.cpp + KvsObject_lcd.cpp + KvsObject_lineEdit.cpp + KvsObject_list.cpp + KvsObject_listWidget.cpp + KvsObject_mainWindow.cpp + KvsObject_memoryBuffer.cpp + KvsObject_menuBar.cpp + KvsObject_multiLineEdit.cpp + KvsObject_painter.cpp + KvsObject_pixmap.cpp + KvsObject_popupMenu.cpp + KvsObject_process.cpp + KvsObject_progressBar.cpp + KvsObject_radioButton.cpp + KvsObject_slider.cpp + KvsObject_socket.cpp + KvsObject_spinBox.cpp + KvsObject_sql.cpp + KvsObject_tabWidget.cpp + KvsObject_tableWidget.cpp + KvsObject_trayIcon.cpp + KvsObject_textBrowser.cpp + KvsObject_toolBar.cpp + KvsObject_toolButton.cpp + KvsObject_treeWidget.cpp + KvsObject_treeWidgeteItem.cpp + KvsObject_vBox.cpp + KvsObject_widget.cpp + KvsObject_window.cpp + KvsObject_wizard.cpp + KvsObject_workspace.cpp + KvsObject_wrapper.cpp + KvsObject_xmlreader.cpp ) # After this call, files will be moc'ed to moc_kvi_*.cpp diff --git a/src/modules/objects/KvsObject_button.cpp b/src/modules/objects/KvsObject_button.cpp new file mode 100644 index 000000000..1730379ae --- /dev/null +++ b/src/modules/objects/KvsObject_button.cpp @@ -0,0 +1,167 @@ +//============================================================================= +// +// File : KvsObject_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) 2000 Krzysztof Godlewski +// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KviError.h" +#include "KviIconManager.h" +#include "KviFile.h" + +#include "KvsObject_button.h" +#include "KvsObject_pixmap.h" + +#include +#include + +/* + @doc:button + @title: + button class + @type: + class + @short: + Button widget. + @inherits: + [class]object[/class] + [class]button[/class] + @description: + This widget provides a push button + @functions: + !fn: $setText([]) + Set the button text.[br] + See also [classfnc]$text[/classfnc](). + !fn: $text() + Return the button text.[br] + See also [classfnc]$setText[/classfnc](). + !fn: $setImage() + Sets the icon for this button. + See the [doc:image_id]image identifier[/doc] documentation for the explaination of the parameter. + !fn: $clickEvent() + Called by KVIrc when the mouse button is clicked. + The default implementation emits the [classfnc]$clicked[/classfnc]()signal. + @signals: + !sg: $clicked() + This signal is emitted by the default implementation of [classfnc]$clickEvent[/classfnc](). + @properties: + !pr: $scaledContents() + This property holds whether the label will scale its contents to fill all available space. +*/ + + +KVSO_BEGIN_REGISTERCLASS(KvsObject_button,"button","widget") + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_button,setText) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_button,text) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_button,clickEvent) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_button,setImage) + +KVSO_END_REGISTERCLASS(KvsObject_button) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_button,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_button) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_button) + +KVSO_END_DESTRUCTOR(KvsObject_button) + +bool KvsObject_button::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT(QPushButton); + connect(widget(),SIGNAL(clicked()),this,SLOT(slotClicked())); + return true; +} + +KVSO_CLASS_FUNCTION(button,text) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setString(((QPushButton *)widget())->text()); + return true; +} + +KVSO_CLASS_FUNCTION(button,setText) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + ((QPushButton *)widget())->setText(szText); + return true; +} + +KVSO_CLASS_FUNCTION(button,setImage) +{ + CHECK_INTERNAL_POINTER(widget()) + KviKvsVariant * pIcon; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("icon_or_hobject",KVS_PT_VARIANT,0,pIcon) + KVSO_PARAMETERS_END(c) + if(!pIcon) + { + c->warning(__tr2qs_ctx("Image parameter missing","object")); + return true; + } + if(pIcon->isHObject()) + { + kvs_hobject_t hObj; + pIcon->asHObject(hObj); + KviKvsObject *pObject = KviKvsKernel::instance()->objectController()->lookupObject(hObj); + if (!pObject) + { + c->warning(__tr2qs_ctx("Pixmap parameter is not an object!","objects")); + return true; + } + if(pObject->inheritsClass("pixmap")) + ((QPushButton *)widget())->setIcon(QIcon(*((KvsObject_pixmap *)pObject)->getPixmap())); + else + c->warning(__tr2qs_ctx("Object Pixmap required!","object")); + return true; + } + QString szIcon; + pIcon->asString(szIcon); + QPixmap * pix = g_pIconManager->getImage(szIcon); + if(pix) ((QPushButton *)widget())->setIcon(*pix); + else((QPushButton *)widget())->setIcon(QIcon()); + return true; +} +KVSO_CLASS_FUNCTION(button,clickEvent) +{ + emitSignal("clicked",c); + return true; +} + +// slots +void KvsObject_button::slotClicked() +{ + KviKvsVariantList *params=0; + callFunction(this,"clickEvent",params); +} + + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_button.moc" +#endif //COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/KvsObject_button.h b/src/modules/objects/KvsObject_button.h new file mode 100644 index 000000000..8fb8ce8c4 --- /dev/null +++ b/src/modules/objects/KvsObject_button.h @@ -0,0 +1,53 @@ +#ifndef _CLASS_BUTTON_H_ +#define _CLASS_BUTTON_H_ +//============================================================================= +// +// File : KvsObject_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) 2000 Krzysztof Godlewski +// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + + + +#include "KvsObject_widget.h" +#include "object_macros.h" + +class KvsObject_button : public KvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_button) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool setText(KviKvsObjectFunctionCall *c); + bool text(KviKvsObjectFunctionCall *c); + + bool setImage(KviKvsObjectFunctionCall *c); + bool clickEvent(KviKvsObjectFunctionCall *c); + +protected slots: + void slotClicked(); +}; + +#endif // !_CLASS_BUTTON_H_ diff --git a/src/modules/objects/KvsObject_buttonGroup.cpp b/src/modules/objects/KvsObject_buttonGroup.cpp new file mode 100644 index 000000000..82f4c1f89 --- /dev/null +++ b/src/modules/objects/KvsObject_buttonGroup.cpp @@ -0,0 +1,106 @@ +//============================================================================= +// +// File : KvsObject_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) 2009 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_buttonGroup.h" +#include "KviError.h" +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KviIconManager.h" + +#include +#include + +/* + @doc: buttongroup + @keyterms: + buttongroup object class, + @title: + buttongroup class + @type: + class + @short: + Provides a buttongroup control. + @inherits: + [class]object[/class] + @description: + This object organizes buttons in a group. + @functions: + !fn: $addButton() + Adds the given button to the button group and returns an unique identifier. + !fn: $checkedButton() + Returns the button group's checked button, or 0 if no buttons are checked. +*/ + +KVSO_BEGIN_REGISTERCLASS(KvsObject_buttonGroup,"buttongroup","object") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_buttonGroup,addButton) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_buttonGroup,checkedButton) +KVSO_END_REGISTERCLASS(KvsObject_buttonGroup) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_buttonGroup,KviKvsObject) + m_iId=0; + btnDict.setAutoDelete(false); + m_pButtonGroup=new QButtonGroup(); +KVSO_END_CONSTRUCTOR(KvsObject_buttonGroup) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_buttonGroup) +btnDict.clear(); +delete m_pButtonGroup; +KVSO_END_CONSTRUCTOR(KvsObject_buttonGroup) + + +KVSO_CLASS_FUNCTION(buttonGroup,addButton) +{ + CHECK_INTERNAL_POINTER(m_pButtonGroup) + KviKvsObject * pObject; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("button",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + CHECK_HOBJECT_IS_WIDGET(pObject) + if(pObject->inheritsClass("radiobutton") || pObject->inheritsClass("checkbox")) + { + m_pButtonGroup->addButton(((QRadioButton *)(pObject->object())),m_iId); + c->returnValue()->setInteger(m_iId); + btnDict.insert(m_iId,pObject); + m_iId++; + } + else + { + c->warning(__tr2qs_ctx("Buttongroup supports only checkbox and radiobox object","objects")); + return true; + } + return true; +} +KVSO_CLASS_FUNCTION(buttonGroup,checkedButton) +{ + CHECK_INTERNAL_POINTER(m_pButtonGroup) + int id=m_pButtonGroup->checkedId(); + if (id!=-1) c->returnValue()->setHObject(btnDict.find(id)->handle()); + else c->returnValue()->setNothing(); + return true; +} diff --git a/src/modules/objects/KvsObject_buttonGroup.h b/src/modules/objects/KvsObject_buttonGroup.h new file mode 100644 index 000000000..a7d44cc91 --- /dev/null +++ b/src/modules/objects/KvsObject_buttonGroup.h @@ -0,0 +1,46 @@ +#ifndef _CLASS_BUTTONGROUP_H_ +#define _CLASS_BUTTONGROUP_H_ +//============================================================================= +// +// File : KvsObject_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) 2009 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "object_macros.h" + +class KvsObject_buttonGroup : public KviKvsObject +{ +public: + KVSO_DECLARE_OBJECT(KvsObject_buttonGroup) +protected: + QButtonGroup *m_pButtonGroup; + int m_iId; + KviPointerHashTable btnDict; + bool addButton(KviKvsObjectFunctionCall *c); + bool checkedButton(KviKvsObjectFunctionCall *c); + +}; +#endif //!_CLASS_GROUPBOX_H_ + diff --git a/src/modules/objects/KvsObject_checkBox.cpp b/src/modules/objects/KvsObject_checkBox.cpp new file mode 100644 index 000000000..53f11fda7 --- /dev/null +++ b/src/modules/objects/KvsObject_checkBox.cpp @@ -0,0 +1,136 @@ +//============================================================================= +// +// File : KvsObject_checkBox.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) 2000 Krzysztof Godlewski +// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + + +#include "KviError.h" +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KvsObject_checkBox.h" + +#include + +/* + @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 . + See also [classfnc]$isChecked[/classfnc](). + !fn: $setText([]) + Sets the label text associated with the checkbox to .[br] + !fn: $toggleEvent() + Called by KVIrc when the checkbox state is toggled. + The default implementation emits the toggled() signal. +*/ + +//--------------------------------------------------------------------------------- + +KVSO_BEGIN_REGISTERCLASS(KvsObject_checkBox,"checkbox","button") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_checkBox,setChecked) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_checkBox,isChecked) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_checkBox,toggleEvent) +KVSO_END_REGISTERCLASS(KvsObject_checkBox) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_checkBox,KvsObject_button) + +KVSO_END_CONSTRUCTOR(KvsObject_checkBox) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_checkBox) + +KVSO_END_CONSTRUCTOR(KvsObject_checkBox) + +bool KvsObject_checkBox::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + QCheckBox * cb = new QCheckBox(parentScriptWidget()); + cb->setObjectName(getName().toUtf8().data()); + setObject(cb, true); + connect(cb,SIGNAL(toggled(bool)),this,SLOT(toggled(bool))); + connect(widget(),SIGNAL(clicked()),this,SLOT(slotClicked())); + return true; +} + +KVSO_CLASS_FUNCTION(checkBox,isChecked) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setBoolean(((QCheckBox *)widget())->isChecked()); + return true; +} + +KVSO_CLASS_FUNCTION(checkBox,setChecked) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bChecked; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bChecked",KVS_PT_BOOL,KVS_PF_OPTIONAL,bChecked) + KVSO_PARAMETERS_END(c) + ((QCheckBox *)widget())->setChecked(bChecked); + return true; +} + +KVSO_CLASS_FUNCTION(checkBox,setText) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + ((QCheckBox *)widget())->setText(szText); + return true; +} + +KVSO_CLASS_FUNCTION(checkBox,toggleEvent) +{ + emitSignal("toggled",c,c->params()); + return true; +} + +//slots +void KvsObject_checkBox::toggled(bool b) +{ + KviKvsVariantList params(new KviKvsVariant(b)); + callFunction(this,"toggleEvent",¶ms); +} + + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_checkBox.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES + diff --git a/src/modules/objects/KvsObject_checkBox.h b/src/modules/objects/KvsObject_checkBox.h new file mode 100644 index 000000000..a1cc15087 --- /dev/null +++ b/src/modules/objects/KvsObject_checkBox.h @@ -0,0 +1,50 @@ +#ifndef _CLASS_CHECKBOX_H_ +#define _CLASS_CHECKBOX_H_ + +//============================================================================= +// +// File : KvsObject_checkBox.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) 2000 Krzysztof Godlewski +// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + + + +#include "KvsObject_button.h" +#include "object_macros.h" + +class KvsObject_checkBox : public KvsObject_button +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_checkBox) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + bool setChecked(KviKvsObjectFunctionCall *c); + bool isChecked(KviKvsObjectFunctionCall *c); + bool toggleEvent(KviKvsObjectFunctionCall *c); + bool setText(KviKvsObjectFunctionCall *c); +protected slots: + void toggled(bool b); +}; +#endif // !_CLASS_CHECKBOX_H_ diff --git a/src/modules/objects/KvsObject_comboBox.cpp b/src/modules/objects/KvsObject_comboBox.cpp new file mode 100644 index 000000000..83dfc51ab --- /dev/null +++ b/src/modules/objects/KvsObject_comboBox.cpp @@ -0,0 +1,366 @@ +//============================================================================= +// +// File : KvsObject_comboBox.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) 2000 Krzysztof Godlewski +// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + + +#include "KviError.h" +#include "KviLocale.h" +#include "kvi_debug.h" +#include "KvsObject_list.h" +#include "KvsObject_comboBox.h" + +#include +#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(KvsObject_comboBox,"combobox","widget") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,insertItem) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,changeItem) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,removeItem) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,clear) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,setMaxCount) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,maxCount) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,count) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,current) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,currentItem) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,setEditable); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,editable) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,setEditText) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,textAt) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,textLineEdit) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,setTextLineEdit) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,setCurrentItem) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,popup) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,setInsertionPolicy) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,textChangedEvent) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_comboBox,activatedEvent) + +KVSO_END_REGISTERCLASS(KvsObject_comboBox) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_comboBox,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_comboBox) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_comboBox) + +KVSO_END_CONSTRUCTOR(KvsObject_comboBox) + +bool KvsObject_comboBox::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT(QComboBox); + connect (((QComboBox *)widget()),SIGNAL(activated( int )),this,SLOT(slotActivated( int ))); + connect (((QComboBox *)widget()),SIGNAL(editTextChanged(const QString & )),this,SLOT(editTextChanged(const QString & ))); + return true; +} + +KVSO_CLASS_FUNCTION(comboBox,insertItem) +{ + CHECK_INTERNAL_POINTER(widget()) + 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(c->paramCount()==1) + ((QComboBox *)widget())->addItem(szItem); + else + ((QComboBox *)widget())->insertItem( iIndex,szItem); + return true; +} +KVSO_CLASS_FUNCTION(comboBox,clear) +{ + CHECK_INTERNAL_POINTER(widget()) + ((QComboBox *)widget())->clear(); + return true; +} +KVSO_CLASS_FUNCTION(comboBox,changeItem) +{ + CHECK_INTERNAL_POINTER(widget()) + 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 (szText.isEmpty()) c->warning(__tr2qs_ctx("No string parameter given - using empty string","objects")); + if(uIndex >= (cnt = ((QComboBox *)widget())->count())) + { + c->warning(__tr2qs_ctx("Item index [%d] is too big - defaulting to " \ + "$count() - 1 [%d]","objects"), uIndex, cnt); + uIndex = cnt - 1; + } + ((QComboBox *)widget())->setItemText( uIndex,szText); + return true; + +} +KVSO_CLASS_FUNCTION(comboBox,removeItem) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uIndex,cnt; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + if(uIndex >= (cnt = ((QComboBox *)widget())->count())) + { + c->warning(__tr2qs_ctx("Item index [%d] is too big - defaulting to " \ + "$count() - 1 [%d]","objects"), uIndex, cnt); + uIndex = cnt - 1; + } + + ((QComboBox *)widget())->removeItem(uIndex); + + return true; + +} +KVSO_CLASS_FUNCTION(comboBox,setMaxCount) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t iMax; + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("count",KVS_PT_UNSIGNEDINTEGER,0,iMax) + KVSO_PARAMETERS_END(c) + ((QComboBox *)widget())->setMaxCount(iMax); + return true; +} +KVSO_CLASS_FUNCTION(comboBox,maxCount) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QComboBox *)widget())->maxCount()); + return true; +} +KVSO_CLASS_FUNCTION(comboBox,count) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QComboBox *)widget())->count()); + return true; +} +KVSO_CLASS_FUNCTION(comboBox,current) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setString(((QComboBox *)widget())->currentText()); + return true; +} +KVSO_CLASS_FUNCTION(comboBox,currentItem) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QComboBox *)widget())->currentIndex()); + return true; +} +KVSO_CLASS_FUNCTION(comboBox,textLineEdit) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setString(((QComboBox *)widget())->lineEdit()->text()); + return true; +} + +KVSO_CLASS_FUNCTION(comboBox,setEditable) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bflag",KVS_PT_BOOLEAN,0,bFlag) + KVSO_PARAMETERS_END(c) + ((QComboBox *)widget())->setEditable(bFlag); + return true; +} +KVSO_CLASS_FUNCTION(comboBox,setTextLineEdit) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + ((QComboBox *)widget())->lineEdit()->setText(szText); + return true; +} + +KVSO_CLASS_FUNCTION(comboBox,editable) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setBoolean(((QComboBox *)widget())->isEditable()); + return true; +} +KVSO_CLASS_FUNCTION(comboBox,setEditText) +{ + CHECK_INTERNAL_POINTER(widget()) + 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 (szText.isEmpty() && !bQuiet) c->warning(__tr2qs_ctx("No string parameter given - using empty string","objects")); + ((QComboBox *)widget())->setEditText(szText); + return true; +} +KVSO_CLASS_FUNCTION(comboBox,textAt) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + c->returnValue()->setString(((QComboBox *)widget())->itemText(uIndex)); + return true; +} +KVSO_CLASS_FUNCTION(comboBox,setCurrentItem) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + ((QComboBox *)widget())->setCurrentIndex(uIndex); + return true; +} +KVSO_CLASS_FUNCTION(comboBox,popup) +{ + Q_UNUSED(c); + + if(widget()) + ((QComboBox *)widget())->showPopup(); + return true; +} +KVSO_CLASS_FUNCTION(comboBox,setInsertionPolicy) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szPolicy; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("policy",KVS_PT_STRING,0,szPolicy) + KVSO_PARAMETERS_END(c) + if(KviQString::equalCI(szPolicy,"NoInsertion")) + ((QComboBox *)widget())->setInsertPolicy(QComboBox::NoInsert); + else if(KviQString::equalCI(szPolicy,"AtTop")) + ((QComboBox *)widget())->setInsertPolicy(QComboBox::InsertAtTop); + else if(KviQString::equalCI(szPolicy,"AtBotton")) + ((QComboBox *)widget())->setInsertPolicy(QComboBox::InsertAtBottom); + else if(KviQString::equalCI(szPolicy,"AtCurrent")) + ((QComboBox *)widget())->setInsertPolicy(QComboBox::InsertAtCurrent); + else if(KviQString::equalCI(szPolicy,"AfterCurrent")) + ((QComboBox *)widget())->setInsertPolicy(QComboBox::InsertAfterCurrent); + else if(KviQString::equalCI(szPolicy,"BeforeCurrent")) + ((QComboBox *)widget())->setInsertPolicy(QComboBox::InsertBeforeCurrent); + else c->warning(__tr2qs_ctx("Invalid insertion Policy '%Q'","objects"),&szPolicy); + return true; +} + +KVSO_CLASS_FUNCTION(comboBox,textChangedEvent) +{ + emitSignal("textChanged",c,c->params()); + return true; +} + + + +KVSO_CLASS_FUNCTION(comboBox,activatedEvent) +{ + emitSignal("activated",c,c->params()); + return true; +} + +//slots +void KvsObject_comboBox::editTextChanged(const QString &text) +{ + KviKvsVariantList params(new KviKvsVariant(text)); + callFunction(this,"textChangedEvent",¶ms); +} + +void KvsObject_comboBox::slotActivated(int i) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)i)); + callFunction(this,"activatedEvent",¶ms); +} + + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_comboBox.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES + diff --git a/src/modules/objects/KvsObject_comboBox.h b/src/modules/objects/KvsObject_comboBox.h new file mode 100644 index 000000000..a10ac6c29 --- /dev/null +++ b/src/modules/objects/KvsObject_comboBox.h @@ -0,0 +1,74 @@ +#ifndef _CLASS_COMBOBOX_H_ +#define _CLASS_COMBOBOX_H_ + +//============================================================================= +// +// File : KvsObject_comboBox.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) 2000 Krzysztof Godlewski +// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + + +#include +#include "KvsObject_widget.h" +#include "object_macros.h" + +class KvsObject_comboBox : public KvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_comboBox) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool insertItem(KviKvsObjectFunctionCall *c); + bool changeItem(KviKvsObjectFunctionCall *c); + bool removeItem(KviKvsObjectFunctionCall *c); + bool clear(KviKvsObjectFunctionCall *c); +//#warning "$insertPixItem" +//#warning "$changePixItem" + + bool count(KviKvsObjectFunctionCall *c); + bool setMaxCount(KviKvsObjectFunctionCall *c); + bool maxCount(KviKvsObjectFunctionCall *c); + bool current(KviKvsObjectFunctionCall *c); + bool currentItem(KviKvsObjectFunctionCall *c); + bool setEditable(KviKvsObjectFunctionCall *c); + bool editable(KviKvsObjectFunctionCall *c); + bool setEditText(KviKvsObjectFunctionCall *c); + bool textAt(KviKvsObjectFunctionCall *c); + bool textLineEdit(KviKvsObjectFunctionCall *c); + bool setTextLineEdit(KviKvsObjectFunctionCall *c); + + bool setInsertionPolicy(KviKvsObjectFunctionCall *c); + + bool setCurrentItem(KviKvsObjectFunctionCall *c); + bool popup(KviKvsObjectFunctionCall *c); + bool textChangedEvent(KviKvsObjectFunctionCall *c); + bool activatedEvent(KviKvsObjectFunctionCall *c); +protected slots: + void editTextChanged(const QString &); + void slotActivated(int); +}; + +#endif // !_CLASS_COMBOBOX_H_ diff --git a/src/modules/objects/KvsObject_dateTimeEdit.cpp b/src/modules/objects/KvsObject_dateTimeEdit.cpp new file mode 100644 index 000000000..e992d69d7 --- /dev/null +++ b/src/modules/objects/KvsObject_dateTimeEdit.cpp @@ -0,0 +1,162 @@ +//============================================================================= +// +// File : KvsObject_dateTimeEdit.cpp +// Creation date : Wed 30 Gen 2009 09:30:05 CEST by Carbone Alessandro +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2009 Carbone Alessandro (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KviLocale.h" +#include "KviError.h" +#include "KviIconManager.h" +#include "KviFile.h" + +#include "KvsObject_dateTimeEdit.h" +#include "KvsObject_pixmap.h" + + #include + +/* + @doc:datetimeedit + @title: + datetimeedit class + @type: + class + @short: + Datetimeedit widget. + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + This widget provides a datetimeedit. + @functions: + !fn: $setDate(,) + Sets the date of the widget using the format . Possible values for format are: + d the day as number without a leading zero (1 to 31) + dd the day as number with a leading zero (01 to 31) + ddd the abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses QDate::shortDayName(). + dddd the long localized day name (e.g. 'Monday' to 'Qt::Sunday'). Uses QDate::longDayName(). + M the month as number without a leading zero (1-12) + MM the month as number with a leading zero (01-12) + MMM the abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses QDate::shortMonthName(). + MMMM the long localized month name (e.g. 'January' to 'December'). Uses QDate::longMonthName(). + yy the year as two digit number (00-99) + yyyy the year as four digit number + !fn: $date() + Returns the widget date according to format. + !fn: $setTime(,) + Sets the date of the widget using the format . Possibile values for format are: + h the hour without a leading zero + hh the hour with a leading zero + m the minute without a leading zero + mm the minute with a leading zero + s the second without a leading zero + ss the second with a leading zero + z the milliseconds without leading zeroes + zzz the milliseconds with leading zeroes + AP(or ap) use AM/PM display. AP will be replaced by either "AM" or "PM". + !fn: $time() + Returns the widget time according to format. +*/ + + +KVSO_BEGIN_REGISTERCLASS(KvsObject_dateTimeEdit,"datetimeedit","widget") + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_dateTimeEdit,date) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_dateTimeEdit,setDate) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_dateTimeEdit,setTime) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_dateTimeEdit,time) + +KVSO_END_REGISTERCLASS(KvsObject_dateTimeEdit) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_dateTimeEdit,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_dateTimeEdit) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_dateTimeEdit) + +KVSO_END_DESTRUCTOR(KvsObject_dateTimeEdit) + +bool KvsObject_dateTimeEdit::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + QDateTimeEdit *obj=new QDateTimeEdit(QDate::currentDate(),parentScriptWidget()); + obj->setObjectName(getName()); + setObject(obj,true); + return true; +} + +KVSO_CLASS_FUNCTION(dateTimeEdit,date) +{ + + CHECK_INTERNAL_POINTER(widget()) + QString szFormat; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("format",KVS_PT_STRING,0,szFormat) + KVSO_PARAMETERS_END(c) + + c->returnValue()->setString(((QDateTimeEdit *)widget())->date().toString(szFormat)); + + return true; +} +KVSO_CLASS_FUNCTION(dateTimeEdit,setDate) +{ + + CHECK_INTERNAL_POINTER(widget()) + QString szFormat,szDate; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("format",KVS_PT_STRING,0,szFormat) + KVSO_PARAMETER("date",KVS_PT_STRING,0,szDate) + KVSO_PARAMETERS_END(c) + QDate date; + date=date.fromString(szDate,szFormat); + ((QDateTimeEdit *)widget())->setDate(date); + return true; +} +KVSO_CLASS_FUNCTION(dateTimeEdit,time) +{ + + CHECK_INTERNAL_POINTER(widget()) + QString szFormat; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("format",KVS_PT_STRING,0,szFormat) + KVSO_PARAMETERS_END(c) + + c->returnValue()->setString(((QDateTimeEdit *)widget())->time().toString(szFormat)); + + return true; +} +KVSO_CLASS_FUNCTION(dateTimeEdit,setTime) +{ + + CHECK_INTERNAL_POINTER(widget()) + QString szFormat,szTime; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("format",KVS_PT_STRING,0,szFormat) + KVSO_PARAMETER("date",KVS_PT_STRING,0,szTime) + KVSO_PARAMETERS_END(c) + QTime time; + time=time.fromString(szTime,szFormat); + ((QDateTimeEdit *)widget())->setTime(time); + return true; +} +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_dateTimeEdit.moc" +#endif //COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/KvsObject_dateTimeEdit.h b/src/modules/objects/KvsObject_dateTimeEdit.h new file mode 100644 index 000000000..fc2963a8f --- /dev/null +++ b/src/modules/objects/KvsObject_dateTimeEdit.h @@ -0,0 +1,56 @@ +#ifndef _CLASS_datetimeedit_H_ +#define _CLASS_datetimeedit_H_ +//============================================================================= +// +// File : KvsObject_dateTimeEdit.h +// Creation date : Wed 30 Gen 2009 09:30:05 CEST by Carbone Alessandro +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2009 Carbone Alessandro (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_widget.h" +#include "object_macros.h" + +class KvsObject_dateTimeEdit : public KvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_dateTimeEdit) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool date(KviKvsObjectFunctionCall *c); + bool setDate(KviKvsObjectFunctionCall *c); + bool time(KviKvsObjectFunctionCall *c); + bool setTime(KviKvsObjectFunctionCall *c); + + /* bool text(KviKvsObjectFunctionCall *c); + + bool setImage(KviKvsObjectFunctionCall *c); + bool clickEvent(KviKvsObjectFunctionCall *c); +*/ +protected slots: + //void slotClicked(); +}; + +#endif // !_CLASS_datetimeedit_H_ diff --git a/src/modules/objects/KvsObject_dialog.cpp b/src/modules/objects/KvsObject_dialog.cpp new file mode 100644 index 000000000..85835cac0 --- /dev/null +++ b/src/modules/objects/KvsObject_dialog.cpp @@ -0,0 +1,91 @@ +//============================================================================= +// +// File : KvsObject_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) 2002-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "KvsObject_dialog.h" +#include "KviError.h" +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KviMainWindow.h" +#include "KviApplication.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 windowlist entry. + !fn; setModal () + 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(KvsObject_dialog,"dialog","widget") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_dialog,setModal) +KVSO_END_REGISTERCLASS(KvsObject_dialog) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_dialog,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_dialog) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_dialog) + +KVSO_END_CONSTRUCTOR(KvsObject_dialog) + +bool KvsObject_dialog::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + QWidget * w = g_pApp->activeModalWidget(); + if(!w)w = g_pFrame; + QDialog * d = new QDialog(parentScriptWidget() ? parentScriptWidget() : w); + d->setObjectName(getName()); + //d->setModal(true); + setObject(d); + return true; +} +KVSO_CLASS_FUNCTION(dialog,setModal) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + ((QDialog *)widget())->setModal(bEnabled); + return true; +} + + diff --git a/src/modules/objects/KvsObject_dialog.h b/src/modules/objects/KvsObject_dialog.h new file mode 100644 index 000000000..602de8756 --- /dev/null +++ b/src/modules/objects/KvsObject_dialog.h @@ -0,0 +1,43 @@ +#ifndef _CLASS_DIALOG_H_ +#define _CLASS_DIALOG_H_ +//============================================================================= +// +// File : KvsObject_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) 2002-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "KvsObject_widget.h" +#include "object_macros.h" + +class KvsObject_dialog : public KvsObject_widget +{ + +public: + KVSO_DECLARE_OBJECT(KvsObject_dialog) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + bool setModal(KviKvsObjectFunctionCall *c); +}; + +#endif // !_CLASS_DIALOG_H_ + diff --git a/src/modules/objects/KvsObject_dockWindow.cpp b/src/modules/objects/KvsObject_dockWindow.cpp new file mode 100644 index 000000000..8a9eb15a7 --- /dev/null +++ b/src/modules/objects/KvsObject_dockWindow.cpp @@ -0,0 +1,181 @@ +//============================================================================= +// +// File : KvsObject_dockWindow.cpp +// Creation date : Thu 29 Dec 2005 23:45:11 by Szymon Stefanek +// +// This file is part of the KVIrc IRC Client distribution +// Copyright (C) 2005-2010 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 "KvsObject_dockWindow.h" + +#include "KviMainWindow.h" +#include "KviLocale.h" +#include "KviQString.h" + +#include +#define QT_DOCK_WINDOW QDockWidget +#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). + @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: $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(KvsObject_dockWindow,"dockwindow","widget") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_dockWindow,addWidget) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_dockWindow,setAllowedDockAreas) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_dockWindow,dock) +KVSO_END_REGISTERCLASS(KvsObject_dockWindow) + + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_dockWindow,KvsObject_widget) +KVSO_END_CONSTRUCTOR(KvsObject_dockWindow) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_dockWindow) +KVSO_END_DESTRUCTOR(KvsObject_dockWindow) + +#define _pDockWindow ((QDockWidget *)widget()) + +bool KvsObject_dockWindow::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + QDockWidget * pWidget = new QDockWidget(g_pFrame); + pWidget->setObjectName(getName()); + setObject(pWidget); + return true; +} + +KVSO_CLASS_FUNCTION(dockWindow,addWidget) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_hobject_t hWidget; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hWidget) + KVSO_PARAMETERS_END(c) + if(hWidget == (kvs_hobject_t)0) + { + // null widget ? + c->warning(__tr2qs_ctx("Can't add a null object","objects")); + return true; + } + + KviKvsObject * pWidget = KviKvsKernel::instance()->objectController()->lookupObject(hWidget); + if(!pWidget) + { + c->warning(__tr2qs_ctx("Invalid object handle passed as parameter (the object is no longer existing ?)","objects")); + return true; + } + + if(!pWidget->object()) + { + c->warning(__tr2qs_ctx("Object in invalid state","objects")); + return true; + } + + if(!pWidget->object()->isWidgetType()) + { + c->warning(__tr2qs_ctx("Can't set a non-widget object to be the main widget of a dock window","objects")); + return true; + } + + if(((QWidget *)(pWidget->object()))->parent() != (QObject *)_pDockWindow) + { + c->warning(__tr2qs_ctx("The added widget is not a child of this dock window","objects")); + } + + _pDockWindow->setWidget((QWidget *)(pWidget->object())); + return true; +} + + +KVSO_CLASS_FUNCTION(dockWindow,setAllowedDockAreas) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szFlags; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("docks",KVS_PT_STRING,0,szFlags) + KVSO_PARAMETERS_END(c) + Qt::DockWidgetAreas fAreas = Qt::NoDockWidgetArea; + if(szFlags.indexOf('t',Qt::CaseInsensitive) >= 0) + fAreas |= Qt::TopDockWidgetArea; + if(szFlags.indexOf('l',Qt::CaseInsensitive) >= 0) + fAreas |= Qt::LeftDockWidgetArea; + if(szFlags.indexOf('r',Qt::CaseInsensitive) >= 0) + fAreas |= Qt::RightDockWidgetArea; + if(szFlags.indexOf('b',Qt::CaseInsensitive) >= 0) + fAreas |= Qt::BottomDockWidgetArea; + _pDockWindow->setAllowedAreas(fAreas); + QDockWidget::DockWidgetFeatures fFeatures = _pDockWindow->features(); + if(szFlags.indexOf('f',Qt::CaseInsensitive)) + fFeatures |= QDockWidget::DockWidgetFloatable; + else + fFeatures &= ~QDockWidget::DockWidgetFloatable; + // no support for minimized dock widgets + _pDockWindow->setFeatures(fFeatures); + + + return true; +} + + +KVSO_CLASS_FUNCTION(dockWindow,dock) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szDock; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("dock",KVS_PT_STRING,0,szDock) + KVSO_PARAMETERS_END(c) + g_pFrame->removeDockWidget(_pDockWindow); + if(szDock.indexOf('m',Qt::CaseInsensitive) == -1)_pDockWindow->setFloating(false); + if(szDock.indexOf('t',Qt::CaseInsensitive) != -1)g_pFrame->addDockWidget(Qt::TopDockWidgetArea,_pDockWindow); + else if(szDock.indexOf('l',Qt::CaseInsensitive) != -1)g_pFrame->addDockWidget(Qt::LeftDockWidgetArea,_pDockWindow); + else if(szDock.indexOf('r',Qt::CaseInsensitive) != -1)g_pFrame->addDockWidget(Qt::RightDockWidgetArea,_pDockWindow); + else if(szDock.indexOf('b',Qt::CaseInsensitive) != -1)g_pFrame->addDockWidget(Qt::BottomDockWidgetArea,_pDockWindow); + else if(szDock.indexOf('f',Qt::CaseInsensitive) != -1)_pDockWindow->setFloating(true); + else if(szDock.indexOf('m',Qt::CaseInsensitive) != -1)qDebug("Sorry: no support for minimized dock widgets in Qt4"); + else c->warning(__tr2qs_ctx("Invalid dock area specified","objects")); + return true; +} + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_dockWindow.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES + diff --git a/src/modules/objects/KvsObject_dockWindow.h b/src/modules/objects/KvsObject_dockWindow.h new file mode 100644 index 000000000..df6a4a6e1 --- /dev/null +++ b/src/modules/objects/KvsObject_dockWindow.h @@ -0,0 +1,44 @@ +#ifndef _CLASS_DOCKWINDOW_H_ +#define _CLASS_DOCKWINDOW_H_ +//============================================================================= +// +// File : KvsObject_dockWindow.h +// Creation date : Thu 29 Dec 2005 23:45:11 by Szymon Stefanek +// +// This file is part of the KVIrc IRC Client distribution +// Copyright (C) 2005-2010 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 "KvsObject_widget.h" + +class KvsObject_dockWindow : public KvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_dockWindow) +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool addWidget(KviKvsObjectFunctionCall *c); + bool setAllowedDockAreas(KviKvsObjectFunctionCall * c); + bool dock(KviKvsObjectFunctionCall * c); +}; + +#endif //!_CLASS_DOCKWINDOW_H_ diff --git a/src/modules/objects/KvsObject_file.cpp b/src/modules/objects/KvsObject_file.cpp new file mode 100644 index 000000000..909b1c552 --- /dev/null +++ b/src/modules/objects/KvsObject_file.cpp @@ -0,0 +1,648 @@ +//============================================================================= +// +// File : KvsObject_file.cpp +// Creation date : Fri Mar 18 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) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + + +#include "KvsObject_file.h" +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KviError.h" +#include "KviFile.h" +#include "KviFileUtils.h" +#include "KvsObject_memoryBuffer.h" + +#include +//#include +#include + +#define CHECK_FILE_IS_OPEN if (!m_pFile->isOpen())\ + {c->warning(__tr2qs_ctx("File is not open!","objects"));return true;} + +// needed for $open() + +const char * const mod_tbl[] = { + "Raw", + "ReadOnly", + "WriteOnly", + "ReadWrite", + "Append", + "Truncate" +}; + +const QIODevice::OpenMode mod_cod[] = { + QIODevice::Unbuffered, + QIODevice::ReadOnly, + QIODevice::WriteOnly, + QIODevice::ReadWrite, + QIODevice::Append, + QIODevice::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() +*/ + + +KVSO_BEGIN_REGISTERCLASS(KvsObject_file,"file","object") + KVSO_REGISTER_HANDLER(KvsObject_file,"setName",setName) + KVSO_REGISTER_HANDLER(KvsObject_file,"name",name) + + KVSO_REGISTER_HANDLER(KvsObject_file,"open",open) + KVSO_REGISTER_HANDLER(KvsObject_file,"isOpen",isOpen) + KVSO_REGISTER_HANDLER(KvsObject_file,"close",close) + KVSO_REGISTER_HANDLER(KvsObject_file,"flush",flush) + + KVSO_REGISTER_HANDLER(KvsObject_file,"size",size) + KVSO_REGISTER_HANDLER(KvsObject_file,"resize",resize) + + KVSO_REGISTER_HANDLER(KvsObject_file,"atEnd",atEnd) + KVSO_REGISTER_HANDLER(KvsObject_file,"where",where) + KVSO_REGISTER_HANDLER(KvsObject_file,"seek",seek) + + KVSO_REGISTER_HANDLER(KvsObject_file,"putch",putch) + KVSO_REGISTER_HANDLER(KvsObject_file,"getch",getch) + KVSO_REGISTER_HANDLER(KvsObject_file,"ungetch",unGetch) + KVSO_REGISTER_HANDLER(KvsObject_file,"readByte",readByte) + + KVSO_REGISTER_HANDLER(KvsObject_file,"readBlock",readBlock) + KVSO_REGISTER_HANDLER(KvsObject_file,"writeBlock", writeBlock) + + KVSO_REGISTER_HANDLER(KvsObject_file,"readHexBlock",readHexBlock) + KVSO_REGISTER_HANDLER(KvsObject_file,"writeHexBlock",writeHexBlock) + + KVSO_REGISTER_HANDLER(KvsObject_file,"readLine",readLine) + KVSO_REGISTER_HANDLER(KvsObject_file,"writeLine",writeLine) + + KVSO_REGISTER_HANDLER(KvsObject_file,"write",write) + KVSO_REGISTER_HANDLER(KvsObject_file,"read",read) + + +KVSO_END_REGISTERCLASS(KvsObject_file) + + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_file,KvsObject_widget) + m_pFile = new KviFile(); + +KVSO_END_CONSTRUCTOR(KvsObject_file) + +KVSO_BEGIN_DESTRUCTOR(KvsObject_file) + + if (m_pFile) delete m_pFile; + +KVSO_END_CONSTRUCTOR(KvsObject_file) + +KVSO_CLASS_FUNCTION(file,setName) +{ + CHECK_INTERNAL_POINTER(m_pFile) + QString szName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("file_name",KVS_PT_STRING,0,szName) + KVSO_PARAMETERS_END(c) + m_pFile->setFileName(szName); + return true; +} + +KVSO_CLASS_FUNCTION(file,name) +{ + CHECK_INTERNAL_POINTER(m_pFile) + c->returnValue()->setString(m_pFile->fileName()); + return true; +} + +KVSO_CLASS_FUNCTION(file,open) +{ + CHECK_INTERNAL_POINTER(m_pFile) + QStringList modes; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("file_mode",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,modes) + KVSO_PARAMETERS_END(c) + + if(m_pFile->fileName().isEmpty()) + { + c->warning(__tr2qs_ctx("Empty filename string","objects")); + return true; + } + QIODevice::OpenMode mod,sum; + if (modes.empty()) sum = QIODevice::ReadWrite|QIODevice::Append; // if no parameters given, default to ReadWrite | Append + else + { + for ( int idx=0;idxwarning(__tr2qs_ctx("No such open mode '%Q'","objects"),&modes.at(idx)); + } + } + c->returnValue()->setBoolean(m_pFile->open(sum)); + return true; +} + +KVSO_CLASS_FUNCTION(file,isOpen) +{ + CHECK_INTERNAL_POINTER(m_pFile) + c->returnValue()->setBoolean(m_pFile->isOpen()); + return true; +} + +KVSO_CLASS_FUNCTION(file,close) +{ + CHECK_INTERNAL_POINTER(m_pFile) + CHECK_FILE_IS_OPEN + m_pFile->close(); + return true; +} + +KVSO_CLASS_FUNCTION(file,flush) +{ + CHECK_INTERNAL_POINTER(m_pFile) + CHECK_FILE_IS_OPEN + m_pFile->flush(); + return true; +} + +KVSO_CLASS_FUNCTION(file,size) +{ + CHECK_INTERNAL_POINTER(m_pFile) + c->returnValue()->setInteger((kvs_int_t)(m_pFile->size())); + return true; +} + +KVSO_CLASS_FUNCTION(file,atEnd) +{ + CHECK_INTERNAL_POINTER(m_pFile) + c->returnValue()->setInteger((kvs_int_t)(m_pFile->atEnd())); + return true; +} + +KVSO_CLASS_FUNCTION(file,where) +{ + CHECK_INTERNAL_POINTER(m_pFile) + CHECK_FILE_IS_OPEN + c->returnValue()->setInteger((kvs_int_t)(m_pFile->pos())); + return true; +} + +KVSO_CLASS_FUNCTION(file,seek) +{ + CHECK_INTERNAL_POINTER(m_pFile) + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + CHECK_FILE_IS_OPEN + m_pFile->seek(uIndex); + return true; +} + + +KVSO_CLASS_FUNCTION(file,resize) +{ + CHECK_INTERNAL_POINTER(m_pFile) + kvs_int_t iSize; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("size",KVS_PT_INTEGER,0,iSize) + KVSO_PARAMETERS_END(c) + CHECK_FILE_IS_OPEN + m_pFile->resize(iSize); + return true; +} + +KVSO_CLASS_FUNCTION(file,putch) +{ + CHECK_INTERNAL_POINTER(m_pFile) + QString szChar; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("char",KVS_PT_STRING,0,szChar) + KVSO_PARAMETERS_END(c) + if (szChar.length()>1)c->warning(__tr2qs_ctx("Argument too long, using only first char","objects")); + const char *ch=szChar.toUtf8().data(); + if (!m_pFile->putChar(ch[0])) c->warning(__tr2qs_ctx("Write error occured!","objects")); + return true; +} + +KVSO_CLASS_FUNCTION(file,getch) +{ + CHECK_INTERNAL_POINTER(m_pFile) + CHECK_FILE_IS_OPEN + char ch; + if (!m_pFile->getChar(&ch)) c->warning(__tr2qs_ctx("Read error occured!","objects")); // c->error ? + QString szChar = QChar(ch); + c->returnValue()->setString(szChar); + return true; +} + +KVSO_CLASS_FUNCTION(file,readByte) +{ + CHECK_INTERNAL_POINTER(m_pFile) + CHECK_FILE_IS_OPEN + char ch; + if (!m_pFile->getChar(&ch)) c->warning(__tr2qs_ctx("Read error occured!","objects")); // c->error ? + //QString szChar = QChar(ch); + c->returnValue()->setInteger((kvs_int_t) ch); + return true; +} + +KVSO_CLASS_FUNCTION(file,unGetch) +{ + CHECK_INTERNAL_POINTER(m_pFile) + CHECK_FILE_IS_OPEN + QString szChar; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("char",KVS_PT_STRING,0,szChar) + KVSO_PARAMETERS_END(c) + if (szChar.length()>1) c->warning(__tr2qs_ctx("Argument too long, using only the first char","objects")); + const char *ch=szChar.toUtf8().data(); + m_pFile->ungetChar(ch[0]); + return true; +} + +KVSO_CLASS_FUNCTION(file,readBlock) +{ + CHECK_INTERNAL_POINTER(m_pFile) + CHECK_FILE_IS_OPEN + kvs_uint_t uLen; + KviKvsObject * pObject; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("length",KVS_PT_UNSIGNEDINTEGER,0,uLen) + KVSO_PARAMETER("hobject",KVS_PT_HOBJECT,KVS_PF_OPTIONAL,hObject) + KVSO_PARAMETERS_END(c) + if (uLen>(kvs_uint_t)m_pFile->size()) uLen=m_pFile->size(); + if (hObject) + { + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!pObject) + { + c->warning(__tr2qs_ctx("Buffer parameter is not an object","objects")); + return true; + } + if (!pObject->inheritsClass("memorybuffer")) + { + c->warning(__tr2qs_ctx("Buffer parameter is not a memorybuffer object","objects")); + return true; + } + //m_pFile->flush(); + ((KvsObject_memoryBuffer *)pObject)->pBuffer()->append(m_pFile->read(uLen)); + return true; + } + else + { + char * buff = new char[uLen + 1]; + //m_pFile->flush(); // advice from QFile man page (to avoid trash) + int rlen = m_pFile->read(buff, uLen); + buff[rlen] = '\0'; + QString szBlock(buff); + c->returnValue()->setString(szBlock); + } + return true; +} + +KVSO_CLASS_FUNCTION(file,read) +{ + CHECK_INTERNAL_POINTER(m_pFile) + CHECK_FILE_IS_OPEN + QString szType; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("type",KVS_PT_STRING,0,szType) + KVSO_PARAMETERS_END(c) + if(KviQString::equalCI(szType, "String")) + { + QString szStr; + m_pFile->load(szStr); + c->returnValue()->setString(szStr); + } + else if(KviQString::equalCI(szType, "Integer")) + { + int iValue; + m_pFile->load(iValue); + c->returnValue()->setInteger(iValue); + } + else if(KviQString::equalCI(szType, "Array")) + { + QString szData; + m_pFile->load(szData); + KviKvsVariant *pVar = KviKvsVariant::unserialize(szData); + if (pVar->isArray()) + c->returnValue()->setArray(pVar->array()); + else + c->warning(__tr2qs_ctx("The incoming data isn't an array","objects")); + } + else if(KviQString::equalCI(szType, "Dict")) + { + QString szData; + m_pFile->load(szData); + KviKvsVariant *pVar = KviKvsVariant::unserialize(szData); + if (pVar->isHash()) + c->returnValue()->setHash(pVar->hash()); + else + c->warning(__tr2qs_ctx("The incoming data isn't a Dictionary","objects")); + } + else if(KviQString::equalCI(szType, "String")) + { + QString szStr; + m_pFile->load(szStr); + c->returnValue()->setString(szStr); + } + else + { + c->warning(__tr2qs_ctx("Unsupported datatype '%Q'","objects"),&szType); + } + return true; +} + +KVSO_CLASS_FUNCTION(file,write) +{ + CHECK_INTERNAL_POINTER(m_pFile) + CHECK_FILE_IS_OPEN + KviKvsVariant * pVariantData; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("variant_data",KVS_PT_VARIANT,0,pVariantData) + KVSO_PARAMETERS_END(c) + if (pVariantData->isInteger()) + { + kvs_int_t num; + pVariantData->asInteger(num); + m_pFile->save(num); + } + if (pVariantData->isHash() || pVariantData->isArray() || pVariantData->isString()) + { + QString szTmp; + pVariantData->serialize(szTmp); + m_pFile->save(szTmp); + } + return true; +} + +KVSO_CLASS_FUNCTION(file,writeBlock) +{ + CHECK_INTERNAL_POINTER(m_pFile) + kvs_uint_t uLen; + KviKvsObject * pObject; + KviKvsVariant * pVariantData; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("string_or_hobject",KVS_PT_VARIANT,0,pVariantData) + KVSO_PARAMETER("length",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,uLen) + KVSO_PARAMETERS_END(c) + if(!m_pFile->isOpen())c->warning(__tr2qs_ctx("File is not open!","objects")); + else + { + if (pVariantData->isHObject()) + { + pVariantData->asHObject(hObject); + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!pObject) + { + c->warning(__tr2qs_ctx("Buffer parameter is not an object","objects")); + return true; + } + if (pObject->inheritsClass("memorybuffer")) + { + if (!uLen) + { + if (((KvsObject_memoryBuffer *)pObject)->pBuffer()->size()) + uLen=((KvsObject_memoryBuffer *)pObject)->pBuffer()->size(); + else + { + c->warning(__tr2qs_ctx("The memoryBuffer object is empty: nothing will be saved","objects")); + } + } + const char *pData=((KvsObject_memoryBuffer *)pObject)->pBuffer()->data(); + int rlen=m_pFile->write(pData,uLen); + c->returnValue()->setInteger(rlen); + //m_pFile->flush(); + } else { + c->warning(__tr2qs_ctx("Buffer parameter is not a memorybuffer object","objects")); + return true; + } + + } + else + { + if (!pVariantData->isString()){ + c->warning(__tr2qs_ctx("Block parameter must be a string or a memorybuffer object","objects")); + return true; + } + QString szBlock; + pVariantData->asString(szBlock); + const char *block=szBlock.toUtf8().data(); + int rlen = m_pFile->write(block, uLen); + c->returnValue()->setInteger(rlen); + //m_pFile->flush(); + } + } + return true; +} + +KVSO_CLASS_FUNCTION(file,readLine) +{ + CHECK_INTERNAL_POINTER(m_pFile) + CHECK_FILE_IS_OPEN + QString buffer; + //bool ok=KviFileUtils::readLine(m_pFile,buffer); + buffer=m_pFile->readLine(); + c->returnValue()->setString(buffer); + return true; +} + +KVSO_CLASS_FUNCTION(file,writeLine) +{ + CHECK_INTERNAL_POINTER(m_pFile) + CHECK_FILE_IS_OPEN + QString szLine; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text_line",KVS_PT_STRING,0,szLine) + KVSO_PARAMETERS_END(c) + QTextStream ts(m_pFile); + ts << szLine; + return true; +} + +KVSO_CLASS_FUNCTION(file,readHexBlock) +{ + CHECK_INTERNAL_POINTER(m_pFile) + CHECK_FILE_IS_OPEN + kvs_uint_t uLen; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("lenght",KVS_PT_UNSIGNEDINTEGER,0,uLen) + KVSO_PARAMETERS_END(c) + if (uLen>(kvs_uint_t)m_pFile->size()) uLen=m_pFile->size(); + char * buff = new char[uLen]; + char * str = new char [(uLen*2)+1]; + m_pFile->flush(); // advice from QFile man page (to avoid trash) + int rlen = m_pFile->read(buff, uLen); + int index=0; + unsigned char byte,msb,lsb=0; + for (int i=0;i>4; + msb>9?msb+='7':msb+='0'; + lsb>9?lsb+='7':lsb+='0'; + str[index++]=msb; + str[index++]=lsb; + } + str[index]='\0'; + c->returnValue()->setString(str); + delete[] str; + delete[] buff; + return true; +} + +KVSO_CLASS_FUNCTION(file,writeHexBlock) +{ + CHECK_INTERNAL_POINTER(m_pFile) + CHECK_FILE_IS_OPEN + QString szBlock; + kvs_uint_t uLen; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text_block",KVS_PT_STRING,0,szBlock) + KVSO_PARAMETER("lenght",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,uLen) + KVSO_PARAMETERS_END(c) + if (szBlock.length()%2) + { + c->warning(__tr2qs_ctx("Length of hex string is not multiple of 2","objects")); + return true; + } + if (uLen>((uint)szBlock.length()/2)|| !uLen) uLen=szBlock.length(); + else uLen*=2; + unsigned char byte,lsb,msb; + for(unsigned int i=0;i='A' && msb<='F')||(msb>='0' && msb<='9')) && ((lsb>='A' && lsb<='F')|| (lsb>='0' && lsb<='9'))) + { + msb>='A'?msb-='7':msb-='0'; + lsb>='A'?lsb-='7':lsb-='0'; + } else{ + c->warning(__tr2qs_ctx("The hex string is not correct!","objects")); + return true; + } + byte=(msb*16)+lsb; + m_pFile->putChar(byte); + } + c->returnValue()->setInteger(uLen/2); + return true; +} diff --git a/src/modules/objects/KvsObject_file.h b/src/modules/objects/KvsObject_file.h new file mode 100644 index 000000000..b226c10b0 --- /dev/null +++ b/src/modules/objects/KvsObject_file.h @@ -0,0 +1,74 @@ +#ifndef _CLASS_FILE_H_ +#define _CLASS_FILE_H_ +//============================================================================= +// +// File : KvsObject_memoryBuffer.h +// Creation date : Fri Mar 18 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) 2005-2009 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "object_macros.h" +#include "KvsObject_widget.h" +#include "KviFile.h" + + +class KvsObject_file : public KvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KvsObject_file) +protected: + KviFile * m_pFile; +public: + + KviFile * file(){ return m_pFile; }; + bool setName(KviKvsObjectFunctionCall *c); + bool name(KviKvsObjectFunctionCall *c); + bool open(KviKvsObjectFunctionCall *c); + bool isOpen(KviKvsObjectFunctionCall *c); + bool close(KviKvsObjectFunctionCall *c); + bool flush(KviKvsObjectFunctionCall *c); + bool size(KviKvsObjectFunctionCall *c); + bool resize(KviKvsObjectFunctionCall *c); + + bool atEnd(KviKvsObjectFunctionCall *c); + // int QFile at() const + bool where(KviKvsObjectFunctionCall *c); + // void QFile at(int) + bool seek(KviKvsObjectFunctionCall *c); + bool putch(KviKvsObjectFunctionCall *c); + bool getch(KviKvsObjectFunctionCall *c); + bool readByte(KviKvsObjectFunctionCall *c); + bool unGetch(KviKvsObjectFunctionCall *c); + + bool readBlock(KviKvsObjectFunctionCall *c); + bool writeBlock(KviKvsObjectFunctionCall *c); + + bool readLine(KviKvsObjectFunctionCall *c); + bool writeLine(KviKvsObjectFunctionCall *c); + + bool readHexBlock(KviKvsObjectFunctionCall *c); + bool writeHexBlock(KviKvsObjectFunctionCall *c); + + bool write(KviKvsObjectFunctionCall *c); + bool read(KviKvsObjectFunctionCall *c); +}; + +#endif // !_CLASS_FILE_H_ diff --git a/src/modules/objects/KvsObject_ftp.cpp b/src/modules/objects/KvsObject_ftp.cpp new file mode 100644 index 000000000..9face909f --- /dev/null +++ b/src/modules/objects/KvsObject_ftp.cpp @@ -0,0 +1,327 @@ +//============================================================================= +// +// File : KvsObject_ftp.cpp +// Creation date : Mon Sep 1 08:13:45 2008 GMT by Carbone Alesssandro +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2009 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KviError.h" +#include "KvsObject_ftp.h" +#include "KviLocale.h" + +#include +#include + + +/* + @doc: ftp + @keyterms: + ftp object class + @title: + ftp class + @type: + class + @short: + An implementation of the client side of FTP protocol. + @inherits: + [class]object[/class] + @description: + This class provides a standard FTP functionality.[br] + @functions: + !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: $connect(,) + Connects to the FTP server host using port port.The command is scheduled, and its execution is performed asynchronously. + The function returns a unique identifier which is passed by commandStarted() and commandFinished().[br] + !fn:$abort() + Aborts the current command and deletes all scheduled commands. + !fn: $login(,) + Logs in to the FTP server with the username user and the password . + The function returns a unique identifier which is passed by commandStarted() and commandFinished().[br] + !fn: $get(,) + Downloads the file from the server. + !fn: $cd() + Changes the working directory of the server to . + !fn: $list() + Lists the contents of directory dir on the FTP server. + !fn: $commandFinishedEvent(,) + Called by KVIrc when the ftp command identified by id has finished. + error is true if an error occurred during the processing; otherwise error is false. + The default implementation emits the [classfnc]$commandFinished[/classfnc]() signal. + !fn: $listInfoEvent() + This event is triggered for each directory entry found by [classfnc]$list[/classfnc]() command. + The default implementation emits the [classfnc]$listInfo[/classfnc]() signal. + !fn: $dataTransferProgressEvent(,) + This event is triggered in response to a [classfnc]get[/classfnc]() or [classfnc]put[/classfnc]() request to indicate the current progress of the download or upload. + The default implementation emits the [classfnc]$dataTransferProgress[/classfnc]() signal. + @signals: + !sg: $commandFinished(,,) + This signal is emitted by the default implementation of [classfnc]$commandFinishedEvent[/classfnc]() + !sg: $listInfo() + This signal is emitted by the default implementation of [classfnc]$listInfoEvent[/classfnc]() + !sg: $dataTransferProgress(,) + This signal is emitted by the default implementation of [classfnc]$dataTransferProgressEvent[/classfnc]() +*/ + +KVSO_BEGIN_REGISTERCLASS(KvsObject_ftp,"ftp","object") + KVSO_REGISTER_HANDLER(KvsObject_ftp,"connect",functionConnect) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_ftp,abort) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_ftp,close) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_ftp,close) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_ftp,login) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_ftp,get) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_ftp,cd) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_ftp,list) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_ftp,commandFinishedEvent) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_ftp,listInfoEvent) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_ftp,stateChangedEvent) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_ftp,dataTransferProgressEvent) +KVSO_END_REGISTERCLASS(KvsObject_ftp) + + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_ftp,KviKvsObject) + m_pFtp = new QFtp(); + m_bAbort=false; + connect(m_pFtp,SIGNAL(commandFinished(int,bool)),this,SLOT(slotCommandFinished(int,bool))); + connect(m_pFtp,SIGNAL(commandStarted(int)),this,SLOT(slotCommandStarted(int))); + connect(m_pFtp,SIGNAL(dataTransferProgress(qint64,qint64)),this,SLOT(slotDataTransferProgress(qint64,qint64))); + connect(m_pFtp,SIGNAL(done(bool)),this,SLOT(slotDone(bool))); + connect(m_pFtp,SIGNAL(listInfo(const QUrlInfo)),this,SLOT(slotListInfo(const QUrlInfo))); + connect(m_pFtp,SIGNAL(readyRead()),this,SLOT(slotReadyRead())); + connect(m_pFtp,SIGNAL(stateChanged(int)),this,SLOT(slotStateChanged(int))); +KVSO_END_CONSTRUCTOR(KvsObject_ftp) + +KVSO_BEGIN_DESTRUCTOR(KvsObject_ftp) + QHashIterator t(getDict); + while (t.hasNext()) + { + t.next(); + int key=t.key(); + QFile *pFile=getDict.value(key); + pFile->close(); + delete pFile; + } + getDict.clear(); + delete m_pFtp; +KVSO_END_DESTRUCTOR(KvsObject_ftp) +//---------------------- + + + +KVSO_CLASS_FUNCTION(ftp,functionConnect) +{ + CHECK_INTERNAL_POINTER(m_pFtp) + QString szHost; + kvs_uint_t uRemotePort; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("host",KVS_PT_STRING,0,szHost) + KVSO_PARAMETER("remote_port",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,uRemotePort) + KVSO_PARAMETERS_END(c) + if (!uRemotePort) uRemotePort=21; + kvs_uint_t id=0; + id=m_pFtp->connectToHost(szHost, uRemotePort); + c->returnValue()->setInteger(id); + return true; +} + +KVSO_CLASS_FUNCTION(ftp,login) +{ + CHECK_INTERNAL_POINTER(m_pFtp) + QString szUser,szPass; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("user",KVS_PT_STRING,0,szUser) + KVSO_PARAMETER("password",KVS_PT_STRING,0,szPass) + KVSO_PARAMETERS_END(c) + int id=m_pFtp->login(szUser, szPass); + c->returnValue()->setInteger(id); + return true; +} + +KVSO_CLASS_FUNCTION(ftp,get) +{ + CHECK_INTERNAL_POINTER(m_pFtp) + QString szFile,szDest; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("remote_filename",KVS_PT_STRING,0,szFile) + KVSO_PARAMETER("local_filename",KVS_PT_STRING,0,szDest) + KVSO_PARAMETERS_END(c) + QFile *pFile; + pFile=new QFile(szDest); + pFile->open(QIODevice::WriteOnly); + int id=0; + id=m_pFtp->get(szFile,pFile); + getDict[id]=pFile; + c->returnValue()->setInteger(id); + return true; +} + +KVSO_CLASS_FUNCTION(ftp,cd) +{ + CHECK_INTERNAL_POINTER(m_pFtp) + QString szPath; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("remote_filename",KVS_PT_STRING,0,szPath) + KVSO_PARAMETERS_END(c) + int id=m_pFtp->cd(szPath); + c->returnValue()->setInteger(id); + return true; +} + +KVSO_CLASS_FUNCTION(ftp,list) +{ + CHECK_INTERNAL_POINTER(m_pFtp) + QString szPath; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("remote_dir",KVS_PT_STRING,0,szPath) + KVSO_PARAMETERS_END(c) + int id=m_pFtp->list(szPath); + c->returnValue()->setInteger(id); + return true; +} + +KVSO_CLASS_FUNCTION(ftp,abort) +{ + CHECK_INTERNAL_POINTER(m_pFtp) + m_bAbort=true; + m_pFtp->abort(); + return true; +} + +KVSO_CLASS_FUNCTION(ftp,close) +{ + CHECK_INTERNAL_POINTER(m_pFtp) + m_bAbort=true; + m_pFtp->close(); + return true; +} + +//signals & slots +KVSO_CLASS_FUNCTION(ftp,commandFinishedEvent) +{ + emitSignal("commandFinished",c,c->params()); + return true; +} + +void KvsObject_ftp::slotCommandFinished ( int id, bool error ) +{ + QString status=""; + if (m_bAbort) + { + m_bAbort=false; + QHashIterator t(getDict); + while (t.hasNext()) + { + t.next(); + int key=t.key(); + QFile *pFile=getDict.value(key); + pFile->close(); + delete pFile; + } + getDict.clear(); + return; + } + if (m_pFtp->currentCommand()==QFtp::Get) + { + status="Downloaded"; + QFile *pFile=getDict.value(id); + pFile->close(); + delete pFile; + getDict.remove(id); + } + else if (m_pFtp->currentCommand()==QFtp:: ConnectToHost) status="connected"; + else if (m_pFtp->currentCommand()==QFtp:: Login) status="logged"; + else if (m_pFtp->currentCommand()==QFtp:: Cd) status="entered"; + else if (m_pFtp->currentCommand()==QFtp:: List) status="listCompleted"; + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant((kvs_int_t) id)); + lParams.append(new KviKvsVariant(status)); + lParams.append(new KviKvsVariant(error)); + callFunction(this,"commandFinishedEvent",0,&lParams); +} + +void KvsObject_ftp::slotCommandStarted ( int ) +{ +} + +void KvsObject_ftp::slotDataTransferProgress ( qint64 done, qint64 total ) +{ + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant((kvs_int_t) done)); + lParams.append(new KviKvsVariant((kvs_int_t) total)); + callFunction(this,"dataTransferProgressEvent",0,&lParams); +} + +KVSO_CLASS_FUNCTION(ftp,dataTransferProgressEvent) +{ + emitSignal("dataTransferProgress",c,c->params()); + return true; +} + +void KvsObject_ftp::slotDone ( bool ) +{ +} + +void KvsObject_ftp::slotListInfo ( const QUrlInfo & i ) +{ + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(i.name())); + callFunction(this,"listInfoEvent",0,&lParams); +} + +KVSO_CLASS_FUNCTION(ftp,listInfoEvent) +{ + emitSignal("listInfo",c,c->params()); + return true; +} + +void KvsObject_ftp::slotReadyRead () +{ +} + +void KvsObject_ftp::slotRawCommandReply (int, const QString & ) +{ +} + +void KvsObject_ftp::slotStateChanged (int state) +{ + QString szState=""; + if (state==QFtp::Unconnected) szState="Unconnected"; + else if (state==QFtp::HostLookup) szState="HostLookup"; + else if (state==QFtp::Connecting) szState="Connecting"; + else if (state==QFtp::Connected) szState="Connected"; + else if (state==QFtp::LoggedIn) szState="LoggedIn"; + else if (state==QFtp::Closing) szState="Closing"; + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(szState)); + callFunction(this,"stateChangedEvent",0,&lParams); +} + +KVSO_CLASS_FUNCTION(ftp,stateChangedEvent) +{ + emitSignal("stateChanged",c,c->params()); + return true; +} + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_ftp.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/KvsObject_ftp.h b/src/modules/objects/KvsObject_ftp.h new file mode 100644 index 000000000..c50942fd1 --- /dev/null +++ b/src/modules/objects/KvsObject_ftp.h @@ -0,0 +1,64 @@ +#ifndef _CLASS_FTP_H_ +#define _CLASS_FTP_H_ +//============================================================================= +// +// File : KvsObject_ftp.h +// Creation date : Mon Sep 1 08:13:45 2008 GMT by Carbone Alesssandro +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2009 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "object_macros.h" + +#include +#include +#include + +class KvsObject_ftp : public KviKvsObject +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_ftp) +protected: + QFtp *m_pFtp; + QHash getDict; + bool m_bAbort; +protected: + bool functionConnect(KviKvsObjectFunctionCall *c); + bool get(KviKvsObjectFunctionCall *c); + bool login(KviKvsObjectFunctionCall *c); + bool cd(KviKvsObjectFunctionCall *c); + bool list(KviKvsObjectFunctionCall *c); + bool dataTransferProgressEvent(KviKvsObjectFunctionCall *c); + bool listInfoEvent(KviKvsObjectFunctionCall *c); + bool commandFinishedEvent(KviKvsObjectFunctionCall *c); + bool stateChangedEvent(KviKvsObjectFunctionCall *c); + bool abort(KviKvsObjectFunctionCall *c); + bool close(KviKvsObjectFunctionCall *c); +protected slots: + void slotCommandFinished ( int id, bool error ); + void slotCommandStarted ( int id ); + void slotDataTransferProgress ( qint64 done, qint64 total ); + void slotDone ( bool error ); + void slotListInfo ( const QUrlInfo & i ); + void slotRawCommandReply ( int replyCode, const QString & detail ); + void slotReadyRead (); + void slotStateChanged ( int state); +}; +#endif //_CLASS_FTP_H_ diff --git a/src/modules/objects/KvsObject_groupBox.cpp b/src/modules/objects/KvsObject_groupBox.cpp new file mode 100644 index 000000000..03042d795 --- /dev/null +++ b/src/modules/objects/KvsObject_groupBox.cpp @@ -0,0 +1,335 @@ +//============================================================================= +// +// File : KvsObject_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) 2005-2009 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_groupBox.h" +#include "KviError.h" +#include "kvi_debug.h" + +#include "KviLocale.h" +#include "KviIconManager.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: $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. + @examples: + [example] + //Let's start. + //First we'll create the main widget. as a dialog + %widget=$new(dialog) + %layout=$new(layout,%widget) + //then the groupbox + %gb=$new(groupbox,%widget) + %gb->$setTitle(Login) + %gb->$setAlignment("Left") + // add the gbox to the main layout + %layout->$addWidget(%gb,0,0) + // now we create the user field (labels + lineedit) + // in a horizontal box + %hbox=$new(hbox,%gb) + %labeluser=$new(label,%hbox) + %labeluser->$settext(User: ) + %inputuser=$new(lineedit,%hbox) + //now we create the pass field (labels + lineedit). + // in a horizontal box + %hbox=$new(hbox,%gb) + %labelpass=$new(label,%hbox) + %labelpass->$settext(Pass: ) + %inputpass=$new(lineedit,%hbox) + %inputpass->$setechomode("password") + // now we create the ok/cancel box buttons + %hbox=$new(hbox,%gb) + %btnok=$new(button,%hbox) + %btnok->$settext("OK") + %btncancel=$new(button,%hbox) + %btncancel->$settext("Cancel") + + //Let's show our nice form + %widget->$show() + [/example] + +*/ + +KVSO_BEGIN_REGISTERCLASS(KvsObject_groupBox,"groupbox","widget") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_groupBox,setTitle) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_groupBox,title) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_groupBox,setFlat) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_groupBox,isFlat) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_groupBox,setCheckable) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_groupBox,isCheckable) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_groupBox,setInsideMargin) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_groupBox,insideMargin) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_groupBox,setInsideSpacing) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_groupBox,insideSpacing) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_groupBox,addSpace) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_groupBox,alignment) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_groupBox,setAlignment) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_groupBox,setOrientation) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_groupBox,isChecked) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_groupBox,setChecked) + +KVSO_END_REGISTERCLASS(KvsObject_groupBox) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_groupBox,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_groupBox) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_groupBox) + +KVSO_END_CONSTRUCTOR(KvsObject_groupBox) + +bool KvsObject_groupBox::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + KviTalGroupBox *groupbox=new KviTalGroupBox(getName(),parentScriptWidget()); + + groupbox->setOrientation(Qt::Horizontal); + groupbox->setObjectName(getName()); + setObject(groupbox,true); + return true; +} + +KVSO_CLASS_FUNCTION(groupBox,setTitle) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szTitle; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("title",KVS_PT_STRING,0,szTitle) + KVSO_PARAMETERS_END(c) + ((KviTalGroupBox *)widget())->setTitle(szTitle); + return true; +} +KVSO_CLASS_FUNCTION(groupBox,title) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setString(((KviTalGroupBox *)widget())->title()); + return true; +} +KVSO_CLASS_FUNCTION(groupBox,setFlat) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bFlag",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + ((KviTalGroupBox *)widget())->setFlat(bEnabled); + return true; +} +KVSO_CLASS_FUNCTION(groupBox,isFlat) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setBoolean(((KviTalGroupBox *)widget())->isFlat()); + return true; +} +KVSO_CLASS_FUNCTION(groupBox,setCheckable) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bFlag",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + ((KviTalGroupBox *)widget())->setCheckable(bEnabled); + return true; +} +KVSO_CLASS_FUNCTION(groupBox,isCheckable) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setBoolean(((KviTalGroupBox *)widget())->isCheckable()); + return true; +} +KVSO_CLASS_FUNCTION(groupBox,setChecked) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bFlag",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + ((KviTalGroupBox *)widget())->setChecked(bEnabled); + return true; +} +KVSO_CLASS_FUNCTION(groupBox,isChecked) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setBoolean(((KviTalGroupBox *)widget())->isChecked()); + return true; +} +KVSO_CLASS_FUNCTION(groupBox,setInsideMargin) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uMargin; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("margin",KVS_PT_UNSIGNEDINTEGER,0,uMargin) + KVSO_PARAMETERS_END(c) + ((KviTalGroupBox *)widget())->setInsideMargin(uMargin); + return true; +} +KVSO_CLASS_FUNCTION(groupBox,insideMargin) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((KviTalGroupBox *)widget())->insideMargin()); + return true; +} +KVSO_CLASS_FUNCTION(groupBox,setInsideSpacing) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uSpacing; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("spacing",KVS_PT_UNSIGNEDINTEGER,0,uSpacing) + KVSO_PARAMETERS_END(c) + ((KviTalGroupBox *)widget())->setInsideSpacing(uSpacing); + return true; +} +KVSO_CLASS_FUNCTION(groupBox,insideSpacing) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((KviTalGroupBox *)widget())->insideSpacing()); + return true; +} + +KVSO_CLASS_FUNCTION(groupBox,addSpace) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t iSpace; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("colums",KVS_PT_UNSIGNEDINTEGER,0,iSpace) + KVSO_PARAMETERS_END(c) + (((KviTalGroupBox *)widget())->addSpace(iSpace)); + return true; +} + +KVSO_CLASS_FUNCTION(groupBox,setAlignment) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szAlign; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("alignment",KVS_PT_STRING,0,szAlign) + KVSO_PARAMETERS_END(c) + 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_ctx("Unknown alignment '%Q'","objets"),&szAlign); + return true; +} + +KVSO_CLASS_FUNCTION(groupBox,alignment) +{ + CHECK_INTERNAL_POINTER(widget()) + 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; +} + +KVSO_CLASS_FUNCTION(groupBox,setOrientation) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("orientation",KVS_PT_STRING,0,szMode) + KVSO_PARAMETERS_END(c) + if(KviQString::equalCI(szMode, "Horizontal")) + ((KviTalGroupBox *)widget())->setOrientation(Qt::Vertical); + else + if(KviQString::equalCI(szMode, "Vertical")) + ((KviTalGroupBox *)widget())->setOrientation(Qt::Horizontal); + else c->warning( __tr2qs_ctx("Unknown orientation '%Q'","objects"),&szMode); + + return true; +} diff --git a/src/modules/objects/KvsObject_groupBox.h b/src/modules/objects/KvsObject_groupBox.h new file mode 100644 index 000000000..4770352a9 --- /dev/null +++ b/src/modules/objects/KvsObject_groupBox.h @@ -0,0 +1,63 @@ +#ifndef _CLASS_GROUPBOX_H_ +#define _CLASS_GROUPBOX_H_ +//============================================================================= +// +// File : KvsObject_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) 2005-2009 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_widget.h" +#include "object_macros.h" + +class KvsObject_groupBox : public KvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KvsObject_groupBox) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + + bool setTitle(KviKvsObjectFunctionCall *c); + bool title(KviKvsObjectFunctionCall *c); + bool setFlat(KviKvsObjectFunctionCall *c); + bool isFlat(KviKvsObjectFunctionCall *c); + bool setCheckable(KviKvsObjectFunctionCall *c); + bool isCheckable(KviKvsObjectFunctionCall *c); + bool setInsideMargin(KviKvsObjectFunctionCall *c); + bool insideMargin(KviKvsObjectFunctionCall *c); + bool setInsideSpacing(KviKvsObjectFunctionCall *c); + bool insideSpacing(KviKvsObjectFunctionCall *c); + bool addSpace(KviKvsObjectFunctionCall *c); + bool alignment(KviKvsObjectFunctionCall *c); + bool setAlignment(KviKvsObjectFunctionCall *c); + bool setOrientation(KviKvsObjectFunctionCall *c); + bool isChecked(KviKvsObjectFunctionCall *c); + bool setChecked(KviKvsObjectFunctionCall *c); + +}; +#endif //!_CLASS_GROUPBOX_H_ + diff --git a/src/modules/objects/KvsObject_hBox.cpp b/src/modules/objects/KvsObject_hBox.cpp new file mode 100644 index 000000000..c9c5b53fb --- /dev/null +++ b/src/modules/objects/KvsObject_hBox.cpp @@ -0,0 +1,202 @@ +//============================================================================= +// +// File : KvsObject_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) 2005-2009 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KviLocale.h" +#include "KvsObject_hBox.h" +#include "KviTalHBox.h" + +const char * const align_tbl[] = { + "Left", + "Right", + "HCenter", + "VCenter", + "Center", + "Top", + "Bottom", + "WordBreak" +}; + + + +const int align_cod[] = { + Qt::AlignLeft, + Qt::AlignRight, + Qt::AlignHCenter, + Qt::AlignVCenter, + Qt::AlignCenter, + Qt::AlignTop, + Qt::AlignBottom, + Qt::AlignJustify, +}; + +#define align_num (sizeof(align_tbl) / sizeof(align_tbl[0])) + +/* + @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. + !fn: $addStretch() + Adds a stretchable space with zero minimum size and stretch factor stretch to the end of this box layout. + !fn: $setAlignment(, , ...) + Sets the alignment for widget w to flags, given as parameters. + Valid flags are:Right,Left,Top,Bottom,HCenter,VCenter,Center +*/ + + +KVSO_BEGIN_REGISTERCLASS(KvsObject_hBox,"hbox","widget") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_hBox,setMargin) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_hBox,setSpacing) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_hBox,setStretchFactor ) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_hBox,addStretch ) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_hBox,setAlignment ) +KVSO_END_REGISTERCLASS(KvsObject_hBox) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_hBox,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_hBox) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_hBox) + +KVSO_END_CONSTRUCTOR(KvsObject_hBox) + +bool KvsObject_hBox::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + + setObject(new KviTalHBox(parentScriptWidget()), true); + return true; +} + +KVSO_CLASS_FUNCTION(hBox,setMargin) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uMargin; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("margin",KVS_PT_UNSIGNEDINTEGER,0,uMargin) + KVSO_PARAMETERS_END(c) + ((KviTalHBox *)widget())->setMargin(uMargin); + return true; +} + +KVSO_CLASS_FUNCTION(hBox,setSpacing) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uSpacing; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("spacing",KVS_PT_UNSIGNEDINTEGER,0,uSpacing) + KVSO_PARAMETERS_END(c) + ((KviTalHBox *)widget())->setSpacing(uSpacing); + return true; +} + +KVSO_CLASS_FUNCTION(hBox,setStretchFactor) +{ + CHECK_INTERNAL_POINTER(widget()) + 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); + CHECK_HOBJECT_IS_WIDGET(pObject) + if(((KvsObject_widget *)pObject)->widget()->parentWidget() != widget()) + { + c->warning(__tr2qs_ctx("The widget must be a child of this hbox","objects")); + return true; + } + ((KviTalHBox *)widget())->setStretchFactor(((QWidget *)(pObject->object())),uStretch); + return true; +} + +KVSO_CLASS_FUNCTION(hBox,addStretch) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iStretch; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("stretch",KVS_PT_INT,0,iStretch) + KVSO_PARAMETERS_END(c) + ((KviTalHBox *)widget())->addStretch(iStretch); + return true; +} + +KVSO_CLASS_FUNCTION(hBox,setAlignment) +{ + CHECK_INTERNAL_POINTER(widget()) + QStringList alignment; + KviKvsObject * pObject; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("alignment",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,alignment) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + CHECK_HOBJECT_IS_WIDGET(pObject) + if(((KvsObject_widget *)pObject)->widget()->parentWidget() != widget()) + { + c->warning(__tr2qs_ctx("The widget must be a child of this hbox","objects")); + 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_ctx("Unknown alignment '%Q'","objects"),&(*it)); + + } + ((KviTalHBox *)widget())->setAlignment(((QWidget *)(pObject->object())),(Qt::Alignment)sum); + return true; +} diff --git a/src/modules/objects/KvsObject_hBox.h b/src/modules/objects/KvsObject_hBox.h new file mode 100644 index 000000000..29e9a75c0 --- /dev/null +++ b/src/modules/objects/KvsObject_hBox.h @@ -0,0 +1,49 @@ +#ifndef _CLASS_HBOX_H_ +#define _CLASS_HBOX_H_ +//============================================================================= +// +// File : KvsObject_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) 2005-2009 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "object_macros.h" +#include "KvsObject_widget.h" + +class KvsObject_hBox : public KvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KvsObject_hBox) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool setMargin(KviKvsObjectFunctionCall *c); + bool setSpacing(KviKvsObjectFunctionCall *c); + bool setStretchFactor(KviKvsObjectFunctionCall *c); + bool addStretch(KviKvsObjectFunctionCall *c); + bool setAlignment(KviKvsObjectFunctionCall *c); + + +}; + + +#endif //_CLASS_HBOX_H_ diff --git a/src/modules/objects/KvsObject_http.cpp b/src/modules/objects/KvsObject_http.cpp new file mode 100644 index 000000000..c0adda535 --- /dev/null +++ b/src/modules/objects/KvsObject_http.cpp @@ -0,0 +1,561 @@ +//============================================================================= +// +// File : KvsObject_http.cpp +// Creation date : Fry Sep 5 18:13:45 2008 GMT by Carbone Alesssandro +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2009 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_http.h" + +#include "kvi_debug.h" +#include "KviError.h" +#include "KviLocale.h" + +#include +#include +#include + +#ifndef QT_NO_OPENSSL + #include + + const char * const ssl_errors_tbl[] = { + "NoError", + "UnableToGetIssuerCertificate", + "UnableToDecryptCertificateSignature", + "UnableToDecodeIssuerPublicKey", + "CertificateSignatureFailed", + "CertificateNotYetValid", + "CertificateExpired", + "InvalidNotBeforeField", + "InvalidNotAfterField", + "SelfSignedCertificate", + "SelfSignedCertificateInChain", + "UnableToGetLocalIssuerCertificate", + "UnableToVerifyFirstCertificate", + "CertificateRevoked", + "InvalidCaCertificate", + "PathLengthExceeded", + "InvalidPurpose", + "CertificateUntrusted", + "CertificateRejected", + "SubjectIssuerMismatch", + "AuthorityIssuerSerialNumberMismatch", + "NoPeerCertificate", + "HostNameMismatch", + "UnspecifiedError", + "NoSslSupport" + }; +#endif + +/* + @doc: http + @keyterms: + http object class + @title: + http class + @type: + class + @short: + An implementation of the client side of HTTP protocol. + @inherits: + [class]object[/class] + @description: + This class provides a standard HTTP functionality.[br] + @functions: + !fn: $get(,[]) + Sends a get request for path to the server set by [classfnc]$setHost[/classfnc]. + If local_file is not specified readyRead() signal is emitted every time new content data is available to read. + !fn: $post(,, + Sends a post request for path to the server set by [classfnc]$setHost[/classfnc]. + If local_file is not specified readyRead() signal is emitted every time new content data is available to read. + !fn: $abort() + Aborts the current request and deletes all scheduled requests. + !fn: $setHost(,) + Sets the HTTP server that is used for requests to hostName on port port. + The function does not block: the request is scheduled, and its execution is performed asynchronously. + The function returns a unique identifier which is passed by [classfnc]requestStartedEvent()[/classfnc] and [classfnc]requestFinishedEvent()[/classfnc]. + When the request is started the requestStarted() signal is emitted. When it is finished the requestFinished() signal is emitted. + !fn: $currentId() + Returns the identifier of the HTTP request being executed or 0 if there is no request being executed. + !fn: $setProxy(,,[,]) + Enables HTTP proxy support, using the proxy server host on port port. + Optionals parameters user and password can be provided if the proxy server requires authentication. + !fn: $setUser(,) + This function sets the user name userName and password password for web pages that require authentication. + !fn: $readAll() + Reads all the bytes from the response content and returns them as string. + !fn: $errorString() + Returns a human-readable description of the last error that occurred. + !fn: $ignoreSslErrors() + !fn: $requestFinishedEvent(,) + This event is triggered by KVIrc when the request identified by has finished. + !fn: $requestStartedEvent(,) + This event is triggered by KVIrc when the request identified by has started. + !fn: $responseHeaderReceivedEvent() + This event is triggered by KVIrc when he HTTP header of a server response is available. + The response is passed ad string. + !fn: $doneEvent() + This event is triggered when the last pending request has finished; (it is emitted after the last request's requestFinished() signal). + !fn: $dataReadProgressEvent(,) + This event is triggered when reads data from a HTTP server. + is the amount of data has already arrived and is the total amount of data. + !fn: $dataSendProgressEvent(,) + This event is triggered when sends data to a HTTP server. + is the amount of data has already arrived and is the total amount of data. + !fn: $stateChangedEvent() + This event is triggered by the framework when the state of the connection changes. + !fn: $readyReadEvent() + This event is triggered by the framework when there is new data read and there is not file specified in [classfnc]get[/classfunc] or [classfnc]post[/classfunc]. + You can call [classfnc]readAll[/classfnc] to reads all the bytes from the response data. + !fn: $sslErrorsEvent() + Returns the list of errors that occurred during the SSL handshake. + Unless you call ignoreSslErrors() from within a slot connected to the signal emited by this event, + the framwork will tear down the connection immediately after emitting the signal. + @signals: + !sg: $requestStarted() + This signal is emitted by the default implementation of [classfnc]$requestStartedEvent[/classfnc]. + !sg: $requestFinished() + This signal is emitted by the default implementation of [classfnc]$requestFinishedEvent[/classfnc]. + !sg: $dataSendProgress() + This signal is emitted by the default implementation of [classfnc]$dataSendProgressEvent[/classfnc]. + !sg: $dataReadProgress() + This signal is emitted by the default implementation of [classfnc]$dataReadProgressEvent[/classfnc]. + !sg: $done() + This signal is emitted by the default implementation of [classfnc]$doneEvent[/classfnc]. + !sg: $readyRead() + This signal is emitted by the default implementation of [classfnc]$readyReadEvent[/classfnc]. + !sg: $sslErrors() + This signal is emitted by the default implementation of [classfnc]$sslErrorsEvent[/classfnc]. + !sg: $stateChanged() + This signal is emitted by the default implementation of [classfnc]$stateChangedEvent[/classfnc]. + !sg: $responseHeaderReceived() + This signal is emitted by the default implementation of [classfnc]$responseHeaderReceivedEvent[/classfnc]. +*/ + +KVSO_BEGIN_REGISTERCLASS(KvsObject_http,"http","object") + KVSO_REGISTER_HANDLER(KvsObject_http,"get",functionGet) + KVSO_REGISTER_HANDLER(KvsObject_http,"post",functionPost) + KVSO_REGISTER_HANDLER(KvsObject_http,"abort",functionAbort) + KVSO_REGISTER_HANDLER(KvsObject_http,"setHost",functionSetHost) + KVSO_REGISTER_HANDLER(KvsObject_http,"setProxy",functionSetProxy) + KVSO_REGISTER_HANDLER(KvsObject_http,"currentId",functionCurrentId) + KVSO_REGISTER_HANDLER(KvsObject_http,"setUser",functionSetUser) + KVSO_REGISTER_HANDLER(KvsObject_http,"readAll",functionReadAll) + KVSO_REGISTER_HANDLER(KvsObject_http,"errorString",functionErrorString) + KVSO_REGISTER_HANDLER(KvsObject_http,"setFollowRedirect",functionFollowRedirect) + + // events + KVSO_REGISTER_HANDLER(KvsObject_http,"doneEvent",functionDoneEvent) + KVSO_REGISTER_HANDLER(KvsObject_http,"requestFinishedEvent",functionRequestFinishedEvent) + KVSO_REGISTER_HANDLER(KvsObject_http,"requestStartedEvent",functionRequestStartedEvent) + KVSO_REGISTER_HANDLER(KvsObject_http,"responseHeaderReceivedEvent",functionResponseHeaderReceivedEvent) + KVSO_REGISTER_HANDLER(KvsObject_http,"dataReadProgressEvent",functionDataReadProgressEvent) + KVSO_REGISTER_HANDLER(KvsObject_http,"dataSendProgressEvent",functionDataSendProgressEvent) + KVSO_REGISTER_HANDLER(KvsObject_http,"stateChangedEvent",functionStateChangedEvent) + KVSO_REGISTER_HANDLER(KvsObject_http,"readyReadEvent",functionReadyReadEvent) + #ifndef QT_NO_OPENSSL + KVSO_REGISTER_HANDLER(KvsObject_http,"sslErrorsEvent",functionSslErrorsEvent) + KVSO_REGISTER_HANDLER(KvsObject_http,"ignoreSSlErrors",functionIgnoreSslErrors) + #endif +KVSO_END_REGISTERCLASS(KvsObject_http) + + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_http,KviKvsObject) + m_pHttp = new QHttp(); + m_bAbort=false; + m_bEnableForceRedirect=false; + connect(m_pHttp,SIGNAL(requestFinished(int,bool)),this,SLOT(slotRequestFinished(int,bool))); + connect(m_pHttp,SIGNAL(done(bool)),this,SLOT(slotDone(bool))); + + connect(m_pHttp,SIGNAL(requestStarted(int)),this,SLOT(slotRequestStarted(int))); + connect(m_pHttp,SIGNAL(dataSendProgress(int,int)),this,SLOT(slotDataSendProgress(int,int))); + connect(m_pHttp,SIGNAL(dataReadProgress(int,int)),this,SLOT(slotDataReadProgress(int,int))); + connect(m_pHttp,SIGNAL(responseHeaderReceived ( const QHttpResponseHeader & )),this,SLOT(slotResponseHeaderReceived(const QHttpResponseHeader &))); + connect(m_pHttp,SIGNAL(readyRead ( const QHttpResponseHeader & )),this,SLOT(slotReadyRead(const QHttpResponseHeader &))); + #ifndef QT_NO_OPENSSL + connect(m_pHttp,SIGNAL(sslErrors ( const QList & )),this,SLOT(slotSslErrors(const QList & ))); + #endif + connect(m_pHttp,SIGNAL(stateChanged(int)),this,SLOT(slotStateChanged(int))); + +KVSO_END_CONSTRUCTOR(KvsObject_http) + +KVSO_BEGIN_DESTRUCTOR(KvsObject_http) + QHashIterator t(getDict); + while (t.hasNext()) + { + t.next(); + int key=t.key(); + QFile *pFile=getDict.value(key); + pFile->close(); + delete pFile; + } + getDict.clear(); + delete m_pHttp; + +KVSO_END_DESTRUCTOR(KvsObject_http) +//---------------------- + + +bool KvsObject_http::functionSetHost(KviKvsObjectFunctionCall *c) +{ + CHECK_INTERNAL_POINTER(m_pHttp) + QString szHost; + QString szConnectionType; + kvs_uint_t uRemotePort; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("host",KVS_PT_STRING,0,szHost) + KVSO_PARAMETER("remote_port",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,uRemotePort) + KVSO_PARAMETERS_END(c) + QUrl url(szHost); + if (!url.isValid()) + { + c->warning(__tr2qs_ctx("Host '%Q' is not a valid url","objects"),&szHost); + return true; + } + if (!szHost.isEmpty() && url.host().isEmpty()) url.setHost(szHost); + if (!uRemotePort) uRemotePort=80; + kvs_uint_t id=0; + QHttp::ConnectionMode mode; + if(url.scheme().toLower()=="https") mode=QHttp::ConnectionModeHttps; + else {mode=QHttp::ConnectionModeHttp;url.setScheme("http");} + if (mode==QHttp::ConnectionModeHttps) uRemotePort=443; + id=m_pHttp->setHost(url.host(), mode, uRemotePort); + c->returnValue()->setInteger(id); + return true; +} +bool KvsObject_http::functionCurrentId(KviKvsObjectFunctionCall *c) +{ + CHECK_INTERNAL_POINTER(m_pHttp) + c->returnValue()->setInteger(m_pHttp->currentId()); + return true; +} +bool KvsObject_http::functionSetUser(KviKvsObjectFunctionCall *c) +{ + CHECK_INTERNAL_POINTER(m_pHttp) + QString szUser; + QString szPass; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("user",KVS_PT_STRING,0,szUser) + KVSO_PARAMETER("password",KVS_PT_STRING,0,szPass) + KVSO_PARAMETERS_END(c) + kvs_int_t id; + id=m_pHttp->setUser(szUser,szPass); + return true; +} +bool KvsObject_http::functionSetProxy(KviKvsObjectFunctionCall *c) +{ + CHECK_INTERNAL_POINTER(m_pHttp) + QString szHost; + QString szUser,szPass; + kvs_uint_t uRemotePort; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("host",KVS_PT_STRING,0,szHost) + KVSO_PARAMETER("remote_port",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,uRemotePort) + KVSO_PARAMETER("user",KVS_PT_STRING,KVS_PF_OPTIONAL,szUser) + KVSO_PARAMETER("pass",KVS_PT_STRING,KVS_PF_OPTIONAL,szPass) + KVSO_PARAMETERS_END(c) + m_pHttp->setProxy(szHost,uRemotePort,szUser,szPass); + return true; +} + +bool KvsObject_http::functionGet(KviKvsObjectFunctionCall *c) +{ + CHECK_INTERNAL_POINTER(m_pHttp) + QString szPath,szDest; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("remote_path",KVS_PT_STRING,0,szPath) + KVSO_PARAMETER("local_filename",KVS_PT_STRING,KVS_PF_OPTIONAL,szDest) + KVSO_PARAMETERS_END(c) + + QFile * pFile=0; + if (!szDest.isEmpty()) + { + pFile=new QFile(szDest); + if (pFile) + { + pFile->open(QIODevice::WriteOnly); + } else { + c->warning(__tr2qs_ctx("'%Q' is not a valid file path","objects"),&szDest); + c->returnValue()->setInteger(-1); + return true; + } + } + + if (szPath.isEmpty()) szPath="/"; + int id=m_pHttp->get(szPath,pFile); + if (pFile) getDict[id]=pFile; + c->returnValue()->setInteger(id); + return true; +} +bool KvsObject_http::functionPost(KviKvsObjectFunctionCall *c) +{ + CHECK_INTERNAL_POINTER(m_pHttp) + QString szPath,szDest,szData; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("remote_path",KVS_PT_STRING,0,szPath) + KVSO_PARAMETER("post_data",KVS_PT_STRING,0,szData) + KVSO_PARAMETER("local_filename",KVS_PT_STRING,0,szDest) + KVSO_PARAMETERS_END(c) + QFile *pFile=0; + if (!szDest.isEmpty()){ + pFile=new QFile(szDest); + if (pFile){ + pFile->open(QIODevice::WriteOnly); + } + } + if (szPath.isEmpty()) szPath="/"; + int id=m_pHttp->post(szPath,szDest.toAscii(),pFile); + if (pFile) getDict[id]=pFile; + c->returnValue()->setInteger(id); + return true; +} +bool KvsObject_http::functionAbort(KviKvsObjectFunctionCall *c) +{ + CHECK_INTERNAL_POINTER(m_pHttp) + m_bAbort=true; + m_pHttp->abort(); + return true; +} +bool KvsObject_http::functionReadAll(KviKvsObjectFunctionCall *c) +{ + CHECK_INTERNAL_POINTER(m_pHttp) + c->returnValue()->setString(m_pHttp->readAll()); + return true; +} +bool KvsObject_http::functionErrorString(KviKvsObjectFunctionCall *c) +{ + CHECK_INTERNAL_POINTER(m_pHttp) + c->returnValue()->setString(m_pHttp->errorString()); + return true; +} +bool KvsObject_http::functionFollowRedirect(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("enable",KVS_PT_BOOLEAN,0,bEnabled) + KVSO_PARAMETERS_END(c) + m_bEnableForceRedirect=bEnabled; + return true; +} +//signals & slots + +bool KvsObject_http::functionRequestFinishedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("requestFinished",c,c->params()); + return true; +} + +void KvsObject_http::slotRequestFinished ( int id, bool error ) +{ + + if (m_bAbort) + { + m_bAbort=false; + QHashIterator t(getDict); + while (t.hasNext()) + { + t.next(); + int key=t.key(); + QFile *pFile=getDict.value(key); + pFile->close(); + delete pFile; + } + getDict.clear(); + return; + } + QFile *pFile=getDict.value(id); + if (pFile) + { + QString name=pFile->fileName(); + pFile->close(); + getDict.remove(id); + int res=m_pHttp->lastResponse().statusCode(); + if ((res==301 || res==302 || res==307) && m_bEnableForceRedirect) + redirect(name,m_pHttp->lastResponse()); + delete pFile; + } + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant((kvs_int_t) id)); + lParams.append(new KviKvsVariant(error)); + callFunction(this,"requestFinishedEvent",0,&lParams); +} + +bool KvsObject_http::functionRequestStartedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("requestStarted",c,c->params()); + return true; +} +void KvsObject_http::slotRequestStarted ( int id ) +{ + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant((kvs_int_t) id)); + callFunction(this,"requestStartedEvent",0,&lParams); +} + +void KvsObject_http::slotDataReadProgress ( int done,int total ) +{ + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant((kvs_int_t) done)); + lParams.append(new KviKvsVariant((kvs_int_t) total)); + callFunction(this,"dataReadProgressEvent",0,&lParams); +} +bool KvsObject_http::functionDataReadProgressEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("dataReadProgress",c,c->params()); + return true; +} +void KvsObject_http::slotDataSendProgress ( int done,int total ) +{ + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant((kvs_int_t) done)); + lParams.append(new KviKvsVariant((kvs_int_t) total)); + callFunction(this,"dataSendProgressEvent",0,&lParams); +} +bool KvsObject_http::functionDataSendProgressEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("dataSendProgress",c,c->params()); + return true; +} +bool KvsObject_http::functionDoneEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("done",c,c->params()); + return true; +} +void KvsObject_http::slotDone ( bool error ) +{ + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(error)); + callFunction(this,"doneEvent",0,&lParams); +} + +bool KvsObject_http::functionResponseHeaderReceivedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("responseHeaderReceived",c,c->params()); + return true; +} +bool KvsObject_http::functionReadyReadEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("readyRead",c,c->params()); + return true; +} +void KvsObject_http::redirect(QString &file,const QHttpResponseHeader &r) +{ + QUrl url(r.value("location")); + m_pHttp->setHost(url.host()); + QFile *pFile=0; + pFile=new QFile(file); + pFile->open(QIODevice::WriteOnly); + int id=m_pHttp->get(url.path(),pFile); + getDict[id]=pFile; +} + +void KvsObject_http::slotResponseHeaderReceived(const QHttpResponseHeader &r) +{ + QString szResponse; + switch (r.statusCode()) { + case 200: szResponse="Ok" ;break; + case 301: szResponse="Moved Permanently" ;break; + case 302: szResponse="Found" ;break; + case 303: szResponse="See Other" ;break; + case 307: szResponse="Temporary Redirect" ;break; + default: szResponse=r.reasonPhrase(); + m_bAbort=true; + } + if (r.statusCode()==400) + { + m_bAbort=true; + m_pHttp->abort(); + } + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(szResponse)); + callFunction(this,"responseHeaderReceivedEvent",0,&lParams); + +} +void KvsObject_http::slotReadyRead(const QHttpResponseHeader &r) +{ + QString szResponse; + switch (r.statusCode()) { + case 200: szResponse="Ok" ;break; + case 301: szResponse="Moved Permanently" ;break; + case 302: szResponse="Found" ;break; + case 303: szResponse="See Other" ;break; + case 307: szResponse="Temporary Redirect" ;break; + default: szResponse=r.reasonPhrase(); + m_bAbort=true; + } + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(szResponse)); + callFunction(this,"readyreadEvent",0,&lParams); +} + + + + +void KvsObject_http::slotStateChanged ( int state) +{ + QString szState=""; + if (state==QHttp::Unconnected) szState="Unconnected"; + else if (state==QHttp::HostLookup) szState="HostLookup"; + else if (state==QHttp::Connecting) szState="Connecting"; + else if (state==QHttp::Connected) szState="Connected"; + else if (state==QHttp::Sending) szState="Sending"; + else if (state==QHttp::Reading) szState="Reading"; + + else if (state==QHttp::Closing) szState="Closing"; + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(szState)); + callFunction(this,"stateChangedEvent",0,&lParams); +} +bool KvsObject_http::functionStateChangedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("stateChanged",c,c->params()); + return true; +} + +#ifndef QT_NO_OPENSSL + +bool KvsObject_http::functionIgnoreSslErrors(KviKvsObjectFunctionCall *) +{ + if (m_pHttp) m_pHttp->ignoreSslErrors(); + return true; +} +void KvsObject_http::slotSslErrors(QList sslerrors) +{ + KviKvsArray *pArray=0; + pArray=new KviKvsArray(); + for(int i=0;iset(i,new KviKvsVariant(ssl_errors_tbl[sslerrors.at(i).error()])); + } + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(pArray)); + callFunction(this,"sslErrorEvent",0,&lParams); + } + +bool KvsObject_http::functionSslErrorsEvent(KviKvsObjectFunctionCall *c) +{ + + emitSignal("sslErrors",c,c->params()); + return true; +} +#endif +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_http.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/KvsObject_http.h b/src/modules/objects/KvsObject_http.h new file mode 100644 index 000000000..1ef5ef592 --- /dev/null +++ b/src/modules/objects/KvsObject_http.h @@ -0,0 +1,89 @@ +#ifndef _CLASS_HTTP_H_ +#define _CLASS_HTTP_H_ +//============================================================================= +// +// File : KvsObject_http.h +// Creation date : Fry Sep 5 18:13:45 2008 GMT by Carbone Alesssandro +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "object_macros.h" +#include +#include +#include +#include + +class KvsObject_http : public KviKvsObject +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_http) +protected: + QHttp *m_pHttp; + QHash getDict; + bool m_bAbort; + bool m_bEnableForceRedirect; +protected: + bool functionSetHost(KviKvsObjectFunctionCall *c); + bool functionGet(KviKvsObjectFunctionCall *c); + bool functionSetUser(KviKvsObjectFunctionCall *c); + bool functionSetProxy(KviKvsObjectFunctionCall *c); + bool functionRequestFinishedEvent(KviKvsObjectFunctionCall *c); + bool functionRequestStartedEvent(KviKvsObjectFunctionCall *c); + bool functionDataReadProgressEvent(KviKvsObjectFunctionCall *c); + bool functionDataSendProgressEvent(KviKvsObjectFunctionCall *c); + bool functionResponseHeaderReceivedEvent(KviKvsObjectFunctionCall *c); + bool functionAbort(KviKvsObjectFunctionCall *c); + bool functionDoneEvent(KviKvsObjectFunctionCall *c); + bool functionStateChangedEvent(KviKvsObjectFunctionCall *c); + bool functionReadAll(KviKvsObjectFunctionCall *c); + bool functionReadyReadEvent(KviKvsObjectFunctionCall *c); + bool functionErrorString(KviKvsObjectFunctionCall *c); + bool functionPost(KviKvsObjectFunctionCall *c); + bool functionFollowRedirect(KviKvsObjectFunctionCall *c); + bool functionCurrentId(KviKvsObjectFunctionCall *c); + void redirect(QString &file,const QHttpResponseHeader &r); + + #ifndef QT_NO_OPENSSL + bool functionIgnoreSslErrors(KviKvsObjectFunctionCall *c); + bool functionSslErrorsEvent(KviKvsObjectFunctionCall *c); + #endif + +protected slots: + void slotRequestFinished ( int id, bool error ); + void slotDone (bool error ); + void slotRequestStarted ( int id ); + void slotDataSendProgress ( int done, int total ); + void slotDataReadProgress ( int done, int total ); + #ifndef QT_NO_OPENSSL + void slotSslErrors(QList); + #endif + void slotResponseHeaderReceived(const QHttpResponseHeader &r); + void slotReadyRead(const QHttpResponseHeader &r); + void slotStateChanged ( int state); + + + +}; +#endif //_CLASS_HTTP_H_ diff --git a/src/modules/objects/KvsObject_label.cpp b/src/modules/objects/KvsObject_label.cpp new file mode 100644 index 000000000..08cb4ffa1 --- /dev/null +++ b/src/modules/objects/KvsObject_label.cpp @@ -0,0 +1,361 @@ +//============================================================================= +// +// File : KvsObject_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) 2000 Krzysztof Godlewski +// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "KviError.h" +#include "kvi_debug.h" +#include "KvsObject_label.h" +#include "KviLocale.h" +#include "KviIconManager.h" + +#include +#include +#include +#include + + + +// Tables used in $setAlignment & $alignment +const char * const align_tbl[] = { + "Left", + "Right", + "HCenter", + "VCenter", + "Center", + "Top", + "Bottom", + "WordBreak" +}; + +const int align_cod[] = { + Qt::AlignLeft, + Qt::AlignRight, + Qt::AlignHCenter, + Qt::AlignVCenter, + Qt::AlignCenter, + Qt::AlignTop, + Qt::AlignBottom, + Qt::AlignJustify, +}; + +#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: $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(KvsObject_label,"label","widget") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_label,setText) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_label,text) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_label,margin) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_label,setMargin) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_label,alignment) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_label,setAlignment) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_label,clear) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_label,frameStyle) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_label,setFrameStyle) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_label,setImage) +KVSO_END_REGISTERCLASS(KvsObject_label) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_label,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_label) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_label) + +KVSO_END_CONSTRUCTOR(KvsObject_label) + +bool KvsObject_label::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT(QLabel) + ((QLabel *)widget())->setWordWrap(true); + return true; +} + +KVSO_CLASS_FUNCTION(label,setText) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + ((QLabel *)widget())->setText(szText); + return true; +} + +KVSO_CLASS_FUNCTION(label,text) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setString(((QLabel *)widget())->text()); + return true; +} + +KVSO_CLASS_FUNCTION(label,setMargin) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t iMargin; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("margin",KVS_PT_UNSIGNEDINTEGER,0,iMargin) + KVSO_PARAMETERS_END(c) + ((QLabel *)widget())->setMargin(iMargin); + return true; +} +KVSO_CLASS_FUNCTION(label,margin) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QLabel *)widget())->margin()); + return true; +} + +KVSO_CLASS_FUNCTION(label,setAlignment) +{ + CHECK_INTERNAL_POINTER(widget()) + QStringList alignment; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("alignment",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,alignment) + KVSO_PARAMETERS_END(c) + 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_ctx("Unknown alignment '%Q'","objects"),&(*it)); + + } + ((QLabel *)widget())->setAlignment((Qt::Alignment)sum); + return true; +} + +KVSO_CLASS_FUNCTION(label,alignment) +{ + CHECK_INTERNAL_POINTER(widget()) + 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; +} + +KVSO_CLASS_FUNCTION(label,clear) +{ + CHECK_INTERNAL_POINTER(widget()) + ((QLabel *)widget())->clear(); + return true; +} + +KVSO_CLASS_FUNCTION(label,setFrameStyle) +{ + CHECK_INTERNAL_POINTER(widget()) + 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_ctx("Unknown style '%Q'","objects"),&(*it)); + + } + ((QLabel *)widget())->setFrameStyle(sum); + return true; +} + +KVSO_CLASS_FUNCTION(label,frameStyle) +{ + CHECK_INTERNAL_POINTER(widget()) + 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; +} + +KVSO_CLASS_FUNCTION(label,setImage) +{ + CHECK_INTERNAL_POINTER(widget()) + QString icon; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("icon",KVS_PT_STRING,0,icon) + KVSO_PARAMETERS_END(c) + QPixmap * pix = g_pIconManager->getImage(icon); + if(pix) ((QLabel *)widget())->setPixmap(*pix); + return true; +} diff --git a/src/modules/objects/KvsObject_label.h b/src/modules/objects/KvsObject_label.h new file mode 100644 index 000000000..f043f126b --- /dev/null +++ b/src/modules/objects/KvsObject_label.h @@ -0,0 +1,53 @@ +#ifndef _CLASS_LABEL_H_ +#define _CLASS_LABEL_H_ +//============================================================================= +// +// File : KvsObject_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) 2000 Krzysztof Godlewski +// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + + +#include "KvsObject_widget.h" +#include "object_macros.h" + +class KvsObject_label : public KvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KvsObject_label) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool setTitle(KviKvsObjectFunctionCall *c); + bool setText(KviKvsObjectFunctionCall *c); + bool text(KviKvsObjectFunctionCall *c); + bool margin(KviKvsObjectFunctionCall *c); + bool setMargin(KviKvsObjectFunctionCall *c); + bool alignment(KviKvsObjectFunctionCall *c); + bool setAlignment(KviKvsObjectFunctionCall *c); + bool clear(KviKvsObjectFunctionCall *c); + bool frameStyle(KviKvsObjectFunctionCall *c); + bool setFrameStyle(KviKvsObjectFunctionCall *c); + bool setImage(KviKvsObjectFunctionCall *c); +}; +#endif // !_CLASS_LABEL_H_ diff --git a/src/modules/objects/KvsObject_layout.cpp b/src/modules/objects/KvsObject_layout.cpp new file mode 100644 index 000000000..8d923da2e --- /dev/null +++ b/src/modules/objects/KvsObject_layout.cpp @@ -0,0 +1,317 @@ +//============================================================================= +// +// File : KvsObject_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-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#define _KVI_DEBUG_CHECK_RANGE_ +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KvsObject_layout.h" + +#include + + + +// Tables used in $setAlignment & $alignment +const char * const align_tbl[] = { + "Left", + "Right", + "HCenter", + "VCenter", + "Center", + "Top", + "Bottom", + }; + + + +const int align_cod[] = { + Qt::AlignLeft, + Qt::AlignRight, + Qt::AlignHCenter, + Qt::AlignVCenter, + Qt::AlignCenter, + Qt::AlignTop, + Qt::AlignBottom, + }; +#define align_num (sizeof(align_tbl) / sizeof(align_tbl[0])) +/* + @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: $setColumnStretch(,) + 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: $setAlignment(, , ...) + Sets the alignment for widget w to flags, given as parameters. + Valid flags are:Right,Left,Top,Bottom,HCenter,VCenter,Center + !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(KvsObject_layout,"layout","object") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_layout,addWidget) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_layout,addMultiCellWidget) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_layout,setRowStretch) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_layout,setColumnStretch) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_layout,addRowSpacing) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_layout,addColSpacing) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_layout,setMargin) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_layout,setSpacing) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_layout,setResizeMode) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_layout,setAlignment ) +KVSO_END_REGISTERCLASS(KvsObject_layout) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_layout,KviKvsObject) + +KVSO_END_CONSTRUCTOR(KvsObject_layout) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_layout) + +KVSO_END_CONSTRUCTOR(KvsObject_layout) + +bool KvsObject_layout::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *) +{ + QWidget * w = parentScriptWidget(); + + if(!w) + { + pContext->warning(__tr2qs_ctx("The parent of a layout must be a widget!","objects")); + return false; + } + // If there already is a layout manager installed on this widget, QWidget won't let you install another. + if(w->layout()) delete w->layout(); + setObject(new QGridLayout(w)); + ((QGridLayout *)object())->setVerticalSpacing(0); + ((QGridLayout *)object())->setHorizontalSpacing(0); + setObjectName(getName()); + return true; +} + +KVSO_CLASS_FUNCTION(layout,addWidget) +{ + CHECK_INTERNAL_POINTER(widget()) + 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); + CHECK_HOBJECT_IS_WIDGET(pObject) + ((QGridLayout *)object())->addWidget(((QWidget *)(pObject->object())),uRow,uCol); + return true; +} + +KVSO_CLASS_FUNCTION(layout,addMultiCellWidget) +{ + CHECK_INTERNAL_POINTER(widget()) + 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); + CHECK_HOBJECT_IS_WIDGET(pObject) + // { addWidget(w, fromRow, fromCol, (toRow < 0) ? -1 : toRow - fromRow + 1, (toCol < 0) ? -1 : toCol - fromCol + 1, _align); } + ((QGridLayout *)object())->addWidget(((QWidget *)(pObject->object())),uStartRow, uStartCol, uEndRow - uStartRow + 1, uEndCol - uStartCol + 1); + return true; +} + +KVSO_CLASS_FUNCTION(layout,setRowStretch) +{ + CHECK_INTERNAL_POINTER(widget()) + 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) + ((QGridLayout *)object())->setRowStretch(uRow,uStretch); + return true; +} + +KVSO_CLASS_FUNCTION(layout,setColumnStretch) +{ + CHECK_INTERNAL_POINTER(widget()) + 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) + ((QGridLayout *)object())->setColumnStretch(uCol,uStretch); + return true; +} + +KVSO_CLASS_FUNCTION(layout,setMargin) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uMargin; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("margin",KVS_PT_UNSIGNEDINTEGER,0,uMargin) + KVSO_PARAMETERS_END(c) + ((QGridLayout *)object())->setMargin(uMargin); + return true; +} + +KVSO_CLASS_FUNCTION(layout,setSpacing) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uSpacing; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("spacing",KVS_PT_UNSIGNEDINTEGER,0,uSpacing) + KVSO_PARAMETERS_END(c) + ((QGridLayout *)object())->setSpacing(uSpacing); + return true; +} + +KVSO_CLASS_FUNCTION(layout,addRowSpacing) +{ + CHECK_INTERNAL_POINTER(widget()) + 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) + //((QGridLayout *)object())->addRowSpacing(uRow,uSpacing); + ((QGridLayout *)object())->addItem(new QSpacerItem(0, uSpacing), uRow, 0); + return true; +} + +KVSO_CLASS_FUNCTION(layout,addColSpacing) +{ + CHECK_INTERNAL_POINTER(widget()) + 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) + ((QGridLayout *)object())->addItem(new QSpacerItem(uSpacing,0), 0, uCol); + return true; +} + +KVSO_CLASS_FUNCTION(layout,setResizeMode) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("resize_mode",KVS_PT_STRING,0,szMode) + KVSO_PARAMETERS_END(c) + QLayout::SizeConstraint r = QLayout::SetDefaultConstraint; + if(KviQString::equalCI(szMode,"FreeResize")) r = QLayout::SetNoConstraint; + else if(KviQString::equalCI(szMode,"Minimum")) r = QLayout::SetMinimumSize; + else if(KviQString::equalCI(szMode,"Fixed"))r = QLayout::SetFixedSize; + else c->warning(__tr2qs_ctx("Invalid resize mode defaulting to Auto","objects")); + ((QGridLayout *)object())->setSizeConstraint(r); + return true; + +} + +KVSO_CLASS_FUNCTION(layout,setAlignment) +{ + CHECK_INTERNAL_POINTER(widget()) + QStringList alignment; + KviKvsObject * pObject; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("alignment",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,alignment) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + CHECK_HOBJECT_IS_WIDGET(pObject) + int index=((QGridLayout *)widget())->indexOf(((QWidget *)(pObject->object()))); + if(index ==-1) + { + c->warning(__tr2qs_ctx("The widget must be a child of this layout","objects")); + 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_ctx("Unknown alignment: '%Q'","objects"),&(*it)); + + } + if (widget()) ((QGridLayout *)widget())->setAlignment(((QWidget *)(pObject->object())),(Qt::Alignment)sum); + return true; +} +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_layout.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/KvsObject_layout.h b/src/modules/objects/KvsObject_layout.h new file mode 100644 index 000000000..65580e99e --- /dev/null +++ b/src/modules/objects/KvsObject_layout.h @@ -0,0 +1,53 @@ +#ifndef _CLASS_LAYOUT_H_ +#define _CLASS_LAYOUT_H_ +//============================================================================= +// +// File : KvsObject_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-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "object_macros.h" + +class KvsObject_layout : public KviKvsObject +{ +public: + KVSO_DECLARE_OBJECT(KvsObject_layout) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool addWidget(KviKvsObjectFunctionCall *c); + bool addMultiCellWidget(KviKvsObjectFunctionCall *c); + bool setRowStretch(KviKvsObjectFunctionCall *c); + bool setColumnStretch(KviKvsObjectFunctionCall *c); + bool setMargin(KviKvsObjectFunctionCall *c); + bool setSpacing(KviKvsObjectFunctionCall *c); + bool addRowSpacing(KviKvsObjectFunctionCall *c); + bool addColSpacing(KviKvsObjectFunctionCall *c); + bool setResizeMode(KviKvsObjectFunctionCall *c); + bool setAlignment(KviKvsObjectFunctionCall *c); + + +}; + + +#endif //_CLASS_LAYOUT_H_ diff --git a/src/modules/objects/KvsObject_lcd.cpp b/src/modules/objects/KvsObject_lcd.cpp new file mode 100644 index 000000000..ab4664bdc --- /dev/null +++ b/src/modules/objects/KvsObject_lcd.cpp @@ -0,0 +1,191 @@ +//============================================================================= +// +// File : KvsObject_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) 2005 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_lcd.h" +#include "KviError.h" +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KviIconManager.h" + +#include + +/* + @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: $displayStr() + Displays the number represented by the string s. + !fn: $displayInt() + Sets the displayed value rounded to the nearest integer to number. + !fn: $displayDouble() + 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(KvsObject_lcd,"lcdnumber","widget") + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lcd,displayStr) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lcd,displayInt) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lcd,displayDouble) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lcd,setMode) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lcd,setSegmentStyle) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lcd,setNumDigits) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lcd,setSmallDecimalPoint) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lcd,checkOverflow) +KVSO_END_REGISTERCLASS(KvsObject_lcd) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_lcd,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_lcd) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_lcd) + +KVSO_END_CONSTRUCTOR(KvsObject_lcd) + +bool KvsObject_lcd::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT(QLCDNumber) + return true; +} + +KVSO_CLASS_FUNCTION(lcd,displayInt) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iDigit; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("number",KVS_PT_INT,0,iDigit) + KVSO_PARAMETERS_END(c) + ((QLCDNumber *)widget())->display((int)iDigit); + return true; +} + +KVSO_CLASS_FUNCTION(lcd,displayStr) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("number",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + ((QLCDNumber *)widget())->display(szText); + return true; +} + +KVSO_CLASS_FUNCTION(lcd,displayDouble) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_real_t dDigit; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("number",KVS_PT_DOUBLE,0,dDigit) + KVSO_PARAMETERS_END(c) + ((QLCDNumber *)widget())->display(dDigit); + return true; +} + +KVSO_CLASS_FUNCTION(lcd,setMode) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("mode",KVS_PT_STRING,0,szMode) + KVSO_PARAMETERS_END(c) + 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_ctx("Unknown mode '%Q'","objects"),&szMode); + return true; +} + +KVSO_CLASS_FUNCTION(lcd,setSegmentStyle) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szStyle; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("style",KVS_PT_STRING,0,szStyle) + KVSO_PARAMETERS_END(c) + 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_ctx("Unknown segment style '%Q'","objects"),&szStyle); + return true; +} + +KVSO_CLASS_FUNCTION(lcd,setNumDigits) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_real_t digit; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("digit",KVS_PT_DOUBLE,0,digit) + KVSO_PARAMETERS_END(c) + ((QLCDNumber *)widget())->setNumDigits((int)digit); + return true; +} + +KVSO_CLASS_FUNCTION(lcd,setSmallDecimalPoint) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bflag",KVS_PT_BOOLEAN,0,bFlag) + KVSO_PARAMETERS_END(c) + ((QLCDNumber *)widget())->setSmallDecimalPoint(bFlag); + return true; +} + +KVSO_CLASS_FUNCTION(lcd,checkOverflow) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_real_t iDigit; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("digit",KVS_PT_DOUBLE,0,iDigit) + KVSO_PARAMETERS_END(c) + c->returnValue()->setBoolean(((QLCDNumber *)widget())->checkOverflow(iDigit)); + return true; +} diff --git a/src/modules/objects/KvsObject_lcd.h b/src/modules/objects/KvsObject_lcd.h new file mode 100644 index 000000000..77c1fdc38 --- /dev/null +++ b/src/modules/objects/KvsObject_lcd.h @@ -0,0 +1,52 @@ +#ifndef _CLASS_LCD_H_ +#define _CLASS_LCD_H_ +//============================================================================= +// +// File : KvsObject_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) 2005 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_widget.h" + + +class KvsObject_lcd : public KvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KvsObject_lcd) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool displayStr(KviKvsObjectFunctionCall *c); + bool setMode(KviKvsObjectFunctionCall *c); + bool setSegmentStyle(KviKvsObjectFunctionCall *c); + bool setNumDigits(KviKvsObjectFunctionCall *c); + bool setSmallDecimalPoint(KviKvsObjectFunctionCall *c); + bool checkOverflow(KviKvsObjectFunctionCall *c); + bool displayInt(KviKvsObjectFunctionCall *c); + bool displayDouble(KviKvsObjectFunctionCall *c); +}; + +#endif // !_CLASS_LCD_H_ diff --git a/src/modules/objects/KvsObject_lineEdit.cpp b/src/modules/objects/KvsObject_lineEdit.cpp new file mode 100644 index 000000000..be41500da --- /dev/null +++ b/src/modules/objects/KvsObject_lineEdit.cpp @@ -0,0 +1,543 @@ +//============================================================================= +// +// File : KvsObject_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) 2000 Krzysztof Godlewski +// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "KviError.h" +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KvsObject_lineEdit.h" +#include +#include +#include +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] + %ledit_example->$setInputMask( "+99 99 99 99 99;_" );[br] + %ledit_example->$setInputMask( "000.000.000.000;_" );[br] + %ledit_example->Ip Number Mask.[br] + %ledit_example->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. + !fn: $setCompleter(,) + Provides completions based on an stringlist. + Valid completion_mode are: + PopupCompletion: Current completions are displayed in a popup below the lineedit. + UnfilteredPopupCompletion: All possible completions are displayed in a popup window with the most likely suggestion selected. + InlineCompletion: Completions appear as selected text. + !fn: $disableCompleter() + Disable temporally the completer. + !fn: $enableCompleter() + Enable the completer. + !fn: $removeCompleter() + Remove the completer. + @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(KvsObject_lineEdit,"lineedit","widget") + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,text) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,setText) + + // completer + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,setCompleter) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,enableCompleter) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,disableCompleter) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,unsetCompleter) + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,maxLength) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,setMaxLength) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,frame) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,setCursorPosition) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,cursorPosition) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,setFrame) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,selectAll) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,setSelection) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,copy) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,cut) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,paste) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,echoMode) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,setEchoMode) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,clear) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,dragAndDrop) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,setInputMask) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,setReadOnly) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,returnPressedEvent) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,lostFocusEvent) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,textChangedEvent) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_lineEdit,setInputValidator) + + +KVSO_END_REGISTERCLASS(KvsObject_lineEdit) + + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_lineEdit,KvsObject_widget) +m_pCompleter=0; +KVSO_END_CONSTRUCTOR(KvsObject_lineEdit) + +KVSO_BEGIN_DESTRUCTOR(KvsObject_lineEdit) +if (m_pCompleter) +{ + delete m_pCompleter; + m_pCompleter=0; +} +KVSO_END_CONSTRUCTOR(KvsObject_lineEdit) + + +bool KvsObject_lineEdit::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT(QLineEdit) + + connect(widget(),SIGNAL(returnPressed()),this,SLOT(slotreturnPressed())); + connect(widget(),SIGNAL(editingFinished()),this,SLOT(slotlostFocus())); + connect(widget(),SIGNAL(textChanged(const QString & )),this,SLOT(slottextChanged(const QString & ))); + return true; +} + +KVSO_CLASS_FUNCTION(lineEdit,text) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setString(((QLineEdit *)widget())->text()); + return true; +} + +KVSO_CLASS_FUNCTION(lineEdit,setText) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + ((QLineEdit *)widget())->setText(szText); + return true; +} +KVSO_CLASS_FUNCTION(lineEdit,setInputValidator) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szReg; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("reg_expression",KVS_PT_STRING,0,szReg) + KVSO_PARAMETERS_END(c) + ((QLineEdit *)widget())->setValidator(new QRegExpValidator(QRegExp(szReg),((QLineEdit *)widget()))); + return true; +} +KVSO_CLASS_FUNCTION(lineEdit,maxLength) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QLineEdit *)widget())->maxLength()); + return true; +} + +KVSO_CLASS_FUNCTION(lineEdit,setMaxLength) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t iMaxlen; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("maxlen",KVS_PT_UNSIGNEDINTEGER,0,iMaxlen) + KVSO_PARAMETERS_END(c) + ((QLineEdit *)widget())->setMaxLength(iMaxlen); + return true; +} + +KVSO_CLASS_FUNCTION(lineEdit,frame) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setBoolean(((QLineEdit *)widget())->hasFrame()); + return true; +} + +KVSO_CLASS_FUNCTION(lineEdit,setFrame) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bFrame; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bframe",KVS_PT_BOOL,0,bFrame) + KVSO_PARAMETERS_END(c) + ((QLineEdit *)widget())->setFrame(bFrame); + return true; +} + +KVSO_CLASS_FUNCTION(lineEdit,cursorPosition) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QLineEdit *)widget())->cursorPosition()); + return true; +} + +KVSO_CLASS_FUNCTION(lineEdit,setCursorPosition) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t iPos; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("position",KVS_PT_UNSIGNEDINTEGER,0,iPos) + KVSO_PARAMETERS_END(c) + ((QLineEdit *)widget())->setCursorPosition(iPos); + return true; +} + +KVSO_CLASS_FUNCTION(lineEdit,selectAll) +{ + CHECK_INTERNAL_POINTER(widget()) + ((QLineEdit *)widget())->selectAll(); + return true; +} + +KVSO_CLASS_FUNCTION(lineEdit,setSelection) +{ + CHECK_INTERNAL_POINTER(widget()) + 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) + ((QLineEdit *)widget())->setSelection(uStart, uLen); + return true; +} + +KVSO_CLASS_FUNCTION(lineEdit,copy) +{ + CHECK_INTERNAL_POINTER(widget()) + ((QLineEdit *)widget())->copy(); + return true; +} + +KVSO_CLASS_FUNCTION(lineEdit,cut) +{ + CHECK_INTERNAL_POINTER(widget()) + ((QLineEdit *)widget())->cut(); + return true; +} + +KVSO_CLASS_FUNCTION(lineEdit,paste) +{ + CHECK_INTERNAL_POINTER(widget()) + ((QLineEdit *)widget())->paste(); + return true; +} + +KVSO_CLASS_FUNCTION(lineEdit,echoMode) +{ + CHECK_INTERNAL_POINTER(widget()) + 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; +} + +KVSO_CLASS_FUNCTION(lineEdit,setEchoMode) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("mode",KVS_PT_STRING,0,szMode) + KVSO_PARAMETERS_END(c) + 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_ctx("Unknown echo mode '%Q'","objects"),&szMode); + return true; +} + +KVSO_CLASS_FUNCTION(lineEdit,clear) +{ + CHECK_INTERNAL_POINTER(widget()) + ((QLineEdit *)widget())->clear(); + return true; +} + +//-| Grifisx & Noldor |-Start: +KVSO_CLASS_FUNCTION(lineEdit,dragAndDrop) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + ((QLineEdit *)widget())->setDragEnabled(bEnabled); + return true; +} + +KVSO_CLASS_FUNCTION(lineEdit,setReadOnly) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bReadonly",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + ((QLineEdit *)widget())->setReadOnly(bEnabled); + return true; +} + +KVSO_CLASS_FUNCTION(lineEdit,setInputMask) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szMask; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("mask",KVS_PT_STRING,0,szMask) + KVSO_PARAMETERS_END(c) + ((QLineEdit *)widget())->setInputMask(szMask); + return true; +} + +KVSO_CLASS_FUNCTION(lineEdit,setCompleter) +{ + CHECK_INTERNAL_POINTER(widget()) + QStringList szCompletionList; + QString szMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("mode",KVS_PT_STRING,KVS_PF_OPTIONAL,szMode) + KVSO_PARAMETER("completion_list",KVS_PT_STRINGLIST,0,szCompletionList) + KVSO_PARAMETERS_END(c) + if(m_pCompleter) + { + delete m_pCompleter; + + } + m_pCompleter=new QCompleter(szCompletionList); + QCompleter::CompletionMode mode=QCompleter::PopupCompletion; + if(KviQString::equalCI(szMode,"InlineCompletion")) mode=QCompleter::InlineCompletion; + else if(KviQString::equalCI(szMode,"UnfilteredPopupCompletion")) mode=QCompleter::UnfilteredPopupCompletion; + else if(!KviQString::equalCI(szMode,"PopupCompletion")) + c->warning(__tr2qs_ctx("Unkonwn '%Q' completition mode, switching to default popupCompletition","objects"),&szMode); + m_pCompleter->setCompletionMode(mode); + ((QLineEdit *)widget())->setCompleter(m_pCompleter); + return true; +} +KVSO_CLASS_FUNCTION(lineEdit,enableCompleter) +{ + CHECK_INTERNAL_POINTER(widget()) + if (m_pCompleter) ((QLineEdit *)widget())->setCompleter(m_pCompleter); + return true; +} +KVSO_CLASS_FUNCTION(lineEdit,disableCompleter) +{ + CHECK_INTERNAL_POINTER(widget()) + ((QLineEdit *)widget())->setCompleter(0); + return true; +} +KVSO_CLASS_FUNCTION(lineEdit,unsetCompleter) +{ + CHECK_INTERNAL_POINTER(widget()) + if (m_pCompleter){ + ((QLineEdit *)widget())->setCompleter(0); + delete m_pCompleter; + m_pCompleter=0; + } + return true; +} + + +KVSO_CLASS_FUNCTION(lineEdit,returnPressedEvent) +{ + emitSignal("returnPressed",c); + return true; +} + +void KvsObject_lineEdit::slotreturnPressed() +{ + KviKvsVariantList * params = 0; + callFunction(this,"returnPressedEvent",params); + +} + +KVSO_CLASS_FUNCTION(lineEdit,lostFocusEvent) +{ + emitSignal("lostFocus",c); + return true; +} + +void KvsObject_lineEdit::slotlostFocus() +{ + KviKvsVariantList * params = 0; + callFunction(this,"lostFocusEvent",params); +} + +KVSO_CLASS_FUNCTION(lineEdit,textChangedEvent) +{ + emitSignal("textChanged",c,c->params()); + return true; + +} + +void KvsObject_lineEdit::slottextChanged(const QString &text) +{ + KviKvsVariantList params(new KviKvsVariant(text)); + callFunction(this,"textChangedEvent",¶ms); +} + + + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_lineEdit.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES + diff --git a/src/modules/objects/KvsObject_lineEdit.h b/src/modules/objects/KvsObject_lineEdit.h new file mode 100644 index 000000000..f561bf682 --- /dev/null +++ b/src/modules/objects/KvsObject_lineEdit.h @@ -0,0 +1,90 @@ +#ifndef _CLASS_LINEEDIT_H_ +#define _CLASS_LINEEDIT_H_ +//============================================================================= +// +// File : KvsObject_lineEdit.h +// 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) 2000 Krzysztof Godlewski +// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + + + +#include "KvsObject_widget.h" + +//#warning "Signals !" +#include +#include "object_macros.h" + +class KvsObject_lineEdit : public KvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_lineEdit) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + QCompleter * m_pCompleter; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool setCompleter(KviKvsObjectFunctionCall *c); + bool enableCompleter(KviKvsObjectFunctionCall *c); + bool disableCompleter(KviKvsObjectFunctionCall *c); + bool unsetCompleter(KviKvsObjectFunctionCall *c); + + bool text(KviKvsObjectFunctionCall *c); + bool setText(KviKvsObjectFunctionCall *c); + bool maxLength(KviKvsObjectFunctionCall *c); + bool setMaxLength(KviKvsObjectFunctionCall *c); + bool frame(KviKvsObjectFunctionCall *c); + bool setCursorPosition(KviKvsObjectFunctionCall *c); + bool cursorPosition(KviKvsObjectFunctionCall *c); + bool setFrame(KviKvsObjectFunctionCall *c); + bool selectAll(KviKvsObjectFunctionCall *c); + bool setSelection(KviKvsObjectFunctionCall *c); + bool copy(KviKvsObjectFunctionCall *c); + bool cut(KviKvsObjectFunctionCall *c); + + bool paste(KviKvsObjectFunctionCall *c); + bool echoMode(KviKvsObjectFunctionCall *c); + bool setEchoMode(KviKvsObjectFunctionCall *c); + bool clear(KviKvsObjectFunctionCall *c); + bool dragAndDrop(KviKvsObjectFunctionCall *c); + bool setInputMask(KviKvsObjectFunctionCall *c); + bool setReadOnly(KviKvsObjectFunctionCall *c); + + bool returnPressedEvent(KviKvsObjectFunctionCall *c); + + bool lostFocusEvent(KviKvsObjectFunctionCall *c); + + bool textChangedEvent(KviKvsObjectFunctionCall *c); + + + bool setInputValidator(KviKvsObjectFunctionCall *c); +protected slots: + void slotreturnPressed(); + void slotlostFocus(); + void slottextChanged(const QString &); + +}; + + +#endif // ! _CLASS_LINEEDIT_H_ diff --git a/src/modules/objects/KvsObject_list.cpp b/src/modules/objects/KvsObject_list.cpp new file mode 100644 index 000000000..a07b3a3e2 --- /dev/null +++ b/src/modules/objects/KvsObject_list.cpp @@ -0,0 +1,342 @@ +//============================================================================= +// +// File : KvsObject_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) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================ + +#include "kvi_debug.h" +#include "KviMemory.h" +#include "KviLocale.h" +#include "KvsObject_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 successfully 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 successfully removed (the list was not empty) + and $false otherwise. + + !fn: $removeLast() + Removes the last item from the list. Returns $true + if the item was successfully removed (the list was not empty) + and $false otherwise. + + !fn: $removeCurrent() + Removes the current item from the list. Returns $true + if the item was successfully 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(KvsObject_list,"list","object") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,count) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,isEmpty) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,clear) + KVSO_REGISTER_HANDLER(KvsObject_list,"removeAll",clear) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,append) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,prepend) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,insert) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,insert) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,at) + KVSO_REGISTER_HANDLER(KvsObject_list,"item",at) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,remove) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,removeFirst) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,removeLast) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,removeCurrent) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,moveFirst) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,moveNext) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,movePrev) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,moveLast) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,sort) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,eof) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_list,current) +KVSO_END_REGISTERCLASS(KvsObject_list) + + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_list,KviKvsObject) + m_pDataList = new KviPointerList; + m_pDataList->setAutoDelete(true); + m_pDataList->first(); +KVSO_END_CONSTRUCTOR(KvsObject_list) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_list) +delete m_pDataList; +m_pDataList = 0; +KVSO_END_CONSTRUCTOR(KvsObject_list) + +KVSO_CLASS_FUNCTION(list,current) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + if(!m_pDataList->count()) + { + c->returnValue()->setNothing(); + return true; + } + KviKvsVariant * v = m_pDataList->safeCurrent(); + if(v)c->returnValue()->copyFrom(*v); + else c->returnValue()->setNothing(); + return true; +} + +KVSO_CLASS_FUNCTION(list,eof) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + c->returnValue()->setBoolean(m_pDataList->current() != 0); + return true; +} + +KVSO_CLASS_FUNCTION(list,moveLast) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + c->returnValue()->setBoolean(m_pDataList->last() != 0); + return true; +} + +KVSO_CLASS_FUNCTION(list,movePrev) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + c->returnValue()->setBoolean(m_pDataList->prev() != 0); + return true; +} + +KVSO_CLASS_FUNCTION(list,moveNext) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + c->returnValue()->setBoolean(m_pDataList->next() != 0); + return true; +} + +KVSO_CLASS_FUNCTION(list,moveFirst) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + c->returnValue()->setBoolean(m_pDataList->first() != 0); + return true; +} + +KVSO_CLASS_FUNCTION(list,removeLast) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + c->returnValue()->setBoolean(m_pDataList->removeLast()); + return true; +} + +KVSO_CLASS_FUNCTION(list,removeCurrent) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + if(m_pDataList->count()) + { + m_pDataList->removeCurrent(); + c->returnValue()->setBoolean(true); + } else { + c->returnValue()->setBoolean(false); + } + return true; +} + +KVSO_CLASS_FUNCTION(list,removeFirst) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + c->returnValue()->setBoolean(m_pDataList->removeFirst()); + return true; +} + +KVSO_CLASS_FUNCTION(list,remove) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UINT,0,uIndex) + KVSO_PARAMETERS_END(c) + c->returnValue()->setBoolean(m_pDataList->remove(uIndex)); + return true; +} + +KVSO_CLASS_FUNCTION(list,at) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UINT,0,uIndex) + KVSO_PARAMETERS_END(c) + KviKvsVariant * v = m_pDataList->at(uIndex); + if(v)c->returnValue()->copyFrom(*v); + else c->returnValue()->setNothing(); + return true; +} + +KVSO_CLASS_FUNCTION(list,insert) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + 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) + m_pDataList->insert(uIndex,new KviKvsVariant(*pVar)); + return true; +} + +KVSO_CLASS_FUNCTION(list,prepend) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + KviKvsVariant * pVar; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("item",KVS_PT_VARIANT,0,pVar) + KVSO_PARAMETERS_END(c) + m_pDataList->prepend(new KviKvsVariant(*pVar)); + return true; +} + +KVSO_CLASS_FUNCTION(list,append) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + KviKvsVariant * pVar; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("item",KVS_PT_VARIANT,0,pVar) + KVSO_PARAMETERS_END(c) + m_pDataList->append(new KviKvsVariant(*pVar)); + if (m_pDataList->count()==1) m_pDataList->first(); + return true; +} + +KVSO_CLASS_FUNCTION(list,clear) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + m_pDataList->clear(); + return true; +} + +inline int kvi_compare(const KviKvsVariant * p1,const KviKvsVariant * p2) +{ + return p1->compare(p2); +} + +KVSO_CLASS_FUNCTION(list,sort) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + m_pDataList->sort(); + return true; +} + +KVSO_CLASS_FUNCTION(list,isEmpty) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + c->returnValue()->setBoolean(m_pDataList->isEmpty()); + return true; +} + +KVSO_CLASS_FUNCTION(list,count) +{ + CHECK_INTERNAL_POINTER(m_pDataList) + c->returnValue()->setInteger(m_pDataList->count()); + return true; +} + diff --git a/src/modules/objects/KvsObject_list.h b/src/modules/objects/KvsObject_list.h new file mode 100644 index 000000000..46a4c0c4b --- /dev/null +++ b/src/modules/objects/KvsObject_list.h @@ -0,0 +1,64 @@ +#ifndef _CLASS_LIST_H_ +#define _CLASS_LIST_H_ +//============================================================================= +// +// File : KvsObject_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-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "kvi_settings.h" +#include "KviCString.h" +#include "KviPointerList.h" +#include "KviKvsVariant.h" +#include "object_macros.h" + + +class KvsObject_list : public KviKvsObject +{ +public: + KVSO_DECLARE_OBJECT(KvsObject_list) +protected: + KviPointerList * m_pDataList; +protected: + KviPointerList * dataList() const { return m_pDataList; }; +public: + bool count(KviKvsObjectFunctionCall *c); + bool isEmpty(KviKvsObjectFunctionCall *c); + bool clear(KviKvsObjectFunctionCall *c); + bool append(KviKvsObjectFunctionCall *c); + bool prepend(KviKvsObjectFunctionCall *c); + bool insert(KviKvsObjectFunctionCall *c); + bool at(KviKvsObjectFunctionCall *c); + bool remove(KviKvsObjectFunctionCall *c); + bool removeFirst(KviKvsObjectFunctionCall *c); + bool removeLast(KviKvsObjectFunctionCall *c); + bool removeCurrent(KviKvsObjectFunctionCall *c); + bool moveFirst(KviKvsObjectFunctionCall *c); + bool moveNext(KviKvsObjectFunctionCall *c); + bool movePrev(KviKvsObjectFunctionCall *c); + bool moveLast(KviKvsObjectFunctionCall *c); + bool eof(KviKvsObjectFunctionCall *c); + bool current(KviKvsObjectFunctionCall *c); + bool sort(KviKvsObjectFunctionCall *c); +}; + + +#endif //_CLASS_LIST_H_ diff --git a/src/modules/objects/KvsObject_listWidget.cpp b/src/modules/objects/KvsObject_listWidget.cpp new file mode 100644 index 000000000..773cfe0b4 --- /dev/null +++ b/src/modules/objects/KvsObject_listWidget.cpp @@ -0,0 +1,680 @@ +//============================================================================= +// +// File : KvsObject_listWidget.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-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "KviError.h" +#include "KviLocale.h" +#include "kvi_debug.h" +#include "KvsObject_list.h" +#include "KvsObject_listWidget.h" +#include "KvsObject_pixmap.h" +#include "KviIconManager.h" +#include + +const int item_flags[] = { + Qt::NoItemFlags, + Qt::ItemIsSelectable, + Qt::ItemIsEditable, + Qt::ItemIsDragEnabled, + Qt::ItemIsDropEnabled, + Qt::ItemIsUserCheckable, + Qt::ItemIsEnabled, + Qt::ItemIsTristate +}; + +const char * const itemflags_tbl[] = { + "noitemflag", + "selectable", + "editable", + "dragEnabled", + "dropEnabled", + "userCheckable", + "enabled", + "tristate" +}; + +#define itemflags_num (sizeof(itemflags_tbl) / sizeof(itemflags_tbl[0])) + +/* + @doc:listbox + @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 listwidget 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: $setFlag(,, , ...) + Sets the flags for the item at index idz to the given flags. These determine whether the item can be selected or modified. This is often used to disable an item. + Supported flags are: + - noitemflag : no flag sets; + - selectable : item is selecatble; + - editable : item is editable; + - dragEnabled : item can dragged; + - dropEnabled : item can used as drop target; + - userCheckable : item is checkable; + - enabled :item is enabled; + - tristate : item is checkable with three separate states. + !fn: $setChecked() + Sets the eventual item check box 'checked state' to . + !fn: $isChecked() + Returns '1' if the eventual item check box is checked, '0' otherwise.[br] + !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: $setFont(,,[,, , ...]) + Set the font's family, size and style, at index ; valid flag for style are:[br] + italic, bold, underline, overline, strikeout, fixedpitch [br] + If you just want to set a style without altering the preset font size and family, you can use $setFont() like this:[br] + %widget->$setFont(0,0,"bold") + !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. + !fn: $itemEnteredEvent() + This function is called by KVIrc when the mouse cursor enters an item. + !fn: $selectionChangedEvent() + This function is called by KVIrc when the selection in the listbox changes. + !fn: $currentItemChangedEvent() + This function is called by KVIrc when the current item changes. + !fn: $itemChangedEvent() + This function is called by KVIrc when the current data item changes (i.e. the user check a ckeckable item) . + + @signals: + !sg: $currentItemChanged() + This signal is emitted by the default implementation of [classfnc]$currentItemChangedEvent[/classfnc]().[br] + !sg: $itemChanged() + This signal is emitted by the default implementation of [classfnc]$itemChangedEvent[/classfnc]().[br] + !sg: $itemEntered() + This signal is emitted by the default implementation of [classfnc]$itemEnteredEvent[/classfnc]().[br] + !sg: $selectionChanged() + This signal is emitted by the default implementation of [classfnc]$selectionChangedEvent[/classfnc]().[br] + */ + + +KVSO_BEGIN_REGISTERCLASS(KvsObject_listWidget,"listbox","widget") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,insertItem) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,insertWidgetItem) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,changeItem) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,removeItem) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,clear) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,count) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,currentText) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,currentItem) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,textAt); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,itemAt); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,itemRect); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,setCurrentItem); + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,selectedItems); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,setSelected); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,isSelected); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,setFont); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,setIcon); + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,setFlags) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,setChecked); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,isChecked); + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,setSelectionMode); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,selectionMode); + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,setForeground); + + // events + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,currentItemChangedEvent); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,itemChangedEvent); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_listWidget,itemEnteredEvent); + KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KvsObject_listWidget,"selectionChangedEvent") + + +KVSO_END_REGISTERCLASS(KvsObject_listWidget) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_listWidget,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_listWidget) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_listWidget) + +KVSO_END_CONSTRUCTOR(KvsObject_listWidget) + +bool KvsObject_listWidget::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT(QListWidget) + obj->setSelectionMode(QAbstractItemView::SingleSelection); + connect(obj,SIGNAL(itemSelectionChanged()),this,SLOT(selectionChanged())); + connect(obj,SIGNAL(currentItemChanged(QListWidgetItem *,QListWidgetItem *)),this,SLOT(currentItemChanged(QListWidgetItem *,QListWidgetItem *))); + connect(obj,SIGNAL(itemEntered(QListWidgetItem *)),this,SLOT(slotItemEntered(QListWidgetItem *))); + connect(obj,SIGNAL(itemChanged(QListWidgetItem *)),this,SLOT(slotItemChanged(QListWidgetItem *))); + + return true; +} + +KVSO_CLASS_FUNCTION(listWidget,insertItem) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iRow; + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETER("index",KVS_PT_INT,KVS_PF_OPTIONAL,iRow) + KVSO_PARAMETERS_END(c) + if (c->parameterCount()==2) ((QListWidget *)widget())->insertItem(iRow, szText); + else ((QListWidget *)widget())->addItem(szText); + return true; +} + +KVSO_CLASS_FUNCTION(listWidget,setFlags) +{ + CHECK_INTERNAL_POINTER(widget()) + QStringList itemflags; + kvs_uint_t iIdx; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,iIdx) + KVSO_PARAMETER("flags",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,itemflags) + KVSO_PARAMETERS_END(c) + int flag,sum=0; + QListWidgetItem *pItem=((QListWidget *)widget())->item(iIdx); + if(!pItem) return true; + for ( int i=0;isetCheckState(Qt::Unchecked); + sum = sum | flag; + } + else + c->warning(__tr2qs_ctx("Unknown item flag '%Q'","objects"),&itemflags.at(i)); + } + pItem->setFlags((Qt::ItemFlags)sum); + return true; +} +KVSO_CLASS_FUNCTION(listWidget,setChecked) +{ + bool bChecked; + kvs_uint_t iIdx; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,iIdx) + KVSO_PARAMETER("bChecked",KVS_PT_BOOL,0,bChecked) + KVSO_PARAMETERS_END(c) + QListWidgetItem *pItem=((QListWidget *)widget())->item(iIdx); + if(!pItem) return true; + pItem->setCheckState(bChecked?Qt::Checked:Qt::Unchecked); + return true; +} + +KVSO_CLASS_FUNCTION(listWidget,isChecked) +{ + kvs_uint_t iIdx; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,iIdx) + KVSO_PARAMETERS_END(c) + QListWidgetItem *pItem=((QListWidget *)widget())->item(iIdx); + if(!pItem) return true; + c->returnValue()->setBoolean(pItem->checkState()==Qt::Checked?1:0); + return true; +} + +KVSO_CLASS_FUNCTION(listWidget,setFont) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szFamily; + QStringList szListStyle; + kvs_int_t iSize,iIdx; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_INTEGER,0,iIdx) + KVSO_PARAMETER("size",KVS_PT_INTEGER,0,iSize) + KVSO_PARAMETER("family",KVS_PT_STRING,0,szFamily) + KVSO_PARAMETER("style",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,szListStyle) + KVSO_PARAMETERS_END(c) + QListWidgetItem *pItem=((QListWidget *)widget())->item(iIdx); + if(!pItem) return true; + QFont font=widget()->font(); + if(!szFamily.isEmpty()) font.setFamily(szFamily); + if(iSize) font.setPointSize(iSize); + QString szStyle; + for(int i=0;iwarning(__tr2qs_ctx("Unknown style '%Q'","objects"),&szStyle); + } + pItem->setFont(font); + return true; +} +KVSO_CLASS_FUNCTION(listWidget,setIcon) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uIdx; + KviKvsObject *obPixmap; + kvs_hobject_t obHpixmap; + KviKvsVariant * vPixmap; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uIdx) + KVSO_PARAMETER("pixmap",KVS_PT_VARIANT,0,vPixmap) + KVSO_PARAMETERS_END(c) + QListWidgetItem *pItem=((QListWidget *)widget())->item(uIdx); + if(!pItem) return true; + + QPixmap *pix = 0; + if (vPixmap->isEmpty()) {pItem->setIcon(QIcon());return true;} + if(vPixmap->isHObject()) + { + vPixmap->asHObject(obHpixmap); + obPixmap=KviKvsKernel::instance()->objectController()->lookupObject(obHpixmap); + if (!obPixmap->inheritsClass("pixmap")) + { + c->warning(__tr2qs_ctx("Pixmap object or image Id required","objects")); + return true; + } + pix=((KvsObject_pixmap *)obPixmap)->getPixmap(); + } else { + QString szPix; + vPixmap->asString(szPix); + pix=g_pIconManager->getImage(szPix); + if(!pix) + { + c->warning(__tr2qs_ctx("Error occured: the suitable file '%Q' is not of the correct format or it is not a valid icon number.","objects"),&szPix); + return true; + } + } + if(pix){ + pItem->setIcon(*pix); + } + else{ + pItem->setIcon(QIcon()); + } + return true; +} +KVSO_CLASS_FUNCTION(listWidget,setForeground) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iCol1,iCol2,iCol3,iOpacity,iIdx; + QString szColorMode,szColor; + KviKvsVariant *var1,*var2,*var3; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_INTEGER,0,iIdx) + KVSO_PARAMETER("Color_1_Or_Colorname",KVS_PT_VARIANT,0,var1) + KVSO_PARAMETER("Color_2",KVS_PT_VARIANT,KVS_PF_OPTIONAL,var2) + KVSO_PARAMETER("Colo3_3",KVS_PT_VARIANT,KVS_PF_OPTIONAL,var3) + KVSO_PARAMETER("color_mode",KVS_PT_STRING,KVS_PF_OPTIONAL,szColorMode) + KVSO_PARAMETER("opacity",KVS_PT_INT,KVS_PF_OPTIONAL,iOpacity) + KVSO_PARAMETERS_END(c) + QListWidgetItem *pItem=((QListWidget *)widget())->item(iIdx); + if(!pItem) return true; + QColor col; + if (!var1->asInteger(iCol1)) + { + var1->asString(szColor); + if (c->paramCount()<3) iOpacity=255; + else + { + if (!var2->asInteger(iOpacity)) + { + c->warning(__tr2qs_ctx("The opacity parameter didn't evaluate to integer","objects")); + return true; + } + } + col.setNamedColor(szColor); + col.setAlpha(iOpacity); + } + else + { + if(c->paramCount()<4) + { + c->error(__tr2qs_ctx("Color name or triplette rgb/hsv value required","objects")); + return true; + } + if (!var2->asInteger(iCol2)||!var3->asInteger(iCol3)) + { + c->error(__tr2qs_ctx("One of the triplette parameters didn't evaluate to an integer","objects"));\ + return true; + } + if (c->paramCount()<5) iOpacity=255; + if(KviQString::equalCI(szColorMode, "HSV")) + col.setHsv(iCol1,iCol2,iCol3,iOpacity); + else + col.setRgb(iCol1,iCol2,iCol3,iOpacity); + } + QBrush brush=pItem->foreground(); + brush.setColor(col); + pItem->setForeground(brush); + return true; +} +KVSO_CLASS_FUNCTION(listWidget,clear) +{ + CHECK_INTERNAL_POINTER(widget()) + ((QListWidget *)widget())->clear(); + return true; +} + +KVSO_CLASS_FUNCTION(listWidget,changeItem) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t iIndex,cnt; + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,iIndex) + KVSO_PARAMETERS_END(c) + if (szText.isEmpty()) c->warning(__tr2qs_ctx("No string parameter given - using empty string","objects")); + if(iIndex >= (cnt = ((QListWidget *)widget())->count())) + { + c->warning(__tr2qs_ctx("Item index [%d] is too big - defaulting to " + "$count() - 1 [%d]","objects"), iIndex, cnt); + iIndex = cnt - 1; + } + ((QListWidget *)widget())->item(iIndex)->setText(szText); + return true; +} + + +KVSO_CLASS_FUNCTION(listWidget,removeItem) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t iIndex,cnt; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,iIndex) + KVSO_PARAMETERS_END(c) + if(iIndex >= (cnt = ((QListWidget *)widget())->count())) + { + c->warning(__tr2qs_ctx("Item index [%d] is too big - defaulting to " \ + "$count() - 1 [%d]","objects"), iIndex, cnt); + iIndex = cnt - 1; + } + delete ((QListWidget *)widget())->takeItem(iIndex); + return true; +} + +KVSO_CLASS_FUNCTION(listWidget,count) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QListWidget *)widget())->count()); + return true; +} +KVSO_CLASS_FUNCTION(listWidget,currentText) +{ + CHECK_INTERNAL_POINTER(widget()) + QString text; + QListWidgetItem *item=((QListWidget *)widget())->currentItem(); + if (item) text=item->text(); + else text=""; + c->returnValue()->setString(text); + return true; +} +KVSO_CLASS_FUNCTION(listWidget,currentItem) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QListWidget *)widget())->currentRow()); + return true; +} + +KVSO_CLASS_FUNCTION(listWidget,textAt) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t iIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,iIndex) + KVSO_PARAMETERS_END(c) + c->returnValue()->setString(((QListWidget *)widget())->item(iIndex)->text()); + return true; +} +KVSO_CLASS_FUNCTION(listWidget,setCurrentItem) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t iIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,iIndex) + KVSO_PARAMETERS_END(c) + ((QListWidget *)widget())->setCurrentRow(iIndex); + return true; +} +KVSO_CLASS_FUNCTION(listWidget,setSelectionMode) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("selection_mode",KVS_PT_STRING,0,szMode) + KVSO_PARAMETERS_END(c) + QAbstractItemView::SelectionMode iMode = QAbstractItemView::SingleSelection; + if(KviQString::equalCI(szMode,"single")) iMode = QAbstractItemView::SingleSelection; + else if(KviQString::equalCI(szMode,"multi")) iMode = QAbstractItemView::MultiSelection; + else if(KviQString::equalCI(szMode,"extended")) iMode = QAbstractItemView::ExtendedSelection; + else if(KviQString::equalCI(szMode,"none")) iMode = QAbstractItemView::NoSelection; + else c->warning(__tr2qs_ctx("Invalid selection mode '%Q' assuming single","objects"),&szMode); + ((QListWidget *)widget())->setSelectionMode(iMode); + return true; +} +KVSO_CLASS_FUNCTION(listWidget,selectionMode) +{ + CHECK_INTERNAL_POINTER(widget()) + switch(((QListWidget *)widget())->selectionMode()) + { + case QAbstractItemView::SingleSelection: c->returnValue()->setString("single"); break; + case QAbstractItemView::MultiSelection: c->returnValue()->setString("multi"); break; + case QAbstractItemView::ExtendedSelection: c->returnValue()->setString("extended"); break; + case QAbstractItemView::NoSelection: c->returnValue()->setString("none"); break; + default: c->returnValue()->setString("single"); break; + } + return true; +} + +KVSO_CLASS_FUNCTION(listWidget,insertWidgetItem) +{ + CHECK_INTERNAL_POINTER(widget()) + KviKvsObject *pObject; + kvs_int_t iIndex; + kvs_hobject_t hWid; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hWid) + KVSO_PARAMETER("index",KVS_PT_INT,0,iIndex) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hWid); + if(pObject==this) + { + c->warning(__tr2qs_ctx("Can't insert the listwidget itself!","objects")); + return true; + } + if(!pObject->object()->isWidgetType()) + { + c->warning(__tr2qs_ctx("Can't insert a non-widget object","objects")); + return true; + } + QWidget *wi=((QWidget *)(pObject->object())); + QListWidgetItem *item=((QListWidget *)widget())->item(iIndex); + ((QListWidget *)widget())->setItemWidget(item,wi); + return true; +} +KVSO_CLASS_FUNCTION(listWidget,selectedItems) +{ + CHECK_INTERNAL_POINTER(widget()) + QList list=((QListWidget *)widget())->selectedItems(); + KviKvsArray * pArray = new KviKvsArray(); + c->returnValue()->setArray(pArray); + for (int i=0;irow(list.at(i)); + pArray->set(i,new KviKvsVariant(index)); + } + return true; +} + +KVSO_CLASS_FUNCTION(listWidget,setSelected) +{ + CHECK_INTERNAL_POINTER(widget()) + 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) + ((QListWidget *)widget())->item(uIndex)->setSelected(bSel); + return true; +} +KVSO_CLASS_FUNCTION(listWidget,isSelected) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + c->returnValue()->setBoolean(((QListWidget *)widget())->item(uIndex)->isSelected()); + return true; +} +KVSO_CLASS_FUNCTION(listWidget,itemAt) +{ + CHECK_INTERNAL_POINTER(widget()) + 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) + c->returnValue()->setInteger(((QListWidget *)widget())->row(((QListWidget *)widget())->itemAt(QPoint(uX,uY)))); + return true; +} +KVSO_CLASS_FUNCTION(listWidget,itemRect) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("iIndex",KVS_PT_UNSIGNEDINTEGER,0,uIndex) + KVSO_PARAMETERS_END(c) + QRect rect=((QListWidget *)widget())->visualItemRect(((QListWidget *)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; +} + +KVSO_CLASS_FUNCTION(listWidget,currentItemChangedEvent) +{ + emitSignal("currentItemChanged",c,c->params()); + return true; +} +KVSO_CLASS_FUNCTION(listWidget,itemChangedEvent) +{ + emitSignal("itemChanged",c,c->params()); + return true; +} + +KVSO_CLASS_FUNCTION(listWidget,itemEnteredEvent) +{ + emitSignal("itemEntered",c,c->params()); + + return true; +} + +//slots +void KvsObject_listWidget::currentItemChanged(QListWidgetItem *currentItem,QListWidgetItem *) +{ + if (!currentItem) callFunction(this,"currentItemChangedEvent",0,0); + else + { + KviKvsVariantList params(new KviKvsVariant(currentItem->text())); + callFunction(this,"currentItemChangedEvent",0,¶ms); + } + +} +void KvsObject_listWidget::selectionChanged() +{ + callFunction(this,"selectionChangedEvent",0,0); +} + + +void KvsObject_listWidget::slotItemEntered(QListWidgetItem *item) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)((QListWidget *)widget())->row(item))); + callFunction(this,"itemEnteredEvent",0,¶ms); +} + +void KvsObject_listWidget::slotItemChanged(QListWidgetItem *item) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)((QListWidget *)widget())->row(item))); + callFunction(this,"itemChangedEvent",0,¶ms); +} + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_listWidget.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES + diff --git a/src/modules/objects/KvsObject_listWidget.h b/src/modules/objects/KvsObject_listWidget.h new file mode 100644 index 000000000..3fb204488 --- /dev/null +++ b/src/modules/objects/KvsObject_listWidget.h @@ -0,0 +1,81 @@ +#ifndef _CLASS_LISTBOX_H_ +#define _CLASS_LISTBOX_H_ +//============================================================================= +// +// File : KvsObject_listWidget.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-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + + +#include "KvsObject_widget.h" +#include +#include "object_macros.h" + +class KvsObject_listWidget: public KvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_listWidget) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + + bool insertItem(KviKvsObjectFunctionCall *c); + bool changeItem(KviKvsObjectFunctionCall *c); + bool removeItem(KviKvsObjectFunctionCall *c); + bool count(KviKvsObjectFunctionCall *c); + bool currentText(KviKvsObjectFunctionCall *c); + bool currentItem(KviKvsObjectFunctionCall *c); + bool textAt(KviKvsObjectFunctionCall *c); + bool setCurrentItem(KviKvsObjectFunctionCall *c); + bool clear(KviKvsObjectFunctionCall *c); + bool setSelectionMode(KviKvsObjectFunctionCall *c); + bool selectionMode(KviKvsObjectFunctionCall *c); + bool insertWidgetItem(KviKvsObjectFunctionCall *c); + bool isSelected(KviKvsObjectFunctionCall *c); + bool setSelected(KviKvsObjectFunctionCall *c); + bool setFlags(KviKvsObjectFunctionCall *c); + bool selectedItems(KviKvsObjectFunctionCall *c); + bool setForeground(KviKvsObjectFunctionCall *c); + bool setIcon(KviKvsObjectFunctionCall *c); + bool setChecked(KviKvsObjectFunctionCall *c); + bool setFont(KviKvsObjectFunctionCall *c); + bool isChecked(KviKvsObjectFunctionCall *c); + bool itemAt(KviKvsObjectFunctionCall *c); + bool itemRect(KviKvsObjectFunctionCall *c); + + // events + bool currentItemChangedEvent(KviKvsObjectFunctionCall *c); + bool itemChangedEvent(KviKvsObjectFunctionCall *c); + bool itemEnteredEvent(KviKvsObjectFunctionCall *c); + +protected slots: + void selectionChanged(); + void currentItemChanged(QListWidgetItem *,QListWidgetItem *); + void slotItemEntered(QListWidgetItem *item); + void slotItemChanged(QListWidgetItem *item); + +}; + + +#endif // !_CLASS_COMBOBOX_H_ diff --git a/src/modules/objects/KvsObject_mainWindow.cpp b/src/modules/objects/KvsObject_mainWindow.cpp new file mode 100644 index 000000000..71844c67a --- /dev/null +++ b/src/modules/objects/KvsObject_mainWindow.cpp @@ -0,0 +1,101 @@ +//============================================================================= +// +// File : KvsObject_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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KviTalMainWindow.h" +#include "KvsObject_mainWindow.h" +#include "KviError.h" +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KviIconManager.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(KvsObject_mainWindow,"mainwindow","widget") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_mainWindow,setCentralWidget) + +KVSO_END_REGISTERCLASS(KvsObject_mainWindow) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_mainWindow,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_mainWindow) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_mainWindow) + +KVSO_END_CONSTRUCTOR(KvsObject_mainWindow) + +bool KvsObject_mainWindow::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + setObject(new KviTalMainWindow(parentScriptWidget(), getName().toUtf8().data()), true); + return true; +} + +KVSO_CLASS_FUNCTION(mainWindow,setCentralWidget) +{ + CHECK_INTERNAL_POINTER(widget()) + 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_ctx("Widget parameter is not an object","objects")); + return true; + } + if (!pObject->object()) + { + c->warning(__tr2qs_ctx("Widget parameter is not a valid object","objects")); + return true; + } + if(!pObject->inheritsClass("widget")) + { + c->warning(__tr2qs_ctx("Widget object required","objects")); + return TRUE; + } + ((KviTalMainWindow *)widget())->setCentralWidget(((QWidget *)(pObject->object()))); + return true; +} + diff --git a/src/modules/objects/KvsObject_mainWindow.h b/src/modules/objects/KvsObject_mainWindow.h new file mode 100644 index 000000000..11ad34645 --- /dev/null +++ b/src/modules/objects/KvsObject_mainWindow.h @@ -0,0 +1,46 @@ +#ifndef _CLASS_MAINWINDOW_H_ +#define _CLASS_MAINWINDOW_H_ +//============================================================================= +// +// File : KvsObject_mainWindow.h +// 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_widget.h" +#include "object_macros.h" + +class KvsObject_mainWindow : public KvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KvsObject_mainWindow) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool setCentralWidget(KviKvsObjectFunctionCall *c); +}; + + +#endif //!_CLASS_MAINWINDOW_H_ + diff --git a/src/modules/objects/KvsObject_memoryBuffer.cpp b/src/modules/objects/KvsObject_memoryBuffer.cpp new file mode 100644 index 000000000..e5947f448 --- /dev/null +++ b/src/modules/objects/KvsObject_memoryBuffer.cpp @@ -0,0 +1,125 @@ +//============================================================================= +// +// File : KvsObject_memoryBuffer.cpp +// Creation date : Fri Mar 18 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_memoryBuffer.h" + +#include "KviError.h" +#include "kvi_debug.h" +#include "kvi_settings.h" +#include "KviLocale.h" +#include "QProcess" +#include "KviFileUtils.h" +#include "KviFile.h" + +#include + +/* + @doc: memorybuffer + @keyterms: + object class + @title: + memorybuffer class + @type: + class + @short: + A class container to manage binary data. + @inherits: + [class]object[/class] + @description: + The memorybuffer class is used to storage binary data[br] + @functions: + !fn: $loadFromFile() + Load into memorybuffer the file. + !fn: $saveToFile() + Save the memorybuffer to file. + +*/ + +KVSO_BEGIN_REGISTERCLASS(KvsObject_memoryBuffer,"memorybuffer","object") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_memoryBuffer,loadFromFile); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_memoryBuffer,saveToFile); +KVSO_END_REGISTERCLASS(KvsObject_memoryBuffer) + + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_memoryBuffer,KviKvsObject) + + m_pBuffer = new QByteArray(); + +KVSO_END_CONSTRUCTOR(KvsObject_memoryBuffer) + +KVSO_BEGIN_DESTRUCTOR(KvsObject_memoryBuffer) + + delete m_pBuffer; + +KVSO_END_CONSTRUCTOR(KvsObject_memoryBuffer) + +KVSO_CLASS_FUNCTION(memoryBuffer,loadFromFile) +{ + CHECK_INTERNAL_POINTER(m_pBuffer) + QString szFileName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("filename",KVS_PT_NONEMPTYSTRING,0,szFileName) + KVSO_PARAMETERS_END(c) + if(KviFileUtils::fileExists(szFileName)) + { + + KviFile f(szFileName); + qDebug("loading file %s",szFileName.toUtf8().data()); + if (f.open(QIODevice::ReadOnly)) + { + m_pBuffer->resize(f.size()); + f.read(m_pBuffer->data(),f.size()); + f.close(); + } + else qDebug("Error in load file!"); + } + else c->warning(__tr2qs_ctx("The file '%Q' does not exist","objects"),&szFileName); + return true; +} +KVSO_CLASS_FUNCTION(memoryBuffer,saveToFile) +{ + CHECK_INTERNAL_POINTER(m_pBuffer) + QString szFileName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("filename",KVS_PT_NONEMPTYSTRING,0,szFileName) + KVSO_PARAMETERS_END(c) + KviFile f(szFileName); + if (f.open(QIODevice::WriteOnly)) + { + f.write(m_pBuffer->data(),m_pBuffer->size()); + f.close(); + } + else + { + c->warning(__tr2qs_ctx("Cannot open file '%Q' for writing","objects"),&szFileName); + } + return true; +} +/* +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_memoryBuffer.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES*/ + + diff --git a/src/modules/objects/KvsObject_memoryBuffer.h b/src/modules/objects/KvsObject_memoryBuffer.h new file mode 100644 index 000000000..0cd6fd388 --- /dev/null +++ b/src/modules/objects/KvsObject_memoryBuffer.h @@ -0,0 +1,53 @@ +#ifndef _CLASS_MEMORYBUFFER_H_ +#define _CLASS_MEMORYBUFFER_H_ +//============================================================================= +// +// File : KvsObject_memoryBuffer.h +// Creation date : Fri Mar 18 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "object_macros.h" + + + +class KvsObject_memoryBuffer : public KviKvsObject +{ +public: + KVSO_DECLARE_OBJECT(KvsObject_memoryBuffer) +protected: + QByteArray * m_pBuffer; +public: + QByteArray dataBuffer() + { + return *m_pBuffer; + }; + QByteArray *pBuffer() + { + return m_pBuffer; + }; + bool loadFromFile(KviKvsObjectFunctionCall *c); + bool saveToFile(KviKvsObjectFunctionCall *c); +}; + +#endif // !_CLASS_MEMORYBUFFER_H_ diff --git a/src/modules/objects/KvsObject_menuBar.cpp b/src/modules/objects/KvsObject_menuBar.cpp new file mode 100644 index 000000000..0a9904b2a --- /dev/null +++ b/src/modules/objects/KvsObject_menuBar.cpp @@ -0,0 +1,77 @@ +//============================================================================= +// +// File : KvsObject_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-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + + +#include "KvsObject_menuBar.h" +#include "KviError.h" +#include "kvi_debug.h" +#include "KviLocale.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(KvsObject_menuBar,"menubar","widget") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_menuBar,insertItem) +KVSO_END_REGISTERCLASS(KvsObject_menuBar) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_menuBar,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_menuBar) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_menuBar) + +KVSO_END_CONSTRUCTOR(KvsObject_menuBar) + +bool KvsObject_menuBar::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT(QMenuBar) + return true; +} + +KVSO_CLASS_FUNCTION(menuBar,insertItem) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szItem; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("item",KVS_PT_STRING,0,szItem) + KVSO_PARAMETERS_END(c) + ((QMenuBar *)widget())->addAction(szItem); + return true; +} diff --git a/src/modules/objects/KvsObject_menuBar.h b/src/modules/objects/KvsObject_menuBar.h new file mode 100644 index 000000000..64e9b62fb --- /dev/null +++ b/src/modules/objects/KvsObject_menuBar.h @@ -0,0 +1,42 @@ +#ifndef _CLASS_MENUBAR_H_ +#define _CLASS_MENUBAR_H_ +//============================================================================= +// +// File : KvsObject_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-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include +#include "KvsObject_widget.h" +#include "object_macros.h" + +class KvsObject_menuBar : public KvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KvsObject_menuBar) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool insertItem(KviKvsObjectFunctionCall *c); +}; +#endif // !_CLASS_MENUBAR_H_ diff --git a/src/modules/objects/KvsObject_multiLineEdit.cpp b/src/modules/objects/KvsObject_multiLineEdit.cpp new file mode 100644 index 000000000..e7df905e5 --- /dev/null +++ b/src/modules/objects/KvsObject_multiLineEdit.cpp @@ -0,0 +1,785 @@ +//============================================================================= +// +// File : KvsObject_multiLineEdit.cpp +// Creation date : Mon Feb 19 2000 00:45:34 CET by Krzysztof Godlewski +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2000 Krzysztof Godlewski +// Copyright (C) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KviError.h" +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KviMemory.h" + +#include +#include +#include +#include +#include +#include + +#include "KvsObject_multiLineEdit.h" + +/* + @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: $numLines() + Returns number of lines in the widget. + !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: $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: $isUndoRedoEnabled() + Returns 1 (TRUE) if undo/redo is enabled; otherwise returns 0 (FALSE). + !fn: $undoDepth() + Returns the depth of the undo history. + !fn: $setText() + Sets the text edit's text to txt. + !fn: $setColor() + 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. + -array(red:integer,green:integer,blue:integer) + -red:integer,green:integer,blue:integer. + !fn: $setPointSize() + Sets to 1 if you want that hypertext links will be underlined; otherwise sets to 0. + !fn: $setTextFormat() + Sets the text format. Correct values are RichText, PlainText. + !fn: $textFormat() + Returns the text format: rich text or plain text. + !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: $lines() + Returns the number of lines in the multilineedit. + !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: $setModified() + Sets whether the document has been modified by the user. Valid Values are 1(TRUE) or 0(FALSE) + !fn: $setAlignment() + Sets the alignment of the current paragraph to . Valid values are:[br] + - Auto - Aligns according to the language.[b + - Left - Aligns with the left edge.[br] + - Right - Aligns with the right edge.[br] + - Center - Centers in both dimensions. + - Justify - Justify the text. + */ + + +KVSO_BEGIN_REGISTERCLASS(KvsObject_textedit,"multilineedit","widget") + + KVSO_REGISTER_HANDLER(KvsObject_textedit,"textLine", functionTextLine) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"setWordWrap", functionSetWordWrap) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"wordWrap", functionWordWrap) + + KVSO_REGISTER_HANDLER(KvsObject_textedit,"atEnd", functionAtEnd) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"numLines", functionNumLines) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"atBeginning", functionAtBeginning) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"cursorPosition", functionCursorPosition) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"text", functionText) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"insert", functionInsert) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"maxLines", functionMaxLines) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"setMaxLines", functionSetMaxLines) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"append", functionAppend) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"copy", functionCopy) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"cut", functionCut) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"paste", functionPaste) + + //->Set Style + KVSO_REGISTER_HANDLER(KvsObject_textedit,"setFamily", functionsetFamily) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"setItalic", functionsetItalic) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"setBold", functionsetBold) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"setUnderline", functionsetUnderline) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"italic", functionitalic) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"bold", functionbold) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"underline", functionunderline) + + //->Zoom In, Out, To + KVSO_REGISTER_HANDLER(KvsObject_textedit,"zoomIn", functionzoomIn) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"zoomOut", functionzoomOut) + + //->Undo & Redo + KVSO_REGISTER_HANDLER(KvsObject_textedit,"undo", functionundo) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"redo", functionredo) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"clear", functionclear) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"setUndoRedoEnabled", functionsetUndoRedoEnabled) + + + KVSO_REGISTER_HANDLER(KvsObject_textedit,"isUndoRedoEnabled", functionisUndoRedoEnabled) + + //->Text color & others + KVSO_REGISTER_HANDLER(KvsObject_textedit,"setText", functionsetText) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"setColor", functionsetColor) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"setModified", functionsetModified) + + KVSO_REGISTER_HANDLER(KvsObject_textedit,"setPointSize", functionsetPointSize) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"setReadOnly",functionSetReadOnly) + + KVSO_REGISTER_HANDLER(KvsObject_textedit,"setTextFormat", functionsetTextFormat) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"textFormat", functiontextFormat) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"loadFile", functionloadFile); + KVSO_REGISTER_HANDLER(KvsObject_textedit,"setAlignment", functionsetAlignment) + + KVSO_REGISTER_HANDLER(KvsObject_textedit,"lines", functionlines) + KVSO_REGISTER_HANDLER(KvsObject_textedit,"selectAll", functionselectAll) +KVSO_END_REGISTERCLASS(KvsObject_textedit) + + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_textedit,KvsObject_widget) + + +KVSO_END_CONSTRUCTOR(KvsObject_textedit) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_textedit) + +KVSO_END_CONSTRUCTOR(KvsObject_textedit) + +bool KvsObject_textedit::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT(QTextEdit); + return true; +} + + + +bool KvsObject_textedit::functionSetReadOnly(KviKvsObjectFunctionCall * c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(widget()) + ((QTextEdit *)widget())->setReadOnly(bEnabled); + return true; +} + +bool KvsObject_textedit::functionTextLine(KviKvsObjectFunctionCall * c) +{ + kvs_int_t iBlock; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("line",KVS_PT_INT,0,iBlock) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + if(iBlock > ((QTextEdit *)widget())->document()->blockCount() || iBlock < 0) c->warning(__tr2qs_ctx("No such line '%d'","objects"),&iBlock); + else + c->returnValue()->setString(((QTextEdit *)widget())->document()->findBlockByNumber(iBlock).text()); + + return true; +} +bool KvsObject_textedit::functionNumLines(KviKvsObjectFunctionCall * c) +{ + if(widget()) c->returnValue()->setInteger(((QTextEdit *)widget())->document()->blockCount()); + return true; +} +bool KvsObject_textedit::functionCursorPosition(KviKvsObjectFunctionCall * c) +{ + if(!widget()) return true; + int iRow=((QTextEdit *)widget())->textCursor().blockNumber(); + int iCol=((QTextEdit *)widget())->textCursor().columnNumber(); + + KviKvsArray * a = new KviKvsArray(); + a->set(0,new KviKvsVariant((kvs_int_t)iRow)); + a->set(1,new KviKvsVariant((kvs_int_t)iCol)); + c->returnValue()->setArray(a); + return true; +} + +bool KvsObject_textedit::functionAtBeginning(KviKvsObjectFunctionCall * c) +{ + if(!widget()) return true; + c->returnValue()->setBoolean(((QTextEdit *)widget())->textCursor().atStart()); + return true; +} + +bool KvsObject_textedit::functionAtEnd(KviKvsObjectFunctionCall * c) +{ + if(!widget()) return true; + c->returnValue()->setBoolean(((QTextEdit *)widget())->textCursor().atEnd()); + return true; +} + +bool KvsObject_textedit::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")) + ((QTextEdit *)widget())->setLineWrapMode(QTextEdit::NoWrap); + else if(KviQString::equalCI(szWrap,"WidgetWidth")) + ((QTextEdit *)widget())->setLineWrapMode(QTextEdit::WidgetWidth); + else if(KviQString::equalCI(szWrap,"FixedPixelWidth")) + ((QTextEdit *)widget())->setLineWrapMode(QTextEdit::FixedPixelWidth); + else if(KviQString::equalCI(szWrap,"FixedColumnWidth")) + ((QTextEdit *)widget())->setLineWrapMode(QTextEdit::FixedColumnWidth); + else c->warning(__tr2qs_ctx("Unknown word wrap '%Q'","objects"),&szWrap); + return true; +} + + +bool KvsObject_textedit::functionWordWrap(KviKvsObjectFunctionCall *c) +{ + + if(!widget()) return true; + QTextEdit::LineWrapMode mode=((QTextEdit *)widget())->lineWrapMode(); + QString szWrapMode; + if (mode==QTextEdit::NoWrap) szWrapMode="NoWrap"; + else if (mode==QTextEdit::WidgetWidth) szWrapMode="WidgetWidth"; + else if (mode==QTextEdit::FixedPixelWidth) szWrapMode="FixedPixelWidth"; + else szWrapMode="FixedColumnWidth"; + c->returnValue()->setString(szWrapMode); + + return true; +} + +bool KvsObject_textedit::functionText(KviKvsObjectFunctionCall * c) +{ + if(widget()) + c->returnValue()->setString(((QTextEdit *)widget())->document()->toPlainText()); + return true; +} + +bool KvsObject_textedit::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()) + ((QTextEdit *)widget())->document()->setMaximumBlockCount(imaxLines); + return true; +} + +bool KvsObject_textedit::functionMaxLines(KviKvsObjectFunctionCall * c) +{ + if(widget()) + c->returnValue()->setInteger(((QTextEdit *)widget())->document()->maximumBlockCount()); + return true; +} + +bool KvsObject_textedit::functionInsert(KviKvsObjectFunctionCall * c) +{ + QString szInsert; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szInsert) + KVSO_PARAMETERS_END(c) + if (widget()) + { + QTextCursor cursor=((QTextEdit *)widget())->textCursor(); + cursor.insertText(szInsert); + ((QTextEdit *)widget())->setTextCursor(cursor); + } + return true; +} + +bool KvsObject_textedit::functionAppend(KviKvsObjectFunctionCall * c) +{ + QString szAppend; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szAppend) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QTextEdit *)widget())->append(szAppend); + return true; +} + +bool KvsObject_textedit::functionCopy(KviKvsObjectFunctionCall *) +{ + if(widget()) + ((QTextEdit *)widget())->copy(); + return true; +} + +bool KvsObject_textedit::functionCut(KviKvsObjectFunctionCall *) +{ + if(widget()) + ((QTextEdit *)widget())->cut(); + return true; +} + +bool KvsObject_textedit::functionPaste(KviKvsObjectFunctionCall *) +{ + if(widget()) + ((QTextEdit *)widget())->paste(); + return true; +} + +//->Set Bold, Italic, Underline +bool KvsObject_textedit::functionsetBold(KviKvsObjectFunctionCall * c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bBold",KVS_PT_BOOL,0,bFlag) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QTextEdit *)widget())->setFontWeight(bFlag?QFont::Bold:QFont::Normal); + return true; +} + +bool KvsObject_textedit::functionsetUnderline(KviKvsObjectFunctionCall * c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bUnderline",KVS_PT_BOOL,0,bFlag) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QTextEdit *)widget())->setFontUnderline(bFlag); + return true; +} + +bool KvsObject_textedit::functionsetItalic(KviKvsObjectFunctionCall * c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bItalic",KVS_PT_BOOL,0,bFlag) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QTextEdit *)widget())->setFontItalic(bFlag); + return true; +} + +//-->Returns Italic, Bold, Underline. +bool KvsObject_textedit::functionbold(KviKvsObjectFunctionCall * c) +{ + if(widget()) + c->returnValue()->setBoolean(((QTextEdit *)widget())->fontWeight() >= QFont::Bold ); + return true; +} + +bool KvsObject_textedit::functionitalic(KviKvsObjectFunctionCall * c) +{ + if(widget()) + c->returnValue()->setBoolean(((QTextEdit *)widget())->fontItalic()); + return true; +} + +bool KvsObject_textedit::functionunderline(KviKvsObjectFunctionCall * c) +{ + if(widget()) + c->returnValue()->setBoolean(((QTextEdit *)widget())->fontUnderline()); + return true; +} + +//->Zoom In, out at +bool KvsObject_textedit::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) + ((QTextEdit *)object())->zoomIn(); + else + ((QTextEdit *)object())->zoomIn(iZoom); + return true; +} + +bool KvsObject_textedit::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) + ((QTextEdit *)object())->zoomOut(); + else + ((QTextEdit *)object())->zoomOut(iZoom); + return true; +} + + + +//-> Undo & Redo functions +bool KvsObject_textedit::functionundo(KviKvsObjectFunctionCall *) +{ + if(widget()) + ((QTextEdit *)widget())->undo(); + return true; +} + +bool KvsObject_textedit::functionredo(KviKvsObjectFunctionCall *) +{ + if(widget()) + ((QTextEdit *)widget())->redo(); + return true; +} + +bool KvsObject_textedit::functionclear(KviKvsObjectFunctionCall *) +{ + if(widget()) + ((QTextEdit *)widget())->clear(); + return true; +} + + + +bool KvsObject_textedit::functionsetUndoRedoEnabled(KviKvsObjectFunctionCall * c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bUndoredo",KVS_PT_BOOL,0,bFlag) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QTextEdit *)widget())->setUndoRedoEnabled(bFlag); + return true; +} + +bool KvsObject_textedit::functionisUndoRedoEnabled(KviKvsObjectFunctionCall * c) +{ + if(widget()) + c->returnValue()->setBoolean(((QTextEdit *)widget())->isUndoRedoEnabled()); + return true; +} + + +//-->Text & Color & Family +bool KvsObject_textedit::functionsetText(KviKvsObjectFunctionCall * c) +{ + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QTextEdit *)widget())->setText(szText); + return true; +} + +bool KvsObject_textedit::functionsetPlainText(KviKvsObjectFunctionCall * c) +{ + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QTextEdit *)widget())->setPlainText(szText); + return true; +} + +bool KvsObject_textedit::functionsetHtmlText(KviKvsObjectFunctionCall * c) +{ + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QTextEdit *)widget())->setHtml(szText); + return true; +} + +bool KvsObject_textedit::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_ctx("The array passed as parameter must contain at least 3 elements","objects")); + 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_ctx("One of the colors array parameters is empty","objects")); + return false; + } + if(!(pColR->asInteger(iColR) && pColG->asInteger(iColG) && pColB->asInteger(iColB))) + { + c->error(__tr2qs_ctx("One of the colors array parameters didn't evaluate to an integer","objects")); + return false; + } + + } else { + if (c->params()->count()==1) + { + bool bOk,bOk1,bOk2; + QString value; + pColArray->asString(value); + if (value.length()!=6) + { + c->warning(__tr2qs_ctx("A string of 6 hex digits is required","objects")); + 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_ctx("Not an hex digit","objects")); + return true; + } + if (widget()) ((QTextEdit *)widget())->setTextColor(QColor(iColR,iColG,iColB)); + return true; + } + if(c->params()->count() < 3) + { + c->error(__tr2qs_ctx("$setColor requires either an array as first parameter or three integers","objects")); + return false; + } + if(!pColArray->asInteger(iColR)) + { + c->error(__tr2qs_ctx("The first parameter didn't evaluate to an array nor an integer","objects")); + return false; + } + } + if (widget()) ((QTextEdit *)widget())->setTextColor(QColor(iColR,iColG,iColB)); + return true; +} + +bool KvsObject_textedit::functionsetPointSize(KviKvsObjectFunctionCall * c) +{ + kvs_real_t dPointSize; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("point_size",KVS_PT_REAL,0,dPointSize) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QTextEdit *)widget())->setFontPointSize(dPointSize); + return true; +} + + + +bool KvsObject_textedit::functionsetFamily(KviKvsObjectFunctionCall * c) +{ + QString szFamily; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("family",KVS_PT_STRING,0,szFamily) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QTextEdit *)widget())->setFontFamily(szFamily); + return true; +} + +bool KvsObject_textedit::functionsetModified(KviKvsObjectFunctionCall * c) +{ + bool bFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bModified",KVS_PT_BOOL,0,bFlag) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QTextEdit *)widget())->document()->setModified(bFlag); + return true; +} + +bool KvsObject_textedit::functionModified(KviKvsObjectFunctionCall * c) +{ + if(widget()) + c->returnValue()->setBoolean(((QTextEdit *)widget())->document()->isModified()); + return true; +} + + +bool KvsObject_textedit::functiontextFormat(KviKvsObjectFunctionCall *c) +{ + if(!widget())return true; + if(((QTextEdit *)widget())->acceptRichText()) + c->returnValue()->setString(QString("RichText")); + else + c->returnValue()->setString(QString("PlainText")); + return true; +} + +bool KvsObject_textedit::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")) + ((QTextEdit *)widget())->setAcceptRichText(false); + else if(KviQString::equalCI(szFormat,"RichText")) + ((QTextEdit *)widget())->setAcceptRichText(true); + else c->warning(__tr2qs_ctx("Unknown text format '%Q'","objects"),&szFormat); + return true; +} + + + + +bool KvsObject_textedit::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_ctx("I can't find the specified file '%Q'.","objects"),&szFile); + return true; + } + + QFile file( szFile ); + if ( !file.open( QIODevice::ReadOnly ) ) + { + c->warning(__tr2qs_ctx("I cannot read the file '%Q'.","objects"),&szFile); + return true; + } + + QTextStream ts( &file ); + QString txt = ts.readAll(); + //settext tries to understand if the text is html or plain + ((QTextEdit *)widget())->setText( txt ); + + file.close(); + return true; +} + +bool KvsObject_textedit::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")) + ((QTextEdit *)widget())->setAlignment(Qt::AlignLeft); + else if(KviQString::equalCI(szAlignment,"Right")) + ((QTextEdit *)widget())->setAlignment(Qt::AlignRight); + else if(KviQString::equalCI(szAlignment,"Center")) + ((QTextEdit *)widget())->setAlignment(Qt::AlignCenter); + else if(KviQString::equalCI(szAlignment,"Justify")) + ((QTextEdit *)widget())->setAlignment(Qt::AlignJustify); + else c->warning(__tr2qs_ctx("Unknown alignment '%Q'","objects"),&szAlignment); + return true; +} + + + + +bool KvsObject_textedit::functionlines(KviKvsObjectFunctionCall * c) +{ + if(widget()) + c->returnValue()->setInteger(((QTextEdit *)widget())->document()->blockCount()); + return true; +} + + + + +bool KvsObject_textedit::functionselectAll(KviKvsObjectFunctionCall *) +{ + if (widget()) + ((QTextEdit *)widget())->selectAll(); + return true; +} + + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_multiLineEdit.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/KvsObject_multiLineEdit.h b/src/modules/objects/KvsObject_multiLineEdit.h new file mode 100644 index 000000000..aa264331a --- /dev/null +++ b/src/modules/objects/KvsObject_multiLineEdit.h @@ -0,0 +1,93 @@ +#ifndef _CLASS_MULTILINEEDIT_H_ +#define _CLASS_MULTILINEEDIT_H_ +//============================================================================= +// +// File : KvsObject_multiLineEdit.cpp +// Creation date : Mon Feb 19 2000 00:45:34 CET by Krzysztof Godlewski +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2000 Krzysztof Godlewski +// Copyright (C) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_widget.h" +#include "object_macros.h" + +class KvsObject_textedit : public KvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_textedit) +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 functionNumLines(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); + 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 functionundo(KviKvsObjectFunctionCall *c); + bool functionredo(KviKvsObjectFunctionCall *c); + bool functiondel(KviKvsObjectFunctionCall *c); + bool functionclear(KviKvsObjectFunctionCall *c); + bool functionsetUndoRedoEnabled(KviKvsObjectFunctionCall *c); + bool functionisUndoRedoEnabled(KviKvsObjectFunctionCall *c); + bool functionsetText(KviKvsObjectFunctionCall *c); + bool functionsetHtmlText(KviKvsObjectFunctionCall *c); + bool functionsetPlainText(KviKvsObjectFunctionCall *c); + bool functionsetPointSize(KviKvsObjectFunctionCall *c); + bool functionsetColor(KviKvsObjectFunctionCall *c); + bool functionisUndoAvailable(KviKvsObjectFunctionCall *c); + bool functionisRedoAvailable(KviKvsObjectFunctionCall *c); + bool functionsetFamily(KviKvsObjectFunctionCall *c); + bool functionsetTextFormat(KviKvsObjectFunctionCall *c); + bool functiontextFormat(KviKvsObjectFunctionCall *c); + bool functionloadFile(KviKvsObjectFunctionCall *c); + bool functionlines(KviKvsObjectFunctionCall *c); + bool functionselectAll(KviKvsObjectFunctionCall *c); + bool functionsetModified(KviKvsObjectFunctionCall *c); + bool functionModified(KviKvsObjectFunctionCall *c); + bool functionsetAlignment(KviKvsObjectFunctionCall *c); + +}; + +#endif //!_CLASS_MULTILINEEDIT_H_ diff --git a/src/modules/objects/KvsObject_painter.cpp b/src/modules/objects/KvsObject_painter.cpp new file mode 100644 index 000000000..a73d7924e --- /dev/null +++ b/src/modules/objects/KvsObject_painter.cpp @@ -0,0 +1,1738 @@ +//============================================================================= +// +// File : KvsObject_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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_painter.h" +#include "KvsObject_pixmap.h" +#include "KvsObject_widget.h" + +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KviError.h" +#include "KviIconManager.h" +#include "KviMemory.h" + #include +#include +#include + +#define PAINTER_ROTATE(__angle,__axis)\ + QTransform transform;\ + transform.rotate(__angle,__axis);\ + m_pPainter->setTransform(transform,true); + +#define PAINTER_TRANSLATE(__x,__y)\ + QTransform transform;\ + transform.translate(__x,__y);\ + m_pPainter->setTransform(transform,true); + +#define PAINTER_SHEAR(__sH,__sV)\ + QTransform transform;\ + transform.shear(__sH,__sV);\ + m_pPainter->setTransform(transform,true); + +#define PAINTER_SCALE(__sX,__sY)\ + QTransform transform;\ + transform.scale(__sX,__sY);\ + m_pPainter->setTransform(transform,true); + + +const Qt::PenStyle penstyles_cod[] = { + Qt::NoPen, + Qt::SolidLine, + Qt::DashLine, + Qt::DotLine, + Qt::DashDotLine, + Qt::DashDotDotLine +}; + +const char * const penstyles_tbl[] = { + "noPen", + "solidLine", + "dashLine", + "dotLine", + "dashDotLine", + "dashDotDotLine" +}; + +#define penstyles_num (sizeof(penstyles_tbl) / sizeof(penstyles_tbl[0])) + +const Qt::BrushStyle brushstyles_cod[] = { + Qt::NoBrush, + Qt::SolidPattern, + Qt::Dense1Pattern, + Qt::Dense2Pattern, + Qt::Dense3Pattern, + Qt::Dense4Pattern, + Qt::Dense5Pattern, + Qt::Dense6Pattern, + Qt::Dense7Pattern, + Qt::HorPattern, + Qt::VerPattern, + Qt::CrossPattern, + Qt::BDiagPattern, + Qt::FDiagPattern, + Qt::DiagCrossPattern +}; + +const char * const brushstyles_tbl[] = { + "NoBrush", + "SolidPattern", + "Dense1Pattern", + "Dense2Pattern", + "Dense3Pattern", + "Dense4Pattern", + "Dense5Pattern", + "Dense6Pattern", + "Dense7Pattern", + "HorPattern", + "VerPattern", + "CrossPattern", + "BDiagPattern", + "FDiagPattern", + "DiagCrossPattern" +}; + +#define brushstyles_num (sizeof(brushstyles_tbl) / sizeof(brushstyles_tbl[0])) + + +/* + @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: $beginPdf() + Begins painting on a file using the pdf format. + At present the pdf support is in experimental state. + !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. + !fn: $setPen(,,][,,],[opacity],[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: $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 family, size and style, 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 by the given angle about the optional parameter . + Valid values for axis are: ZAxis, XAxis, YAxis. + Optional parameter + !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() + 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() + Enable/disable antialias in text if possible. + You must call the [classfnc]$begin[/classfnc] before using it. + !fn: $setAntialiasing() + Enable/disable antialias in edges of primitives if possible. + You must call the [classfnc]$begin[/classfnc] before using it. + !fn: $setSmoothPixmapTransform() + 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->$setWindowTitle("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(KvsObject_painter,"painter","object") + + // Fonts + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setFont) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setFontSize) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,fontAscent) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,fontDescent) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,fontMetricsHeight) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,fontMetricsWidth) + + // Draws + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawRect) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawLine) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawRoundRect) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawPoint) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawArc) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawEllipse) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawPie) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawChord) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,fillRect) + + // Text & Pixmap & Icons + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawText) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawPixmap) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawIcon) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawHtmlText) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,htmlTextSize) + + + // Transform Operation + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,rotate) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,shear) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,scale) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,translate) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,reset) + + + + // ?? + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setOpacity) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setTextAntialiasing) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setAntialiasing) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setSmoothPixmapTransform) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setBackGroundMode) + + + + // QPainterPath stuff + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawPath) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,resetPath) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,pathAddText) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,pathMoveTo) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,pathLineTo) + + // Pen + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setPenJoinStyle) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setPenCapStyle) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setPenWidth) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setPenStyle) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setPen) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,colorNames) + + + // Brush + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setBrush) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setBrushStyle) + + + // Gradients + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setGradientStart) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setGradientStop) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setGradientColor) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setGradientAsBrush) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,clearGradient) + + // painter state + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,save) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,restore) + + // painter device + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,painterDeviceWidth) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,painterDeviceHeight) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,begin) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,end) + + // extra + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,beginPdf) + + +KVSO_END_REGISTERCLASS(KvsObject_painter) + + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_painter,KviKvsObject) + + m_pPainter = new QPainter(); + bDonotdeleteinternalqpainter=false; + m_pPrinter = 0 ; + m_pDeviceObject=0; + m_pPainterPath=0; + m_pGradient=0; + +KVSO_END_CONSTRUCTOR(KvsObject_painter) + +KVSO_BEGIN_DESTRUCTOR(KvsObject_painter) + +if (m_pPainterPath) delete m_pPainterPath; + m_pPainterPath=0; +if (m_pGradient) delete m_pGradient; + m_pGradient=0; +if (m_pPainter && !bDonotdeleteinternalqpainter) delete m_pPainter; + m_pPainter = 0; +if (m_pPrinter) delete m_pPrinter; + m_pPrinter = 0; + +KVSO_END_CONSTRUCTOR(KvsObject_painter) + +#define KVSO_PARAMETERS_PAINTER(__pXOrArray,__iY,__iW,__iH)\ +if(__pXOrArray->isArray())\ + {\ + if(__pXOrArray->array()->size() < 4)\ + {\ + c->error(__tr2qs_ctx("The array passed as parameter must contain at least 4 elements","objects"));\ + 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_ctx("One of the geometry array parameters is empty","objects"));\ + return false;\ + }\ + if(!(pX->asInteger(iX) && pY->asInteger(__iY) && pW->asInteger(__iW) && pH->asInteger(__iH)))\ + {\ + c->error(__tr2qs_ctx("One of the geometry array parameters didn't evaluate to an integer","objects"));\ + return false;\ + }\ + } else {\ + if(c->params()->count() < 4)\ + {\ + QString error=function+__tr2qs_ctx(" requires either an array as first parameter or four integers","objects");\ + c->error(error);\ + return false;\ + }\ + if(!__pXOrArray->asInteger(iX))\ + {\ + c->error(__tr2qs_ctx("The first parameter didn't evaluate to an array nor an integer","objects"));\ + return false;\ + }\ + }\ + +#define KVSO_2ARRAYPARAMETERS(__pXOrArray,__iY)\ +if(__pXOrArray->isArray())\ + {\ + if(__pXOrArray->array()->size() < 2)\ + {\ + c->error(__tr2qs_ctx("The array passed as parameter must contain at least 2 elements","objects"));\ + return false;\ + }\ + KviKvsVariant * pX = __pXOrArray->array()->at(0);\ + KviKvsVariant * pY = __pXOrArray->array()->at(1);\ + if(!(pX && pY ))\ + {\ + c->error(__tr2qs_ctx("One of the array parameters is empty","objects"));\ + return false;\ + }\ + if(!(pX->asInteger(iX) && pY->asInteger(__iY)))\ + {\ + c->error(__tr2qs_ctx("One of the array parameters didn't evaluate to an integer","objects"));\ + return false;\ + }\ + } else {\ + if(c->params()->count() < 2)\ + {\ + QString error=function+__tr2qs_ctx(" requires either an array as first parameter or two integers","objects");\ + c->error(error);\ + return false;\ + }\ + if(!__pXOrArray->asInteger(iX))\ + {\ + c->error(__tr2qs_ctx("The first parameter didn't evaluate to an array nor an integer","objects"));\ + return false;\ + }\ + }\ + +#define KVSO_3OR4ARRAYPARAMETERS(__pCol1OrArray,__iCol2,__iCol3,__iOpacity)\ +if(__pCol1OrArray->isArray())\ + {\ + if(__pCol1OrArray->array()->size() < 3)\ + {\ + c->error(__tr2qs_ctx("The array passed as parameter must contain at least 3 elements","objects"));\ + 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_ctx("One of the array parameters is empty","objects"));\ + return false;\ + }\ + if(!(c1->asInteger(iCol1) && c2->asInteger(__iCol2) && c3->asInteger(__iCol3)))\ + {\ + c->error(__tr2qs_ctx("One of the array parameters didn't evaluate to an integer","objects"));\ + return false;\ + }\ + if(__pCol1OrArray->array()->size() > 3)\ + {\ + KviKvsVariant * c4 = __pCol1OrArray->array()->at(3);\ + if(!(c4->asInteger(__iOpacity)))\ + {\ + c->error(__tr2qs_ctx("The opacity value didn't evaluate to an integer","objects"));\ + return false;\ + }\ + }\ + } else {\ + if(c->params()->count() < 3)\ + {\ + QString error=function+__tr2qs_ctx(" requires either an array as first parameter or 3 integers","objects");\ + c->error(error);\ + return false;\ + }\ + if(!__pCol1OrArray->asInteger(iCol1))\ + {\ + c->error(__tr2qs_ctx("The first parameter didn't evaluate to an array nor an integer","objects"));\ + return false;\ + }\ + }\ + +KVSO_CLASS_FUNCTION(painter,setFont) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + QString szFamily; + QStringList szListStyle; + kvs_int_t iSize; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("size",KVS_PT_INTEGER,0,iSize) + KVSO_PARAMETER("family",KVS_PT_STRING,0,szFamily) + KVSO_PARAMETER("style",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,szListStyle) + KVSO_PARAMETERS_END(c) + QFont font=m_pPainter->font(); + font.setFamily(szFamily); + font.setPointSize(iSize); + QString szStyle; + for(int i=0;iwarning(__tr2qs_ctx("Unknown style '%Q'","objects"),&szStyle); + } + m_pPainter->setFont(font); + return true; +} + +KVSO_CLASS_FUNCTION(painter,setFontSize) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + kvs_uint_t uSize; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("size",KVS_PT_UNSIGNEDINTEGER,0,uSize) + KVSO_PARAMETERS_END(c) + QFont font=m_pPainter->font(); + font.setPointSize(uSize); + m_pPainter->setFont(font); + return true; +} + +KVSO_CLASS_FUNCTION(painter,setBackGroundMode) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + QString szMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("background mode",KVS_PT_STRING,0,szMode) + KVSO_PARAMETERS_END(c) + 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_ctx("Unknown '%Q' background mode","objects"),&szMode); + return true; +} + +KVSO_CLASS_FUNCTION(painter,drawLine) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + KviKvsVariant * pXOrArray; + kvs_int_t iX,iY,iX1,iY1; + 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("x1",KVS_PT_INT,KVS_PF_OPTIONAL,iX1) + KVSO_PARAMETER("y1",KVS_PT_INT,KVS_PF_OPTIONAL,iY1) + KVSO_PARAMETERS_END(c) + QString function="$drawLine"; + KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iX1,iY1) + if(m_pPainter) m_pPainter->drawLine(iX,iY,iX1,iY1); + return true; +} + +KVSO_CLASS_FUNCTION(painter,drawRect) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + 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) + m_pPainter->drawRect(iX,iY,iW,iH); + return true; +} + + +KVSO_CLASS_FUNCTION(painter,drawEllipse) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + 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) + m_pPainter->drawEllipse(iX,iY,iW,iH); + return true; +} + +KVSO_CLASS_FUNCTION(painter,drawRoundRect) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + 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) + m_pPainter->drawRoundRect(iX,iY,iW,iH,iXrnd,iYrnd); + return true; +} + +KVSO_CLASS_FUNCTION(painter,drawArc) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + 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) + m_pPainter->drawArc(iX,iY,iW,iH,iSangle,iLena); + return true; +} + +KVSO_CLASS_FUNCTION(painter,drawChord) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + 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) + m_pPainter->drawChord(iX,iY,iW,iH,iSangle,iLena); + return true; +} + +KVSO_CLASS_FUNCTION(painter,setBrush) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + kvs_int_t iCol1,iCol2,iCol3,iOpacity; + KviKvsVariant *var1,*var2,*var3; + QString szColorMode,szColor; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("Color_1_Or_Colorname_Or_Pixmap",KVS_PT_VARIANT,0,var1) + KVSO_PARAMETER("Color_2",KVS_PT_VARIANT,KVS_PF_OPTIONAL,var2) + KVSO_PARAMETER("Colo3_3",KVS_PT_VARIANT,KVS_PF_OPTIONAL,var3) + KVSO_PARAMETER("color_mode",KVS_PT_STRING,KVS_PF_OPTIONAL,szColorMode) + KVSO_PARAMETER("opacity",KVS_PT_INT,KVS_PF_OPTIONAL,iOpacity) + KVSO_PARAMETERS_END(c) + if(var1->isHObject()) + { + kvs_hobject_t hObj; + var1->asHObject(hObj); + KviKvsObject *pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObj); + if (!pObject) + { + c->warning(__tr2qs_ctx("Pixmap parameter is not an object!","objects")); + return true; + } + if(pObject->inheritsClass("pixmap")) + m_pPainter->setBrush(*((KvsObject_pixmap *)pObject)->getPixmap()); + else c->warning(__tr2qs_ctx("Object Pixmap required!","objects")); + return true; + } + if (!var1->asInteger(iCol1)) + { + var1->asString(szColor); + if (c->paramCount()<2) iOpacity=255; + else + { + if (!var2->asInteger(iOpacity)) + { + c->warning(__tr2qs_ctx("The opacity parameter didn't evaluate to integer","objects")); + return true; + } + } + QColor col(szColor); + col.setAlpha(iOpacity); + m_pPainter->setBrush(col); + } + else + { + if(c->paramCount()<3) + { + c->error(__tr2qs_ctx("Color name or triplette rgb/hsv value required","objects")); + return true; + } + if (!var2->asInteger(iCol2)||!var3->asInteger(iCol3)) + { + c->error(__tr2qs_ctx("One of the triplette parameters didn't evaluate to an integer","objects"));\ + return true; + } + if (c->paramCount()<5) iOpacity=255; + QColor col; + if(KviQString::equalCI(szColorMode, "HSV")) + col.setHsv(iCol1,iCol2,iCol3,iOpacity); + else + col.setRgb(iCol1,iCol2,iCol3,iOpacity); + m_pPainter->setBrush(col); + + } + return true; +} + +KVSO_CLASS_FUNCTION(painter,setPen) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + kvs_int_t iCol1,iCol2,iCol3,iOpacity; + QString szColorMode,szColor; + KviKvsVariant *var1,*var2,*var3; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("Color_1_Or_Colorname",KVS_PT_VARIANT,0,var1) + KVSO_PARAMETER("Color_2",KVS_PT_VARIANT,KVS_PF_OPTIONAL,var2) + KVSO_PARAMETER("Colo3_3",KVS_PT_VARIANT,KVS_PF_OPTIONAL,var3) + KVSO_PARAMETER("color_mode",KVS_PT_STRING,KVS_PF_OPTIONAL,szColorMode) + KVSO_PARAMETER("opacity",KVS_PT_INT,KVS_PF_OPTIONAL,iOpacity) + KVSO_PARAMETERS_END(c) + if (!var1->asInteger(iCol1)) + { + var1->asString(szColor); + if (c->paramCount()<2) iOpacity=255; + else + { + if (!var2->asInteger(iOpacity)) + { + c->warning(__tr2qs_ctx("The opacity parameter didn't evaluate to integer","objects")); + return true; + } + } + QColor col(szColor); + col.setAlpha(iOpacity); + m_pPainter->setPen(col); + } + else + { + if(c->paramCount()<3) + { + c->error(__tr2qs_ctx("Color name or triplette rgb/hsv value required","objects")); + return true; + } + if (!var2->asInteger(iCol2)||!var3->asInteger(iCol3)) + { + c->error(__tr2qs_ctx("One of the triplette parameters didn't evaluate to an integer","objects"));\ + return true; + } + if (c->paramCount()<5) iOpacity=255; + QColor col; + if(KviQString::equalCI(szColorMode, "HSV")) + col.setHsv(iCol1,iCol2,iCol3,iOpacity); + else + col.setRgb(iCol1,iCol2,iCol3,iOpacity); + m_pPainter->setPen(col); + + } + + return true; +} + +KVSO_CLASS_FUNCTION(painter,drawPie) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + 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) + m_pPainter->drawPie(iX,iY,iW,iH,iSangle,iLena); + return true; +} + +KVSO_CLASS_FUNCTION(painter,drawPoint) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + 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) + m_pPainter->drawPoint(iX,iY); + return true; +} + +KVSO_CLASS_FUNCTION(painter,fontDescent) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + c->returnValue()->setInteger(m_pPainter->fontMetrics().descent()); + return true; +} + +KVSO_CLASS_FUNCTION(painter,fontAscent) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + c->returnValue()->setInteger(m_pPainter->fontMetrics().ascent()); + return true; + +} + +KVSO_CLASS_FUNCTION(painter,fontMetricsWidth) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if (m_pPainter->isActive()) + c->returnValue()->setInteger(m_pPainter->fontMetrics().width(szText)); + else + c->warning(__tr2qs_ctx("$fontMetricsWidth: the painter is not active!","objects")); + return true; +} + +KVSO_CLASS_FUNCTION(painter,fontMetricsHeight) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + if (m_pPainter->isActive()) + c->returnValue()->setInteger(m_pPainter->fontMetrics().height()); + else + c->warning(__tr2qs_ctx("$fontMetricsHeight: the painter is not active!","objects")); + return true; +} + +KVSO_CLASS_FUNCTION(painter,begin) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + KviKvsObject * pObject; + kvs_hobject_t hObject; + KviKvsVariant *v; + QString szFileName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("paint_device",KVS_PT_VARIANT,0,v) + KVSO_PARAMETER("file_name",KVS_PT_STRING,KVS_PF_OPTIONAL,szFileName) + KVSO_PARAMETERS_END(c) + QPaintDevice * pd; + if(v->isString()) + { + QString szDev; + v->asString(szDev); + if(KviQString::equalCI(szDev,"printer") || KviQString::equalCI(szDev,"pdf")) + { + if (m_pPrinter) delete m_pPrinter; + m_pPrinter=new QPrinter(); + if ( KviQString::equalCI(szDev,"pdf")) + { + // m_pPrinter=new QPrinter(); + if(szFileName.isEmpty()) + { + c->warning(__tr2qs_ctx("Missing filename","objects")); + return true; + } + m_pPrinter->setOutputFormat(QPrinter::PdfFormat); + m_pPrinter->setOutputFileName(szFileName); + } + else + { + QPrintDialog printDialog(m_pPrinter, 0); + if (printDialog.exec() == QDialog::Accepted) + { + qDebug("papersize %d",m_pPrinter->paperSize()); + m_pPainter->begin(m_pPrinter); + return true; + } + else + { + m_pPrinter=0; + return true; + } + } + //if (i==3) m_pPrinter->setPaperSize(QPrinter::A3); + //if (i==4) m_pPrinter->setPaperSize(QPrinter::A4); + } + else + { + c->warning(__tr2qs_ctx("No valid paint device","objects")); + return true; + } + m_pPainter->begin(m_pPrinter); + return true; + } + else if (v->isHObject()) + { + v->asHObject(hObject); + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!pObject) + { + c->warning(__tr2qs_ctx("Pixmap or Widget parameter is not an object","objects")); + return true; + } + if(pObject->inheritsClass("pixmap"))pd=((KvsObject_pixmap *)pObject)->getPixmap(); + else if (pObject->inheritsClass("widget")) pd=((KvsObject_widget *)pObject)->widget(); + else + { + c->warning(__tr2qs_ctx("Widget or Pixmap required ","objects")); + return true; + } + } + else + { + c->warning(__tr2qs_ctx("No valid paint device","objects")); + return true; + } + attachDevice(pObject,pd); + //if (pObject->inheritsClass("pixmap")) ((KvsObject_pixmap *)pObject)->pixmapChanged(); + return true; +} + +void KvsObject_painter::attachDevice(KviKvsObject * o,QPaintDevice * p) +{ + if(m_pDeviceObject)detachDevice(); + m_pDeviceObject = o; + // KvsObject_pixmap and KvsObject_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 KvsObject_painter::detachDevice() +{ + if(!m_pDeviceObject)return; + disconnect(m_pDeviceObject,SIGNAL(aboutToDie()),this,SLOT(detachDevice())); + m_pPainter->end(); + if (m_pPrinter) + { + delete m_pPrinter; + m_pPrinter=0; + } + m_pDeviceObject = 0; +} + +KVSO_CLASS_FUNCTION(painter,end) +{ + Q_UNUSED(c); + + if(!m_pDeviceObject) + { + m_pPainter->end(); + if (m_pPrinter) + { + delete m_pPrinter; + m_pPrinter=0; + } + } + else detachDevice(); + return true; +} + +KVSO_CLASS_FUNCTION(painter,beginPdf) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + QString szFileName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("file_name",KVS_PT_STRING,0,szFileName) + KVSO_PARAMETERS_END(c) + if (m_pPrinter) delete m_pPrinter; + m_pPrinter=new QPrinter();//QPrinter::HighResolution); + m_pPrinter->setOutputFormat(QPrinter::PdfFormat); + m_pPrinter->setOutputFileName(szFileName); + m_pPainter->begin(m_pPrinter); + return true; +} +KVSO_CLASS_FUNCTION(painter,drawText) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + QString szText,szMode; + kvs_int_t iX,iY,iN=-1; + 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("num_chars",KVS_PT_INT,KVS_PF_OPTIONAL,iN) + KVSO_PARAMETER("mode",KVS_PT_STRING,KVS_PF_OPTIONAL,szMode) + KVSO_PARAMETERS_END(c) + if (!szMode.isEmpty() && !KviQString::equalCI(szMode,"Auto")) + { + 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_ctx("Invalid mode '%Q'","objects"),&szMode); + return true; + } + } + m_pPainter->drawText(iX,iY,szText.left(iN)); + return true; +} + +KVSO_CLASS_FUNCTION(painter,drawPixmap) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + kvs_real_t iX,iY; + kvs_int_t iStartx,iStarty,iEndx,iEndy; + bool bTiled; + KviKvsObject *obj; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x",KVS_PT_REAL,0,iX) + KVSO_PARAMETER("y",KVS_PT_REAL,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_PARAMETER("b_Tiled",KVS_PT_BOOLEAN,KVS_PF_OPTIONAL,bTiled) + KVSO_PARAMETERS_END(c) + obj=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!obj) + { + c->warning(__tr2qs_ctx("Pixmap parameter is not an object","objects")); + return true; + } + if (!obj->inheritsClass("pixmap")) + { + c->warning(__tr2qs_ctx("Pixmap object required","objects")); + return true; + } + + m_pPainter->drawPixmap(QPointF(iX,iY),*((KvsObject_pixmap *)obj)->getPixmap(),QRect(iStartx,iStarty,iEndx,iEndy)); + return true; +} + +KVSO_CLASS_FUNCTION(painter,rotate) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + kvs_real_t dAngle; + QString szAxis; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("angle",KVS_PT_DOUBLE,0,dAngle) + KVSO_PARAMETER("axis",KVS_PT_STRING,KVS_PF_OPTIONAL,szAxis) + KVSO_PARAMETERS_END(c) + Qt::Axis axis = Qt::ZAxis; + if(!szAxis.isEmpty()) + { + if (KviQString::equalCI(szAxis,"XAxis"))axis=Qt::XAxis; + else if (KviQString::equalCI(szAxis,"YAxis")) axis=Qt::YAxis; + else if (KviQString::equalCI(szAxis,"ZAxis")) axis=Qt::ZAxis; + else c->warning(__tr2qs_ctx("Unknown axis '%Q' switching to default ZAxis","objects"),&szAxis); + } + PAINTER_ROTATE(dAngle,axis) + return true; +} + +KVSO_CLASS_FUNCTION(painter,translate) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + 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) + PAINTER_TRANSLATE(dXtrasl,dYtrasl) + return true; +} + +KVSO_CLASS_FUNCTION(painter,shear) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + 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) + PAINTER_SHEAR(dShearh,dShearv); + return true; +} + +KVSO_CLASS_FUNCTION(painter,scale) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + 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) + PAINTER_SCALE(dScalex,dScaley); + return true; +} + +KVSO_CLASS_FUNCTION(painter,reset) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + m_pPainter->resetTransform(); + return true; +} + +KVSO_CLASS_FUNCTION(painter,drawHtmlText) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + QString szText; + kvs_int_t iX,iY,iW,iH; + + 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("w",KVS_PT_INT,0,iW) + KVSO_PARAMETER("h",KVS_PT_INT,0,iH) + + KVSO_PARAMETERS_END(c) + QTextDocument doc; + doc.setHtml(szText); + doc.setDefaultFont(m_pPainter->font()); + m_pPainter->save(); + m_pPainter->translate(iX,iY); + doc.setPageSize(QSize(iW,iH)); + doc.drawContents(m_pPainter); + m_pPainter->restore(); + return true; +} + +KVSO_CLASS_FUNCTION(painter,htmlTextSize) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + QTextDocument doc; + doc.setHtml(szText); + doc.setDefaultFont(m_pPainter->font()); + QSizeF size=doc.size(); + KviKvsArray * a = new KviKvsArray(); + a->set(0,new KviKvsVariant((kvs_real_t)size.width())); + a->set(1,new KviKvsVariant((kvs_real_t)size.height())); + c->returnValue()->setArray(a); + return true; +} + +KVSO_CLASS_FUNCTION(painter,drawIcon) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + QString szIcon,szState; + kvs_int_t iX,iY,iW,iH; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x",KVS_PT_INT,0,iX) + KVSO_PARAMETER("y",KVS_PT_INT,0,iY) + KVSO_PARAMETER("icon",KVS_PT_STRING,0,szIcon) + KVSO_PARAMETER("state",KVS_PT_STRING,KVS_PF_OPTIONAL,szState) + KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) + KVSO_PARAMETERS_END(c) + QPixmap *pix=g_pIconManager->getImage(szIcon); + if (!pix) + { + c->warning("The icon '%Q' does not exists",&szIcon); + return true; + } + QSize pixsize(pix->width(),pix->height()); + QIcon ico(*pix); + QIcon::Mode mode=QIcon::Normal; + if(!ico.isNull()) + { + if (KviQString::equalCI(szState,"Disabled")) + mode=QIcon::Disabled; + else if (KviQString::equalCI(szState,"Active"))mode=QIcon::Active; + else if (KviQString::equalCI(szState,"Selected"))mode=QIcon::Selected; + if (c->parameterCount()<5) + m_pPainter->drawPixmap(iX,iY,ico.pixmap(pixsize,mode)); + else + m_pPainter->drawPixmap(iX,iY,ico.pixmap(QSize(iW,iH),mode)); + } + return true; +} + +KVSO_CLASS_FUNCTION(painter,setOpacity) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + 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; +} + +KVSO_CLASS_FUNCTION(painter,setTextAntialiasing) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + 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; +} + +KVSO_CLASS_FUNCTION(painter,setAntialiasing) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + 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; +} + +KVSO_CLASS_FUNCTION(painter,setSmoothPixmapTransform) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + 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; +} + +KVSO_CLASS_FUNCTION(painter,setPenJoinStyle) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + QString szStyle; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("style",KVS_PT_STRING,0,szStyle) + KVSO_PARAMETERS_END(c) + Qt::PenJoinStyle style=Qt::BevelJoin; + if(KviQString::equalCI(szStyle,"Milter"))style=Qt::MiterJoin; + else if (KviQString::equalCI(szStyle,"Round"))style=Qt::RoundJoin; + QPen pen=m_pPainter->pen(); + pen.setJoinStyle(style); + m_pPainter->setPen(pen); + return true; +} + +KVSO_CLASS_FUNCTION(painter,setPenCapStyle) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + QString szStyle; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("style",KVS_PT_STRING,0,szStyle) + KVSO_PARAMETERS_END(c) + Qt::PenCapStyle style=Qt::SquareCap; + if(KviQString::equalCI(szStyle,"Flat")) style=Qt::FlatCap; + else if (KviQString::equalCI(szStyle,"Round"))style=Qt::RoundCap; + QPen pen=m_pPainter->pen(); + pen.setCapStyle(style); + m_pPainter->setPen(pen); + return true; +} + +KVSO_CLASS_FUNCTION(painter,save) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + m_pPainter->save(); + return true; +} + +KVSO_CLASS_FUNCTION(painter,restore) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + m_pPainter->restore(); + return true; +} + +KVSO_CLASS_FUNCTION(painter,setPenStyle) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + QString szStyle; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("style",KVS_PT_STRING,0,szStyle) + KVSO_PARAMETERS_END(c) + bool found=false; + unsigned int j = 0; + for(; j < penstyles_num; j++) + { + if(KviQString::equalCI(szStyle,penstyles_tbl[j])) + { + found=true; + break; + } + } + QPen pen=m_pPainter->pen(); + if (found){ + pen.setStyle(penstyles_cod[j]); + m_pPainter->setPen(pen); + } + else c->warning(__tr2qs_ctx("Unknown pen style '%Q'","objects"),&szStyle); + return true; +} + +KVSO_CLASS_FUNCTION(painter,setBrushStyle) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + QString szStyle; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("style",KVS_PT_STRING,0,szStyle) + KVSO_PARAMETERS_END(c) + bool found=false; + unsigned int j = 0; + for(; j < brushstyles_num; j++) + { + if(KviQString::equalCI(szStyle,brushstyles_tbl[j])) + { + found=true; + break; + } + } + QBrush brush=m_pPainter->brush(); + if (found){ + brush.setStyle(brushstyles_cod[j]); + m_pPainter->setBrush(brush); + } + else c->warning(__tr2qs_ctx("Unknown brush style '%Q'","objects"),&szStyle); + return true; +} + +KVSO_CLASS_FUNCTION(painter,setGradientStart) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + kvs_real_t dX,dY; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x_Point",KVS_PT_DOUBLE,0,dX) + KVSO_PARAMETER("y_Point",KVS_PT_DOUBLE,0,dY) + KVSO_PARAMETERS_END(c) + if (!m_pGradient) m_pGradient=new(QLinearGradient); + m_pGradient->setStart(dX,dY); + return true; +} + +KVSO_CLASS_FUNCTION(painter,setGradientStop) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + kvs_real_t dX,dY; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x_Point",KVS_PT_DOUBLE,0,dX) + KVSO_PARAMETER("y_Point",KVS_PT_DOUBLE,0,dY) + KVSO_PARAMETERS_END(c) + if (!m_pGradient) m_pGradient=new(QLinearGradient); + m_pGradient->setFinalStop(dX,dY); + return true; +} + +KVSO_CLASS_FUNCTION(painter,setGradientColor) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + kvs_real_t dAt; + kvs_int_t iCol1,iCol2,iCol3,iOpacity; + KviKvsVariant *var1,*var2,*var3; + QString szColorMode,szColor; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("at",KVS_PT_DOUBLE,0,dAt) + KVSO_PARAMETER("Color_1_Or_Colorname",KVS_PT_VARIANT,0,var1) + KVSO_PARAMETER("Color_2",KVS_PT_VARIANT,KVS_PF_OPTIONAL,var2) + KVSO_PARAMETER("Colo3_3",KVS_PT_VARIANT,KVS_PF_OPTIONAL,var3) + KVSO_PARAMETER("color_mode",KVS_PT_STRING,KVS_PF_OPTIONAL,szColorMode) + KVSO_PARAMETER("opacity",KVS_PT_INT,KVS_PF_OPTIONAL,iOpacity) + KVSO_PARAMETERS_END(c) + if (!var1->asInteger(iCol1)) + { + var1->asString(szColor); + if (c->paramCount()<3) iOpacity=255; + else + { + if (!var2->asInteger(iOpacity)) + { + c->warning(__tr2qs_ctx("The opacity parameter didn't evaluate to integer","objects")); + return true; + } + } + if (!m_pGradient) m_pGradient=new(QLinearGradient); + QColor col(szColor); + col.setAlpha(iOpacity); + m_pGradient->setColorAt(dAt,col); + } + else + { + if(c->paramCount()<4) + { + c->error(__tr2qs_ctx("Color name or triplette RGB/HSV values required","objects")); + return true; + } + if ( !var2->asInteger(iCol2)||!var3->asInteger(iCol3)) + { + c->error(__tr2qs_ctx("One of the triplette parameters didn't evaluate to an integer","objects"));\ + return true; + } + if (c->paramCount()<5) iOpacity=255; + QColor col; + if(KviQString::equalCI(szColorMode, "HSV")) + col.setHsv(iCol1,iCol2,iCol3,iOpacity); + else + col.setRgb(iCol1,iCol2,iCol3,iOpacity); + if (!m_pGradient) m_pGradient=new(QLinearGradient); + m_pGradient->setColorAt(dAt,col); + + } + return true; +} + +KVSO_CLASS_FUNCTION(painter,setGradientAsBrush) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + if (!m_pGradient) m_pGradient=new(QLinearGradient); + m_pPainter->setBrush(*m_pGradient); + return true; +} + +KVSO_CLASS_FUNCTION(painter,clearGradient) +{ + Q_UNUSED(c); + if (!m_pGradient) delete m_pGradient; + m_pGradient=0; + return true; +} + +KVSO_CLASS_FUNCTION(painter,setPenWidth) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + kvs_real_t iWidth; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("width",KVS_PT_REAL,0,iWidth) + KVSO_PARAMETERS_END(c) + QPen pen=m_pPainter->pen(); + pen.setWidthF(iWidth); + m_pPainter->setPen(pen); + return true; +} + +KVSO_CLASS_FUNCTION(painter,fillRect) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + kvs_int_t iX,iY,iW,iH; + kvs_int_t iCol1,iCol2,iCol3,iOpacity; + QString szColorMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x",KVS_PT_INT,0,iX) + KVSO_PARAMETER("y",KVS_PT_INT,0,iY) + KVSO_PARAMETER("w",KVS_PT_INT,0,iW) + KVSO_PARAMETER("h",KVS_PT_INT,0,iH) + KVSO_PARAMETER("Color_1",KVS_PT_INT,0,iCol1) + KVSO_PARAMETER("Color_2",KVS_PT_INT,0,iCol2) + KVSO_PARAMETER("Colo3_3",KVS_PT_INT,0,iCol3) + KVSO_PARAMETER("opacity",KVS_PT_INT,KVS_PF_OPTIONAL,iOpacity) + KVSO_PARAMETER("color_mode",KVS_PT_STRING,KVS_PF_OPTIONAL,szColorMode) + KVSO_PARAMETERS_END(c) + if (c->paramCount()<8) iOpacity=255; + QColor col; + if(KviQString::equalCI(szColorMode, "HSV")) + col.setHsv(iCol1,iCol2,iCol3,iOpacity); + else + col.setRgb(iCol1,iCol2,iCol3,iOpacity); + m_pPainter->fillRect(iX,iY,iW,iH,col); + return true; +} + +KVSO_CLASS_FUNCTION(painter,colorNames) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + QStringList color=QColor::colorNames(); + KviKvsArray * a = new KviKvsArray(); + //a->set(0,new KviKvsVariant((kvs_int_t)col.red())); + for(int i=0;iset(i,new KviKvsVariant(color.at(i))); + } + c->returnValue()->setArray(a); + return true; +} +KVSO_CLASS_FUNCTION(painter,painterDeviceWidth) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + kvs_int_t width=m_pPainter->device()->width(); + c->returnValue()->setInteger(width); + return true; +} +KVSO_CLASS_FUNCTION(painter,painterDeviceHeight) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + kvs_int_t height=m_pPainter->device()->height(); + c->returnValue()->setInteger(height); + return true; +} +KVSO_CLASS_FUNCTION(painter,pathMoveTo) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + kvs_real_t dX,dY; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x",KVS_PT_REAL,0,dX) + KVSO_PARAMETER("y",KVS_PT_REAL,0,dY) + KVSO_PARAMETERS_END(c) + if (!m_pPainterPath) m_pPainterPath=new QPainterPath(QPointF(0,0)); + m_pPainterPath->moveTo(dX,dY); + return true; +} + +KVSO_CLASS_FUNCTION(painter,pathLineTo) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + kvs_real_t dX,dY; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x",KVS_PT_REAL,0,dX) + KVSO_PARAMETER("y",KVS_PT_REAL,0,dY) + KVSO_PARAMETERS_END(c) + if (!m_pPainterPath) m_pPainterPath=new QPainterPath(QPointF(0,0)); + m_pPainterPath->lineTo(dX,dY); + return true; +} + +KVSO_CLASS_FUNCTION(painter,pathAddText) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + kvs_real_t dX,dY; + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x",KVS_PT_REAL,0,dX) + KVSO_PARAMETER("y",KVS_PT_REAL,0,dY) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if (!m_pPainterPath) m_pPainterPath=new QPainterPath(QPointF(0,0)); + m_pPainterPath->addText(dX,dY,m_pPainter->font(),szText); + return true; +} + +KVSO_CLASS_FUNCTION(painter,drawPath) +{ + CHECK_INTERNAL_POINTER(m_pPainter) + m_pPainter->drawPath(*m_pPainterPath); + //delete m_pPainterPath; + //m_pPainterPath=0; + return true; +} + +KVSO_CLASS_FUNCTION(painter,resetPath) +{ + Q_UNUSED(c); + if (m_pPainterPath){ + delete m_pPainterPath; + m_pPainterPath=0; + } + return true; +} +void KvsObject_painter::setInternalPainter(QPainter *p) +{ + delete m_pPainter; + m_pPainter=p; + bDonotdeleteinternalqpainter=true; +} +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_painter.moc" +#endif //COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/KvsObject_painter.h b/src/modules/objects/KvsObject_painter.h new file mode 100644 index 000000000..e8529dfb0 --- /dev/null +++ b/src/modules/objects/KvsObject_painter.h @@ -0,0 +1,131 @@ +#ifndef _CLASS_PAINTER_H_ +#define _CLASS_PAINTER_H_ +//============================================================================= +// +// File : KvsObject_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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KviCString.h" +#include +#include "object_macros.h" + + +class KvsObject_painter : public KviKvsObject +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_painter) +protected: + QPrinter * m_pPrinter; + bool bDonotdeleteinternalqpainter; + QPainter * m_pPainter; + QMatrix m_pMatrix; + QLinearGradient *m_pGradient; + QPainterPath *m_pPainterPath; +public: + void setInternalPainter(QPainter *p); + bool setFont(KviKvsObjectFunctionCall *c); + bool setFontSize(KviKvsObjectFunctionCall *c); + + bool fontAscent(KviKvsObjectFunctionCall *c); + bool fontDescent(KviKvsObjectFunctionCall *c); + bool fontMetricsWidth(KviKvsObjectFunctionCall *c); + bool fontMetricsHeight(KviKvsObjectFunctionCall *c); + bool setBrush(KviKvsObjectFunctionCall *c); + bool setPen(KviKvsObjectFunctionCall *c); + bool setBackGroundMode(KviKvsObjectFunctionCall *c); + + bool drawRect(KviKvsObjectFunctionCall *c); + bool drawWinFocusRect(KviKvsObjectFunctionCall *c); + bool drawLine(KviKvsObjectFunctionCall *c); + bool drawRoundRect(KviKvsObjectFunctionCall *c); + bool drawPoint(KviKvsObjectFunctionCall *c); + bool drawArc(KviKvsObjectFunctionCall *c); + bool drawChord(KviKvsObjectFunctionCall *c); + bool drawPie(KviKvsObjectFunctionCall *c); + bool drawEllipse(KviKvsObjectFunctionCall *c); + + bool drawText(KviKvsObjectFunctionCall *c); + bool drawPixmap(KviKvsObjectFunctionCall *c); + + + bool begin(KviKvsObjectFunctionCall *c); + bool end(KviKvsObjectFunctionCall *c); + bool save(KviKvsObjectFunctionCall *c); + bool restore(KviKvsObjectFunctionCall *c); + + + bool scale(KviKvsObjectFunctionCall *c); + bool shear(KviKvsObjectFunctionCall *c); + bool rotate(KviKvsObjectFunctionCall *c); + bool reset(KviKvsObjectFunctionCall *c); + bool translate(KviKvsObjectFunctionCall *c); + bool setPenStyle(KviKvsObjectFunctionCall *c); + bool setBrushStyle(KviKvsObjectFunctionCall *c); + +// QT4 + bool setOpacity(KviKvsObjectFunctionCall *c); + bool setSmoothPixmapTransform(KviKvsObjectFunctionCall *c); + bool setTextAntialiasing(KviKvsObjectFunctionCall *c); + bool setAntialiasing(KviKvsObjectFunctionCall *c); + bool setGradientStart(KviKvsObjectFunctionCall *c); + bool setGradientStop(KviKvsObjectFunctionCall *c); + bool setGradientColor(KviKvsObjectFunctionCall *c); + bool setGradientAsBrush(KviKvsObjectFunctionCall *c); + bool clearGradient(KviKvsObjectFunctionCall *c); + + bool drawIcon(KviKvsObjectFunctionCall *c); + bool drawHtmlText(KviKvsObjectFunctionCall *c); + bool htmlTextSize(KviKvsObjectFunctionCall *c); + bool fillRect(KviKvsObjectFunctionCall *c); + bool setPenWidth(KviKvsObjectFunctionCall *c); + bool colorNames(KviKvsObjectFunctionCall *c); + bool pathMoveTo(KviKvsObjectFunctionCall *c); + bool pathLineTo(KviKvsObjectFunctionCall *c); + bool drawPath(KviKvsObjectFunctionCall *c); + bool setPenJoinStyle(KviKvsObjectFunctionCall *c); + bool setPenCapStyle(KviKvsObjectFunctionCall *c); + bool pathAddText(KviKvsObjectFunctionCall *c); + bool resetPath(KviKvsObjectFunctionCall *c); + + bool beginPdf(KviKvsObjectFunctionCall *c); + + bool painterDeviceWidth(KviKvsObjectFunctionCall *c); + bool painterDeviceHeight(KviKvsObjectFunctionCall *c); + + +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/KvsObject_pixmap.cpp b/src/modules/objects/KvsObject_pixmap.cpp new file mode 100644 index 000000000..64128ef5d --- /dev/null +++ b/src/modules/objects/KvsObject_pixmap.cpp @@ -0,0 +1,360 @@ +//============================================================================= +// +// File : KvsObject_pixmap.cpp +// 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_pixmap.h" +#include "KvsObject_widget.h" + +#include "KvsObject_memoryBuffer.h" +#include "KviAnimatedPixmap.h" + +#include "kvi_debug.h" +#include "KviLocale.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 or the animation by sx horizontally and sy vertically. + Aspect_ratio values: + - IgnoreAspectRatio:the pixmap is scaled ignoring his aspect ratio. + - KeepAspectRatio: pixmap is scaled to a rectangle as large as possible inside size, preserving the aspect ratio. + - KeepAspectRatioByExpanding, the pixmap is scaled to a rectangle as small as possible outside size, preserving the aspect ratio. + Default value is KeepAspectRatio. + !fn: $load() + Load a pixmap from the file . + !fn: $save() + Save the pixmap or the current animation frame to the file . + !fn: $loadAnimation() + Load an animation from the file and start it. + !fn: $startAnimation() + Start the animation. + !fn: $stopAnimation() + Stop the animation. + !fn: $height() + Return the height of the pixmap or of the animation. + !fn: $width() + Return the width of the pixmap or of the animation. + !fn: $frameChangedEvent() + This event is triggered by KVIrc when the current animation frame changes. + @signals: + !sg: $frameChanged() + This signal is emitted by the default implementation of [classfnc]$frameChangedEvent[/classfnc]().[br] + +*/ + + +KVSO_BEGIN_REGISTERCLASS(KvsObject_pixmap,"pixmap","object") + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,fill) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,resize) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,scale) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,load) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,loadAnimation) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,save) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,startAnimation) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,stopAnimation) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,loadFromMemoryBuffer) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,height) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,width) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,grabWidget) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,frameChangedEvent) + +KVSO_END_REGISTERCLASS(KvsObject_pixmap) + + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_pixmap,KviKvsObject) + m_pAnimatedPixmap = 0; + m_pPixmap = 0; +KVSO_END_CONSTRUCTOR(KvsObject_pixmap) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_pixmap) + emit aboutToDie(); + if (m_pPixmap)delete m_pPixmap; + if (m_pAnimatedPixmap) delete m_pAnimatedPixmap; +KVSO_END_CONSTRUCTOR(KvsObject_pixmap) + + +KVSO_CLASS_FUNCTION(pixmap,fill) +{ + KviKvsObject *pObject; + 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) + + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + CHECK_HOBJECT_IS_WIDGET(pObject) + if (m_pAnimatedPixmap) + { + delete m_pAnimatedPixmap; + m_pAnimatedPixmap=0; + } + if(!m_pPixmap) m_pPixmap=new QPixmap(); + m_pPixmap->fill(((QWidget *)(pObject->object())),iXoffset,iYoffset); + return true; +} +KVSO_CLASS_FUNCTION(pixmap,resize) +{ + kvs_int_t iWidth,iHeight; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("width",KVS_PT_INTEGER,0,iWidth) + KVSO_PARAMETER("height",KVS_PT_INTEGER,0,iHeight) + KVSO_PARAMETERS_END(c) + if(m_pPixmap) delete m_pPixmap; + if (m_pAnimatedPixmap){ + delete m_pAnimatedPixmap; + m_pAnimatedPixmap=0; + } + m_pPixmap=new QPixmap(iWidth,iHeight); + return true; +} +KVSO_CLASS_FUNCTION(pixmap,scale) +{ + kvs_int_t iWidth,iHeight; + QString szAspectRatio; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("width",KVS_PT_INTEGER,0,iWidth) + KVSO_PARAMETER("height",KVS_PT_INTEGER,0,iHeight) + KVSO_PARAMETER("aspect_ratio",KVS_PT_STRING,KVS_PF_OPTIONAL,szAspectRatio) + KVSO_PARAMETERS_END(c) + Qt::AspectRatioMode ratio=Qt::KeepAspectRatio; + if(!m_pPixmap || m_pAnimatedPixmap) return true; + if(!szAspectRatio.isEmpty()) + { + if(KviQString::equalCI(szAspectRatio,"IgnoreAspectRatio")) ratio=Qt::IgnoreAspectRatio; + else if (KviQString::equalCI(szAspectRatio,"KeepAspectRatio")) ratio=Qt::KeepAspectRatio; + else if (KviQString::equalCI(szAspectRatio,"KeepAspectRatioByExpanding")) ratio=Qt::KeepAspectRatioByExpanding; + else c->warning(__tr2qs_ctx("Unknown aspect ratio %Q - Switching to KeepAspectRatio ratio","objects"),&szAspectRatio); + } + if (m_pAnimatedPixmap) m_pAnimatedPixmap->resize(QSize(iWidth,iHeight),ratio); + else *m_pPixmap=m_pPixmap->scaled(iWidth,iHeight,ratio,Qt::SmoothTransformation); + return true; +} +KVSO_CLASS_FUNCTION(pixmap,loadAnimation) + +{ + 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_ctx("I can't find the specified file '%Q'.","objects"),&szFile); + return true; + } + if (m_pAnimatedPixmap) delete m_pAnimatedPixmap; + if (m_pPixmap) + { + delete m_pPixmap; + m_pPixmap=0; + } + m_pAnimatedPixmap= new KviAnimatedPixmap(szFile); + connect(m_pAnimatedPixmap,SIGNAL(frameChanged()),this,SLOT(frameChanged())); + return true; +} + +KVSO_CLASS_FUNCTION(pixmap,startAnimation) +{ + Q_UNUSED(c); + if (m_pAnimatedPixmap) m_pAnimatedPixmap->start(); + return true; +} + +KVSO_CLASS_FUNCTION(pixmap,stopAnimation) +{ + Q_UNUSED(c); + if (m_pAnimatedPixmap) m_pAnimatedPixmap->stop(); + return true; +} + +KVSO_CLASS_FUNCTION(pixmap,load) +{ + 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_ctx("I can't find the specified file '%Q'.","objects"),&szFile); + return true; + } + if (m_pAnimatedPixmap) delete m_pAnimatedPixmap; + if(!m_pPixmap) m_pPixmap=new QPixmap(); + m_pPixmap->load(szFile); + return true; +} +KVSO_CLASS_FUNCTION(pixmap,save) +{ + QString szFile; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("file",KVS_PT_STRING,0,szFile) + KVSO_PARAMETERS_END(c) + if (m_pAnimatedPixmap) m_pAnimatedPixmap->pixmap()->save(szFile); + else if(m_pPixmap) m_pPixmap->save(szFile); + return true; +} +/* +KVSO_CLASS_FUNCTION(pixmap,save) +{ + //CHECK_INTERNAL_POINTER(m_pPixmap) + 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_ctx("I can't find the specified file '%Q'.","objects"),&szFile); + return true; + } + if (m_pAnimatedPixmap) delete m_pAnimatedPixmap; + m_pAnimatedPixmap= new KviAnimatedPixmap(szFile); + connect(m_pAnimatedPixmap,SIGNAL(frameChanged()),this,SLOT(frameChanged())); + //bPixmapModified=true; + + return true; +} +*/ +KVSO_CLASS_FUNCTION(pixmap,loadFromMemoryBuffer) +{ + KviKvsObject * pObject; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("hobject",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETERS_END(c) + + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!pObject) + { + c->warning(__tr2qs_ctx("Buffer parameter is not an object","objects")); + return true; + } + if (!pObject->inheritsClass("memorybuffer")) + { + c->warning(__tr2qs_ctx("Buffer parameter is not a memorybuffer object","objects")); + return true; + } + if (m_pAnimatedPixmap){ + delete m_pAnimatedPixmap; + m_pAnimatedPixmap=0; + } + if (!m_pPixmap) m_pPixmap=new QPixmap(); + m_pPixmap->loadFromData(((KvsObject_memoryBuffer *)pObject)->dataBuffer()); + return true; +} + +KVSO_CLASS_FUNCTION(pixmap,grabWidget) +{ + CHECK_INTERNAL_POINTER(m_pPixmap) + 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); + CHECK_HOBJECT_IS_WIDGET(pObject) + if (m_pAnimatedPixmap){ + delete m_pAnimatedPixmap; + m_pAnimatedPixmap=0; + } + if (!m_pPixmap) m_pPixmap=new QPixmap(); + *m_pPixmap=QPixmap::grabWidget(((KvsObject_widget *)pObject)->widget()); + /* QString szFileName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("file_name",KVS_PT_STRING,0,szFileName) + KVSO_PARAMETERS_END(c) + QPrinter printer;//(QPrinter::HighResolution); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setPaperSize(QPrinter::A4); + printer.setOutputFileName(szFileName); + + QPixmap pixmap=QPixmap::grabWidget(((QTableWidget *)widget())); + QPainter painter(&printer); + painter.drawPixmap(QPoint(0,0), pixmap, pixmap.rect()); + */ + + return true; +} +KVSO_CLASS_FUNCTION(pixmap,height) +{ + if(!m_pAnimatedPixmap && !m_pPixmap) c->returnValue()->setInteger(0); + else if(m_pAnimatedPixmap) c->returnValue()->setInteger(m_pAnimatedPixmap->size().height()); + else c->returnValue()->setInteger(m_pPixmap->height()); + return true; +} +KVSO_CLASS_FUNCTION(pixmap,width) +{ + if(!m_pAnimatedPixmap && !m_pPixmap) c->returnValue()->setInteger(0); + else if(m_pAnimatedPixmap) c->returnValue()->setInteger(m_pAnimatedPixmap->size().width()); + else c->returnValue()->setInteger(m_pPixmap->width()); + return true; +} + +QPixmap * KvsObject_pixmap::getPixmap() +{ + if (!m_pAnimatedPixmap && !m_pPixmap) return new QPixmap(); + else if(m_pAnimatedPixmap) return m_pAnimatedPixmap->pixmap(); + else return m_pPixmap; +} +KVSO_CLASS_FUNCTION(pixmap,frameChangedEvent) +{ + emitSignal("frameChanged",c); + return true; +} + +// slots +void KvsObject_pixmap::frameChanged() +{ + KviKvsVariantList *params=0; + callFunction(this,"frameChangedEvent",params); +} + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_pixmap.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES + diff --git a/src/modules/objects/KvsObject_pixmap.h b/src/modules/objects/KvsObject_pixmap.h new file mode 100644 index 000000000..a1e2eeb3a --- /dev/null +++ b/src/modules/objects/KvsObject_pixmap.h @@ -0,0 +1,76 @@ +#ifndef _CLASS_PIXMAP_H_ +#define _CLASS_PIXMAP_H_ +//============================================================================= +// +// File : KvsObject_pixmap.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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 +#include "KviCString.h" + + +#include "object_macros.h" + + +class KvsObject_pixmap : public KviKvsObject +{ + Q_OBJECT +// Q_PROPERTY(QPixmap pixmap READ getPixmap) +public: + KVSO_DECLARE_OBJECT(KvsObject_pixmap) + QPixmap * getPixmap(); + + //QPixmap * pixmap(){ return m_pPixmap; } +protected: + KviAnimatedPixmap * m_pAnimatedPixmap; + QPixmap * m_pPixmap; +signals: + void aboutToDie(); +protected: + bool fill(KviKvsObjectFunctionCall *c); + bool resize(KviKvsObjectFunctionCall *c); + bool scale(KviKvsObjectFunctionCall *c); + //bool rotate(KviKvsObjectFunctionCall *c); + bool save(KviKvsObjectFunctionCall *c); + bool startAnimation(KviKvsObjectFunctionCall *c); + bool stopAnimation(KviKvsObjectFunctionCall *c); + bool loadAnimation(KviKvsObjectFunctionCall *c); + bool load(KviKvsObjectFunctionCall *c); + bool height(KviKvsObjectFunctionCall *c); + bool width(KviKvsObjectFunctionCall *c); + bool grabWidget(KviKvsObjectFunctionCall *c); +// bool setOpacity(KviKvsObjectFunctionCall *c); + bool loadFromMemoryBuffer(KviKvsObjectFunctionCall *c); + + bool frameChangedEvent(KviKvsObjectFunctionCall *c); + +protected slots: + void frameChanged(); + }; + +#endif // !_CLASS_PIXMAP_H_ diff --git a/src/modules/objects/KvsObject_popupMenu.cpp b/src/modules/objects/KvsObject_popupMenu.cpp new file mode 100644 index 000000000..25cc28cac --- /dev/null +++ b/src/modules/objects/KvsObject_popupMenu.cpp @@ -0,0 +1,398 @@ +//============================================================================= +// +// File : KvsObject_popupMenu.cpp +// Creation date : Fri Mar 18 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_popupMenu.h" + +#include "KviError.h" +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KviIconManager.h" +#include "KviTalPopupMenu.h" + +#include +#include +#include + + + +/* + @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: $addMenu() + Sets the popupmenu title to text. + !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] + @examples: + [example] + // first we define a class inherited from popupmenu + class(menu,popupmenu) + { + constructor() + { + // we store the item's id for checkit in activatedEvent + @%tile_id=@$insertItem("Tile",118) + @%cascade_id=@$insertItem("Cascade",115) + @$insertSeparator(3) + @%closeactw_id=@$insertItem("Close Active Window",08) + @%closeallw_id=@$insertItem("Close All Window",58) + } + activatedEvent() + { + // now we emit a signals to the relative to the user choice + %id=$0 + if (%id==@%tile_id) @$emit("tile") + else if(%id==@%cascade_id) @$emit("cascade") + else if (%id==@%closeactw_id) @$emit("closeactive") + else @$emit("closeallwindows") + // deleting the popup + delete $$ + } + } + class (ws,widget)[br] + { + #In the constructor we create everything that belong to the single widget. + constructor() + { + #Here we generate a loop to create our labels inside the widget. + %lay=$new(layout,$$) + // we use a vbox to managing labels in vertical orientation + %vb=$new(vbox,$$) + // then add the vbox to the main layout + %lay->$addWidget(%vb,0,0) + // let's create our colorful labels + for(%i=0;%i<15;%i++) + { + @%label=$new(label,%vb) + @%label->$settext("Another class by N\&G") + #We set our foreground's colors using the hex array in a random way. + @%label->$setforegroundcolor($array($rand(255),$rand(255),$rand(255))) + } + } + customContextMenuRequestedEvent() + { + #We create the popupmenu relative to this widget at runtime. + %p=$new(menu,$$) + objects.connect %p tile @$parent tile + objects.connect %p cascade @$parent cascade + objects.connect %p closeactive @$parent closeactivewindow + objects.connect %p closeallwindows @$parent closeallwindows + %p->$exec($$,$($0+10),$($1+10)) + } + } + // we create the workspace widget + %Workspace=$new(workspace) + // we use as space as we have + %size[]=%Workspace->$screenResolution() + // resize it + %Workspace->$resize(%size[0],%size[1]) + // then create 20 subwidget + for(%i=0;%i<20;%i++) + { + %w=$new(ws,%Workspace) + // let's add avery widget to the workspace + %Workspace->$addSubWindow(%w) + // then "shake it" a little bit around :-) + %w->$move($rand($(%size[0]-50)),$rand($(%size[1]-50))) + } + // reimplement closeEvent to delete all this :-) + privateimpl(%Workspace,closeEvent) + { + delete $$ + } + #Let's show! + %Workspace->$show() + [/example] +*/ + +static QHash actionsDict; +static int iIdentifier=0; + + +static int addActionToDict(QAction *pAction) +{ + actionsDict.insert(iIdentifier,pAction); + iIdentifier++; + return (iIdentifier-1); +} +static void removeMenuAllActions(QMenu *pMenu) +{ + QList pActionsList=pMenu->actions(); + QList pActionsListDictValues=actionsDict.values(); + for(int i=0;i=0) actionsDict.remove(actionsDict.key(pActionsList.at(i))); + } +} + +static QAction* getAction(int idx) +{ + return actionsDict.value(idx); +} +static void removeAction(int idx) +{ + actionsDict.remove(idx); +} + + +KVSO_BEGIN_REGISTERCLASS(KvsObject_popupMenu,"popupmenu","widget") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_popupMenu,insertItem) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_popupMenu,setTitle) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_popupMenu,exec) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_popupMenu,insertSeparator) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_popupMenu,removeItem) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_popupMenu,addMenu) + + // events + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_popupMenu,highlightedEvent) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_popupMenu,activatedEvent) + +KVSO_END_REGISTERCLASS(KvsObject_popupMenu) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_popupMenu,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_popupMenu) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_popupMenu) + +KVSO_END_CONSTRUCTOR(KvsObject_popupMenu) + +bool KvsObject_popupMenu::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT(QMenu) + connect(widget(),SIGNAL(triggered(QAction *)),this,SLOT(slottriggered(QAction *))); + connect(widget(),SIGNAL(destroyed(QObject *)),this,SLOT(aboutToDie(QObject *))); + connect(widget(),SIGNAL(highlighted(int)),this,SLOT(slothighlighted(int))); + return true; +} + +KVSO_CLASS_FUNCTION(popupMenu,insertItem) +{ + CHECK_INTERNAL_POINTER(widget()) + 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) + QPixmap *pix = 0; + QAction * pAction = 0; + if(!szIcon.isEmpty()) + { + pix = g_pIconManager->getImage(szIcon); + if (pix) pAction=((QMenu *)widget())->addAction(*pix,szItem); + else c->warning(__tr2qs_ctx("Icon '%Q' doesn't exist","objects"),&szIcon); + } + else + pAction=((QMenu *)widget())->addAction(szItem); + int identifier=addActionToDict(pAction); + c->returnValue()->setInteger((kvs_int_t)identifier); + return true; +} + +KVSO_CLASS_FUNCTION(popupMenu,setTitle) +{ + QString szTitle; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("title",KVS_PT_STRING,0,szTitle) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + ((QMenu *)widget())->setTitle(szTitle); + + return true; +} + +KVSO_CLASS_FUNCTION(popupMenu,exec) +{ + CHECK_INTERNAL_POINTER(widget()) + if(!c->params()->count()) + { + ((QMenu *)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); + CHECK_HOBJECT_IS_WIDGET(pObject) + ((QMenu *)widget())->exec(((QWidget *)(pObject->object()))->mapToGlobal(QPoint(iX,iY)) ); + + return true; +} + + + +KVSO_CLASS_FUNCTION(popupMenu,addMenu) +{ + CHECK_INTERNAL_POINTER(widget()) + KviKvsObject *pObject; + kvs_uint_t iIdx; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("popupmenu",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,iIdx) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!pObject)\ + { + c->warning(__tr2qs_ctx("Popup menu parameter is not an object","objects"));\ + return true; + } + if (!pObject->object())\ + { + c->warning(__tr2qs_ctx("Popup menu parameter is not a valid object","objects"));\ + return true;\ + } + if(!pObject->inheritsClass("popupmenu"))\ + {\ + c->warning(__tr2qs_ctx("Popupmenu object required","objects"));\ + return true;\ + } + QAction *pAction; + if(iIdx) + { + QAction *pActionBefore=actionsDict[iIdx]; + pAction=((QMenu *)widget())->insertMenu(pActionBefore,(QMenu*)pObject->object()); + } + else pAction=((QMenu *)widget())->addMenu((QMenu*)pObject->object()); + int identifier=addActionToDict(pAction); + c->returnValue()->setInteger((kvs_int_t)identifier); + identifier++; + return true; +} + +KVSO_CLASS_FUNCTION(popupMenu,removeItem) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iIdx; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("item_id",KVS_PT_INTEGER,0,iIdx) + KVSO_PARAMETERS_END(c) + QAction * pAction=getAction(iIdx); + if(pAction) + { + ((QMenu *)widget())->removeAction(pAction); + removeAction(iIdx); + } + return true; +} + +KVSO_CLASS_FUNCTION(popupMenu,insertSeparator) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t iIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,iIndex) + KVSO_PARAMETERS_END(c) + QAction * pAction=getAction(iIndex); + if(pAction)((QMenu *)widget())->insertSeparator(pAction); + return true; +} + +void KvsObject_popupMenu::slothighlighted(int i) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)i)); + callFunction(this,"highlightedEvent",¶ms); +} +void KvsObject_popupMenu::aboutToDie(QObject *pObject) +{ + qDebug("Removing popup from kvs dict"); + removeMenuAllActions((QMenu *)pObject); +} +KVSO_CLASS_FUNCTION(popupMenu,highlightedEvent) +{ + emitSignal("highlighted",c,c->params()); + return true; +} + +void KvsObject_popupMenu::slottriggered(QAction *a) +{ + QHashIterator i(actionsDict); + while (i.hasNext()) + { + i.next(); + if (i.value()== a) break; + } + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)i.key())); + callFunction(this,"activatedEvent",¶ms); +} + +KVSO_CLASS_FUNCTION(popupMenu,activatedEvent) +{ + emitSignal("activated",c,c->params()); + return true; +} + + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_popupMenu.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/KvsObject_popupMenu.h b/src/modules/objects/KvsObject_popupMenu.h new file mode 100644 index 000000000..95e1a023a --- /dev/null +++ b/src/modules/objects/KvsObject_popupMenu.h @@ -0,0 +1,64 @@ +#ifndef _CLASS_POPUPMENU_H_ +#define _CLASS_POPUPMENU_H_ +//============================================================================= +// +// File : KvsObject_popupMenu.h +// Creation date : Fri Mar 18 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_widget.h" +#include "object_macros.h" +#include +#include + + + + +class KvsObject_popupMenu : public KvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_popupMenu) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool insertItem(KviKvsObjectFunctionCall *c); + bool setTitle(KviKvsObjectFunctionCall *c); + bool addMenu(KviKvsObjectFunctionCall *c); + bool exec(KviKvsObjectFunctionCall *c); + bool removeItem(KviKvsObjectFunctionCall *c); + bool removeItemAt(KviKvsObjectFunctionCall *c); + bool insertSeparator(KviKvsObjectFunctionCall *c); + bool activatedEvent(KviKvsObjectFunctionCall *c); + bool highlightedEvent(KviKvsObjectFunctionCall *c); + +protected slots: + void slottriggered(QAction *); + void slothighlighted(int); + void aboutToDie(QObject *); +}; + +#endif // !_CLASS_POPUPMENU_H_ + diff --git a/src/modules/objects/KvsObject_process.cpp b/src/modules/objects/KvsObject_process.cpp new file mode 100644 index 000000000..7934127c6 --- /dev/null +++ b/src/modules/objects/KvsObject_process.cpp @@ -0,0 +1,323 @@ +//============================================================================= +// +// File : KvsObject_process.cpp +// Creation date : Fri Mar 18 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_process.h" +#include "KviError.h" +#include "kvi_debug.h" +#include "kvi_settings.h" +#include "KviLocale.h" +#include "QProcess" + +/* + @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: $addArgument() + With this command you give the process name (or more arguments) for comunication. + Es: see the next example. + !fn: $startProcess() + 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->$addArgument("cmd.exe")[br] + %Process->$startProcess();[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(KvsObject_process,"process","object") + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_process,addArgument); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_process,startProcess); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_process,readStdout); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_process,readStderr); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_process,writeToStdin); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_process,closekill); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_process,kill); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_process,tryTerminate); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_process,closeStdin); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_process,isRunning); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_process,normalExit); + + // Events + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_process,readyReadStdoutEvent); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_process,readyReadStderrEvent); + + KVSO_END_REGISTERCLASS(KvsObject_process) + + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_process,KviKvsObject) + + m_pProcess = new QProcess(); + connect(m_pProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(slotReadStdout())); + connect(m_pProcess,SIGNAL(readyReadStandardError()),this,SLOT(slotReadStderr())); + +KVSO_END_CONSTRUCTOR(KvsObject_process) + +KVSO_BEGIN_DESTRUCTOR(KvsObject_process) + + delete m_pProcess; + +KVSO_END_CONSTRUCTOR(KvsObject_process) + + + +KVSO_CLASS_FUNCTION(process,addArgument) +{ + + QString szArgument; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("argument",KVS_PT_NONEMPTYSTRING,0,szArgument) + KVSO_PARAMETERS_END(c) + m_szArgs.append(szArgument); + return true; +} + +//->Start the process. +KVSO_CLASS_FUNCTION(process,startProcess) +{ + CHECK_INTERNAL_POINTER(m_pProcess) + QString szcmd; + + szcmd = m_szArgs.takeFirst(); + m_pProcess->start(szcmd, m_szArgs); + + if(m_pProcess->state()==QProcess::NotRunning) + { + c->warning( __tr2qs_ctx("Process could not be started.","objects")); + } + return true; +} +//-->Read the standard output. +KVSO_CLASS_FUNCTION(process,readStderr) +{ + CHECK_INTERNAL_POINTER(m_pProcess) + QString ng_Process = m_pProcess->readAllStandardError(); + c->returnValue()->setString(ng_Process); + return true; +} + +//-->Read the standard error. +KVSO_CLASS_FUNCTION(process,readStdout) +{ + CHECK_INTERNAL_POINTER(m_pProcess) + QString ng_Process =m_pProcess->readAllStandardOutput(); + c->returnValue()->setString(ng_Process); + return true; +} +//-->Signals and slot to manage reading output and error from the process. +KVSO_CLASS_FUNCTION(process,readyReadStdoutEvent) +{ + emitSignal("readyReadStdout",c); + return true; +} + +KVSO_CLASS_FUNCTION(process,readyReadStderrEvent) +{ + emitSignal("readyReadStderr",c); + return true; +} +KVSO_CLASS_FUNCTION(process,writeToStdin) +{ + CHECK_INTERNAL_POINTER(m_pProcess) + QString szCommand; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("command",KVS_PT_STRING,0,szCommand) + KVSO_PARAMETERS_END(c) + if (m_pProcess) m_pProcess->write(szCommand.toUtf8().data()); + return true; +} +//-->The 3 Closing process functions +KVSO_CLASS_FUNCTION(process,closekill) +{ + CHECK_INTERNAL_POINTER(m_pProcess) + //I try to to terminate the process the nice way.... + m_pProcess->terminate(); + //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; +} +KVSO_CLASS_FUNCTION(process,kill) +{ + CHECK_INTERNAL_POINTER(m_pProcess) + m_pProcess->kill(); + return true; +} +KVSO_CLASS_FUNCTION(process,tryTerminate) +{ + CHECK_INTERNAL_POINTER(m_pProcess) + m_pProcess->terminate(); + return true; +} +//-->Close the standard input. +KVSO_CLASS_FUNCTION(process,closeStdin) +{ + CHECK_INTERNAL_POINTER(m_pProcess) + m_pProcess->closeReadChannel(QProcess::StandardOutput); + return true; +} +//->Returns if the process still runnig +KVSO_CLASS_FUNCTION(process,isRunning) +{ + CHECK_INTERNAL_POINTER(m_pProcess) + c->returnValue()->setBoolean(m_pProcess->state()==QProcess::Running); + return true; +} +//->Returns if the process exited. +KVSO_CLASS_FUNCTION(process,normalExit) +{ + CHECK_INTERNAL_POINTER(m_pProcess) + c->returnValue()->setBoolean(m_pProcess->state()==QProcess::NotRunning && m_pProcess->exitStatus()==QProcess::NormalExit); + return true; +} + +void KvsObject_process::slotReadStdout() +{ + KviKvsVariantList *params=0; + callFunction(this,"readyReadStdoutEvent",params); +} + +void KvsObject_process::slotReadStderr() +{ + KviKvsVariantList *params=0; + callFunction(this,"readyReadStderrEvent",params); +} + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_process.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES + diff --git a/src/modules/objects/KvsObject_process.h b/src/modules/objects/KvsObject_process.h new file mode 100644 index 000000000..f2726f225 --- /dev/null +++ b/src/modules/objects/KvsObject_process.h @@ -0,0 +1,69 @@ +#ifndef _CLASS_PROCESS_H_ +#define _CLASS_PROCESS_H_ +//============================================================================= +// +// File : KvsObject_process.h +// Creation date : Fri Mar 18 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_widget.h" + + +#include "object_macros.h" +#include "QProcess" + + +class KvsObject_process : public KviKvsObject +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_process) +protected: + QProcess * m_pProcess; +private: + QStringList m_szArgs; +public: + + bool addArgument(KviKvsObjectFunctionCall *c); + bool startProcess(KviKvsObjectFunctionCall *c); + bool readStdout(KviKvsObjectFunctionCall *c); + bool readStderr(KviKvsObjectFunctionCall *c); + bool writeToStdin(KviKvsObjectFunctionCall *c); + bool closekill(KviKvsObjectFunctionCall *c); + bool closeStdin(KviKvsObjectFunctionCall *c); + bool kill(KviKvsObjectFunctionCall *c); + bool tryTerminate(KviKvsObjectFunctionCall *c); + bool normalExit(KviKvsObjectFunctionCall *c); + bool isRunning(KviKvsObjectFunctionCall *c); + + bool readyReadStdoutEvent(KviKvsObjectFunctionCall *c); + bool readyReadStderrEvent(KviKvsObjectFunctionCall *c); + +protected slots: + void slotReadStdout(); + void slotReadStderr(); +}; + + +#endif // !_CLASS_PROCESS_H_ diff --git a/src/modules/objects/KvsObject_progressBar.cpp b/src/modules/objects/KvsObject_progressBar.cpp new file mode 100644 index 000000000..07cddba24 --- /dev/null +++ b/src/modules/objects/KvsObject_progressBar.cpp @@ -0,0 +1,150 @@ +//============================================================================= +// +// File : KvsObject_progressBar.cpp +// 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_progressBar.h" +#include "KviError.h" +#include "kvi_debug.h" + +#include "KviLocale.h" +#include "KviIconManager.h" +#include + + + + +/* + @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: $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(KvsObject_progressBar,"progressbar","widget") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_progressBar,setProgress) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_progressBar,setFormat) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_progressBar,setTotalSteps) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_progressBar,reset) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_progressBar,setPercentageVisible) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_progressBar,percentageVisible) +KVSO_END_REGISTERCLASS(KvsObject_progressBar) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_progressBar,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_progressBar) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_progressBar) + +KVSO_END_CONSTRUCTOR(KvsObject_progressBar) + +bool KvsObject_progressBar::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT (QProgressBar) + return true; +} +KVSO_CLASS_FUNCTION(progressBar,setProgress) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t iValue; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("step_value",KVS_PT_UNSIGNEDINTEGER,0,iValue) + KVSO_PARAMETERS_END(c) + ((QProgressBar *)widget())->setValue(iValue); + return true; +} + +KVSO_CLASS_FUNCTION(progressBar,setTotalSteps) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t iMax; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("total_steps",KVS_PT_UNSIGNEDINTEGER,0,iMax) + KVSO_PARAMETERS_END(c) + ((QProgressBar *)widget())->setMaximum(iMax); + return true; +} + +KVSO_CLASS_FUNCTION(progressBar,reset) +{ + CHECK_INTERNAL_POINTER(widget()) + ((QProgressBar *)widget())->reset(); + return true; +} + + +KVSO_CLASS_FUNCTION(progressBar,setPercentageVisible) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + ((QProgressBar *)widget())->setTextVisible(bEnabled); + return true; +} +KVSO_CLASS_FUNCTION(progressBar,setFormat) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szFormat; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_STRING,0,szFormat) + KVSO_PARAMETERS_END(c) + ((QProgressBar *)widget())->setFormat(szFormat); + return true; +} +KVSO_CLASS_FUNCTION(progressBar,percentageVisible) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setBoolean(((QProgressBar *)widget())->isTextVisible()); + return true; +} + + diff --git a/src/modules/objects/KvsObject_progressBar.h b/src/modules/objects/KvsObject_progressBar.h new file mode 100644 index 000000000..9b27177e1 --- /dev/null +++ b/src/modules/objects/KvsObject_progressBar.h @@ -0,0 +1,51 @@ +#ifndef _CLASS_PROGRESSBAR_H_ +#define _CLASS_PROGRESSBAR_H_ +//============================================================================= +// +// File : KvsObject_progressBar.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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_widget.h" +#include "object_macros.h" + +class KvsObject_progressBar : public KvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KvsObject_progressBar) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool setProgress(KviKvsObjectFunctionCall *c); + bool setTotalSteps(KviKvsObjectFunctionCall *c); + bool reset(KviKvsObjectFunctionCall *c); + bool setPercentageVisible(KviKvsObjectFunctionCall *c); + bool percentageVisible(KviKvsObjectFunctionCall *c); + bool setFormat(KviKvsObjectFunctionCall *c); +}; + + +#endif //!_CLASS_PROGRESSBAR_H_ + diff --git a/src/modules/objects/KvsObject_radioButton.cpp b/src/modules/objects/KvsObject_radioButton.cpp new file mode 100644 index 000000000..1b8be1a93 --- /dev/null +++ b/src/modules/objects/KvsObject_radioButton.cpp @@ -0,0 +1,146 @@ +//============================================================================= +// +// File : KvsObject_radioButton.cpp +// 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_radioButton.h" +#include "KviError.h" +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KviIconManager.h" + +#include +/* + @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(KvsObject_radioButton,"radiobutton","widget") + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_radioButton,setText) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_radioButton,setChecked) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_radioButton,isChecked) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_radioButton,setImage) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_radioButton,toggleEvent) + +KVSO_END_REGISTERCLASS(KvsObject_radioButton) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_radioButton,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_radioButton) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_radioButton) + +KVSO_END_CONSTRUCTOR(KvsObject_radioButton) + +bool KvsObject_radioButton::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT(QRadioButton) + connect(widget(),SIGNAL(toggled(bool)),this,SLOT(toggled(bool))); + return true; +} +KVSO_CLASS_FUNCTION(radioButton,setText) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + ((QRadioButton *)widget())->setText(szText); + return true; +} +KVSO_CLASS_FUNCTION(radioButton,isChecked) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setBoolean(((QRadioButton *)widget())->isChecked()); + return true; +} + +KVSO_CLASS_FUNCTION(radioButton,setChecked) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bChecked; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bChecked",KVS_PT_BOOL,0,bChecked) + KVSO_PARAMETERS_END(c) + ((QRadioButton *)widget())->setChecked(bChecked); + return true; +} +KVSO_CLASS_FUNCTION(radioButton,setImage) +{ + CHECK_INTERNAL_POINTER(widget()) + QString icon; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("icon_id",KVS_PT_STRING,0,icon) + KVSO_PARAMETERS_END(c) + QPixmap * pix = g_pIconManager->getImage(icon); + if(pix)((QRadioButton *)widget())->setIcon(*pix); + return true; +} +KVSO_CLASS_FUNCTION(radioButton,toggleEvent) +{ + emitSignal("toggled",c,c->params()); + return true; +} + +void KvsObject_radioButton::toggled(bool b) +{ + KviKvsVariantList params(new KviKvsVariant(b)); + callFunction(this,"toggleEvent",¶ms); +} + + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_radioButton.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES + diff --git a/src/modules/objects/KvsObject_radioButton.h b/src/modules/objects/KvsObject_radioButton.h new file mode 100644 index 000000000..00cdb9f6a --- /dev/null +++ b/src/modules/objects/KvsObject_radioButton.h @@ -0,0 +1,51 @@ +#ifndef _CLASS_RADIOBUTTON_H_ +#define _CLASS_RADIOBUTTON_H_ +//============================================================================= +// +// File : KvsObject_radioButton.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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_widget.h" +#include "object_macros.h" + +class KvsObject_radioButton : public KvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_radioButton) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool setText(KviKvsObjectFunctionCall *c); + bool isChecked(KviKvsObjectFunctionCall *c); + bool setChecked(KviKvsObjectFunctionCall *c); + bool setImage(KviKvsObjectFunctionCall *c); + bool toggleEvent(KviKvsObjectFunctionCall *c); +protected slots: + void toggled(bool b); + +}; + +#endif //!_CLASS_RADIOBUTTON_H_ diff --git a/src/modules/objects/KvsObject_slider.cpp b/src/modules/objects/KvsObject_slider.cpp new file mode 100644 index 000000000..7bf2f4923 --- /dev/null +++ b/src/modules/objects/KvsObject_slider.cpp @@ -0,0 +1,301 @@ +//============================================================================= +// +// File : KvsObject_slider.cpp +// 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_slider.h" +#include "KviError.h" +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KviIconManager.h" + +#include + + +/* +@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(KvsObject_slider,"slider","widget") + + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setTracking); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setValue); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setMinValue); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setMaxValue); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setLineStep); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setPageStep); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setTickInterval); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,value); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,minValue); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,maxValue); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,lineStep); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,pageStep); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setTickmarks); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,setOrientation); + + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_slider,valueChangedEvent); +KVSO_END_REGISTERCLASS(KvsObject_slider) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_slider,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_slider) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_slider) + +KVSO_END_CONSTRUCTOR(KvsObject_slider) + +bool KvsObject_slider::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT(QSlider) + connect(widget(),SIGNAL(valueChanged(int)),this,SLOT(valueChanged(int))); + return true; +} + +KVSO_CLASS_FUNCTION(slider,setTracking) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + ((QSlider *)widget())->setTracking(bEnabled); + return true; +} + + +KVSO_CLASS_FUNCTION(slider,setValue) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iValue; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("value",KVS_PT_INT,0,iValue) + KVSO_PARAMETERS_END(c) + ((QSlider *)widget())->setValue(iValue); + return true; +} +KVSO_CLASS_FUNCTION(slider,setMinValue) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iMinvalue; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("minimum_value",KVS_PT_INT,0,iMinvalue) + KVSO_PARAMETERS_END(c) + ((QSlider *)widget())->setMinimum(iMinvalue); + return true; +} +KVSO_CLASS_FUNCTION(slider,setMaxValue) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iMaxvalue; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("max_value",KVS_PT_INT,0,iMaxvalue) + KVSO_PARAMETERS_END(c) + ((QSlider *)widget())->setMaximum(iMaxvalue); + return true; +} + +KVSO_CLASS_FUNCTION(slider,setLineStep) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iLinestep; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("line_step",KVS_PT_INT,0,iLinestep) + KVSO_PARAMETERS_END(c) + ((QSlider *)widget())->setSingleStep(iLinestep); + return true; +} +KVSO_CLASS_FUNCTION(slider,setPageStep) +{ + CHECK_INTERNAL_POINTER(widget()) + 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; +} + +KVSO_CLASS_FUNCTION(slider,setTickInterval) +{ + kvs_int_t iInterval; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("tick_interval",KVS_PT_INT,0,iInterval) + KVSO_PARAMETERS_END(c) + ((QSlider *)widget())->setTickInterval(iInterval); + return true; +} + +KVSO_CLASS_FUNCTION(slider,value) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QSlider *)widget())->value()); + return true; +} + +KVSO_CLASS_FUNCTION(slider,minValue) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QSlider *)widget())->minimum()); + return true; +} +KVSO_CLASS_FUNCTION(slider,maxValue) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QSlider *)widget())->maximum()); + return true; +} +KVSO_CLASS_FUNCTION(slider,lineStep) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QSlider *)widget())->singleStep()); + return true; +} + +KVSO_CLASS_FUNCTION(slider,pageStep) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QSlider *)widget())->pageStep()); + return true; +} + + +KVSO_CLASS_FUNCTION(slider,setTickmarks) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szTick; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("tick_marks",KVS_PT_STRING,0,szTick) + KVSO_PARAMETERS_END(c) + if(KviQString::equalCI(szTick,"NoMarks")) + ((QSlider *)widget())->setTickPosition(QSlider::NoTicks); + else if(KviQString::equalCI(szTick,"Both")) + ((QSlider *)widget())->setTickPosition(QSlider::TicksBothSides); + else if(KviQString::equalCI(szTick,"Above")) + ((QSlider *)widget())->setTickPosition(QSlider::TicksAbove); + else if(KviQString::equalCI(szTick,"Below")) + ((QSlider *)widget())->setTickPosition(QSlider::TicksBelow); + else if(KviQString::equalCI(szTick,"Left")) + ((QSlider *)widget())->setTickPosition(QSlider::TicksLeft); + else if(KviQString::equalCI(szTick,"Right")) + ((QSlider *)widget())->setTickPosition(QSlider::TicksRight); + else c->warning( __tr2qs_ctx("Unknown tickmark '%Q'","objects"),&szTick); + return true; +} +KVSO_CLASS_FUNCTION(slider,setOrientation) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szOrientation; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("orientation",KVS_PT_STRING,0,szOrientation) + KVSO_PARAMETERS_END(c) + 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_ctx("Unknown orientation '%Q'","objects"),&szOrientation); + return true; +} +KVSO_CLASS_FUNCTION(slider,valueChangedEvent) +{ + emitSignal("valueChanged",c,c->params()); + return true; +} + +void KvsObject_slider::valueChanged(int value) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)value)); + callFunction(this,"valueChangedEvent",¶ms); +} + + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_slider.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES + diff --git a/src/modules/objects/KvsObject_slider.h b/src/modules/objects/KvsObject_slider.h new file mode 100644 index 000000000..7474d0db0 --- /dev/null +++ b/src/modules/objects/KvsObject_slider.h @@ -0,0 +1,64 @@ +#ifndef _CLASS_SLIDER_H_ +#define _CLASS_SLIDER_H_ +//============================================================================= +// +// File : KvsObject_slider.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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_widget.h" +#include "object_macros.h" + +class KvsObject_slider : public KvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_slider) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool setTracking(KviKvsObjectFunctionCall *c); + bool setValue(KviKvsObjectFunctionCall *c); + bool setMinValue(KviKvsObjectFunctionCall *c); + bool setMaxValue(KviKvsObjectFunctionCall *c); + bool setLineStep(KviKvsObjectFunctionCall *c); + bool setPageStep(KviKvsObjectFunctionCall *c); + bool setTickInterval(KviKvsObjectFunctionCall *c); + bool value(KviKvsObjectFunctionCall *c); + bool minValue(KviKvsObjectFunctionCall *c); + bool maxValue(KviKvsObjectFunctionCall *c); + bool lineStep(KviKvsObjectFunctionCall *c); + bool pageStep(KviKvsObjectFunctionCall *c); + bool setTickmarks(KviKvsObjectFunctionCall *c); + bool setOrientation(KviKvsObjectFunctionCall *c); + bool valueChangedEvent(KviKvsObjectFunctionCall *c); + +protected slots: + void valueChanged(int); +}; + + + +#endif // !_CLASS_SLIDER_H_ + diff --git a/src/modules/objects/KvsObject_socket.cpp b/src/modules/objects/KvsObject_socket.cpp new file mode 100644 index 000000000..6c40f8ea2 --- /dev/null +++ b/src/modules/objects/KvsObject_socket.cpp @@ -0,0 +1,1297 @@ +//============================================================================= +// +// File : KvsObject_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-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "KvsObject_socket.h" +#include "KvsObject_memoryBuffer.h" +#include "KvsObject_file.h" + +#include "kvi_settings.h" +#include "KviQString.h" + +#define _KVI_DEBUG_CHECK_RANGE_ +#include "kvi_debug.h" + +#include "KviFile.h" +#include "KviFileUtils.h" +#include "KviLocale.h" +#include "KviError.h" +#include "KviNetUtils.h" +#include "KviDnsResolver.h" +#include "KviError.h" +#include "kvi_socket.h" +#include "KviMemory.h" +#include "KviMemory.h" +#include "KviDataBuffer.h" + +#include + +//#include + +#define KVI_IN_BUFFER_ALLOC_CHUNK 4096 +#define KVI_READ_CHUNK 1024 + +/* + @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 successfully 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 successfully 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] + By default this function can deal ascii data only: NULL characters are transformed to + ASCII characters 255. You can pass a [class]memorybuffer[/class] object to read binary data. + + !fn: $write([,length]) + Writes to the socket.[br] + This function can deal with binary data passing a [class]memorybuffer[/class] object[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] + Using an array you can pass bytes or data string like this: @$write($array($(0xff),$(0xff),$(0xff),$(0xff),"This is an example")); + 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: $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 or 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 8080 port and answer to requests (multi-threaded) + class (webserver,socket) + { + constructor () + { + @$listen(8080, "127.0.0.1") + } + incomingConnectionEvent() + { + %tmp = $new(socket) + @$accept(%tmp) + echo "Webserver incoming Conection from: %tmp->$remoteIp : %tmp->$remotePort" + %tmp->$write("HTTP/1.1 200 OK\n\n

KVIrc Webserver

\n") + %tmp->$close() + delete %tmp + } + } + // finally start webserver + %WebS = $new(webserver) + [/example] + [example] + // Client socket - go to google and grab request header[br] + class (httprequest,socket) + { + constructor () + { + // connect to the server + @$connect("www.google.com",80) + } + destructor() + { + // if the socket is still open close it + if(@$status() == 4) @$close() + } + connectFailedEvent() + { + // the connection to the server failed + debug "Connection failed: "$0 + delete $$ + } + connectEvent() + { + // connection is complete + // send a request to receive the headers only from http://www.google.com/ + @$write("HEAD / HTTP/1.1\r\nHost: www.google.de\r\nConnction: Close\r\nUser-Agent: KVIrc socket\r\n\r\n"); + } + dataAvailableEvent() + { + // reading the received data + %newdata = @$read($0) + echo %newdata + #close and delete the socket + @$close() + delete $$ + } + disconnectEvent() + { + // connection has been closed + echo "Connection closed" + delete $$ + } + } + %Temp = $new(httprequest) + [/example] +*/ + +KVSO_BEGIN_REGISTERCLASS(KvsObject_socket,"socket","object") + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_socket,status) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_socket,remotePort) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_socket,remoteIp) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_socket,localIp) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_socket,localPort) + KVSO_REGISTER_HANDLER(KvsObject_socket,"connect",functionConnect) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_socket,connectTimeout) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_socket,setConnectTimeout) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_socket,close) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_socket,read) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_socket,write) + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_socket,setProtocol) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_socket,listen) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_socket,accept) + + KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KvsObject_socket,"connectEvent") + KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KvsObject_socket,"connectFailedEvent") + KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KvsObject_socket,"disconnectEvent") + KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KvsObject_socket,"dataAvailableEvent") + KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KvsObject_socket,"incomingConnectionEvent") + +KVSO_END_REGISTERCLASS(KvsObject_socket) + + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_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(KvsObject_socket) + +KVSO_BEGIN_DESTRUCTOR(KvsObject_socket) + delete m_pOutBuffer; + delete m_pFlushTimer; + m_pOutBuffer=0; + m_pFlushTimer=0; + + + if(m_pInBuffer)KviMemory::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(KvsObject_socket) +//---------------------- + + +KVSO_CLASS_FUNCTION(socket,status) +{ + c->returnValue()->setInteger(m_iStatus); + return true; +} + +KVSO_CLASS_FUNCTION(socket,close) +{ + Q_UNUSED(c); + + if (!m_pOutBuffer) return true; + if((m_pOutBuffer->size() != 0) && (m_iStatus == KVI_SCRIPT_SOCKET_STATUS_CONNECTED)) + tryFlush(); + + reset(); + return true; +} + +KVSO_CLASS_FUNCTION(socket,connectTimeout) +{ + c->returnValue()->setInteger(m_uConnectTimeout); + return true; +} + +KVSO_CLASS_FUNCTION(socket,setConnectTimeout) +{ + 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; +} + +KVSO_CLASS_FUNCTION(socket,remotePort) +{ + c->returnValue()->setInteger(m_uRemotePort); + return true; +} + +KVSO_CLASS_FUNCTION(socket,remoteIp) +{ + c->returnValue()->setString(m_szRemoteIp); + return true; +} + +KVSO_CLASS_FUNCTION(socket,localPort) +{ + c->returnValue()->setInteger(m_uLocalPort); + return true; +} + +KVSO_CLASS_FUNCTION(socket,localIp) +{ + c->returnValue()->setString(m_szLocalIp); + return true; +} + +unsigned int KvsObject_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; +} + +KVSO_CLASS_FUNCTION(socket,read) +{ + kvs_uint_t uLen; + KviKvsObject * pObject; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("length",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,uLen) + KVSO_PARAMETER("hobject",KVS_PT_HOBJECT,KVS_PF_OPTIONAL,hObject) + KVSO_PARAMETERS_END(c) + if (uLen>m_uInDataLen || !uLen) uLen=m_uInDataLen; + if (hObject) + { + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if(!pObject) + { + c->warning(__tr2qs_ctx("Buffer parameter is not an object","objects")); + return true; + } + if(pObject->inheritsClass("memorybuffer")) + { + QByteArray *pBuffer=((KvsObject_memoryBuffer *)pObject)->pBuffer(); + int oldsize=pBuffer->size(); + pBuffer->resize(oldsize+uLen); + KviMemory::move(pBuffer->data()+oldsize,m_pInBuffer,uLen); + + } else if(pObject->inheritsClass("file")) + { + KviFile *pFile=((KvsObject_file *)pObject)->file(); + if (!pFile->isOpen()) + { + c->warning(__tr2qs_ctx("File is not open!","objects")); + return true; + } + pFile->write(m_pInBuffer,uLen); + } else + { + c->warning(__tr2qs_ctx("Buffer parameter is not a memorybuffer object","objects")); + return true; + } + eatInData(uLen); + return true; + } + 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; +} + + + +KVSO_CLASS_FUNCTION(socket,write) +{ + kvs_uint_t uLen; + KviKvsObject * pObject; + KviKvsVariant * pVariantData; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("data_or_file_or_memorybuffer",KVS_PT_VARIANT,0,pVariantData) + KVSO_PARAMETER("length",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,uLen) + KVSO_PARAMETERS_END(c) + if (pVariantData->isHObject()) + { + pVariantData->asHObject(hObject); + pObject = KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if(!pObject) + { + c->warning(__tr2qs_ctx("Buffer parameter is not an object","objects")); + return true; + } + if(pObject->inheritsClass("memorybuffer")) + { + QByteArray *p=((KvsObject_memoryBuffer *)pObject)->pBuffer(); + m_pOutBuffer->append((const unsigned char *)p->data(),p->size()); + } else if(pObject->inheritsClass("file")) + { + KviFile * pFile = ((KvsObject_file *)pObject)->file(); + if(!pFile->isOpen()) + { + c->warning(__tr2qs_ctx("File is not open!","objects")); + return true; + } + if(!uLen) + uLen = pFile->size(); + kvs_int_t size = pFile->size(); + pFile->flush(); + m_pOutBuffer->append((const unsigned char*)pFile->read(uLen).data(),uLen); + c->returnValue()->setBoolean((size-pFile->pos()==0)); + } else { + c->warning(__tr2qs_ctx("Buffer parameter is not a memorybuffer or file object","objects")); + return true; + } + } else { + if(pVariantData->isArray()) + { + KviKvsArray * pArray = pVariantData->array(); + for(unsigned int i=0; i < pArray->size(); i++) + { + KviKvsVariant * pVar = pArray->at(i); + kvs_int_t iValue; + if(pVar->asInteger(iValue)) + { + if(iValue < 256 && iValue >= 0) + { + m_pOutBuffer->append((unsigned char)iValue); + continue; + } else { + c->warning(__tr2qs_ctx("Only values in the range of 0-255 are allowed: integer %d is out of range","objects"),iValue); + return true; + } + } else { + if(pVar->isString()) + { + QString szData; + pVar->asString(szData); + QByteArray szData8 = szData.toUtf8(); + m_pOutBuffer->append((const unsigned char*)szData8.data(),szData8.length()); + } else { + c->warning(__tr2qs_ctx("Datatype not supported","objects")); + return true; + } + } + } + delayedFlush(0); + return true; + } + + QString szData; + pVariantData->asString(szData); + if(!KviFileUtils::fileExists(szData)) + { + QByteArray szData8 = szData.toUtf8(); + if(szData8.length() > 0) + { + qDebug("write on socket %s",szData8.data()); + m_pOutBuffer->append((const unsigned char*)szData8.data(),szData8.length()); + } + } else { + KviFile f(szData); + f.open(QIODevice::ReadOnly); + QByteArray ar = f.readAll(); + m_pOutBuffer->append((const unsigned char*)ar.data(),ar.size()); + f.close(); + } + } + delayedFlush(0); + return true; +} + + +KVSO_CLASS_FUNCTION(socket,accept) +{ + 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_ctx("No socket object specified","objects")); + return true; + } + + if(!pObject->inheritsClass("socket")) + { + c->warning(__tr2qs_ctx("Invalid socket object specified (it doesn't inherit from socket)","objects")); + return true; + } + + if(m_secondarySock != KVI_INVALID_SOCKET) + { + ((KvsObject_socket *)pObject)->acceptConnection(m_secondarySock,m_uSecondaryPort,m_szSecondaryIp.toUtf8().data()); + + m_secondarySock = KVI_INVALID_SOCKET; + m_uSecondaryPort = 0; + m_szSecondaryIp=""; + } else { + c->warning(__tr2qs_ctx("There is no connection to accept!","objects")); + } + return true; +} + + +KVSO_CLASS_FUNCTION(socket,setProtocol) +{ + QString szProto; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("protocol",KVS_PT_STRING,0,szProto) + KVSO_PARAMETERS_END(c) + + m_bUdp = KviQString::equalCI(szProto,"udp"); + return true; +} + +KVSO_CLASS_FUNCTION(socket,functionConnect) +{ + 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) + qDebug("Function connect"); + + if (m_uRemotePort>65535) + { + c->warning(__tr2qs_ctx("Value %d for port is out of range (values allowed are from 0 to 65535)","objects"),m_uRemotePort); + return true; + } + if((m_sock != KVI_INVALID_SOCKET) || (m_iStatus != KVI_SCRIPT_SOCKET_STATUS_DISCONNECTED)) + { + c->warning(__tr2qs_ctx("Another connection in progress","objects")); + c->returnValue()->setBoolean(true); + return true; + } + + +#ifdef COMPILE_IPV6_SUPPORT + if(KviNetUtils::isValidStringIp(m_szRemoteIp) || KviNetUtils::isValidStringIPv6(m_szRemoteIp)) +#else + if(KviNetUtils::isValidStringIp(m_szRemoteIp)) +#endif + { + qDebug("ok connecting"); + qDebug("connecting to ip %s ",m_szRemoteIp.toUtf8().data()); + qDebug("no ip"); + m_iStatus = KVI_SCRIPT_SOCKET_STATUS_CONNECTING; + delayedConnect(); + } else { + qDebug("connecting on ip %s port %d",m_szRemoteIp.toUtf8().data(),(int) m_uRemotePort); + m_iStatus = KVI_SCRIPT_SOCKET_STATUS_DNS; + delayedLookupRemoteIp(); + } + c->returnValue()->setBoolean(true); + return true; +} + + +KVSO_CLASS_FUNCTION(socket,listen) +{ + if((m_sock != KVI_INVALID_SOCKET) || (m_iStatus != KVI_SCRIPT_SOCKET_STATUS_DISCONNECTED)) + { + c->warning(__tr2qs_ctx("Another connection in progress","objects")); + 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_ctx("No IPv6 support in this executable","objects")); + c->returnValue()->setBoolean(false); + reset(); + return true; + } +#endif + + if(!m_szLocalIp.isEmpty()) + { + + // Check the address type + if(!KviNetUtils::isValidStringIp(m_szLocalIp)) + { +#ifdef COMPILE_IPV6_SUPPORT + if(KviNetUtils::isValidStringIPv6(m_szLocalIp)) + { + m_bIPv6 = true; + } else { +#else + c->warning(__tr2qs_ctx("Invalid IP address (%Q)","objects"),&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_ctx("Socket creation failed","objects")); + c->returnValue()->setBoolean(false); + reset(); + return true; + } + + if(!m_szLocalIp.isEmpty()) + { +#ifdef COMPILE_IPV6_SUPPORT + KviSockaddr sa(m_szLocalIp.toUtf8().data(),m_uLocalPort,m_bIPv6,m_bUdp); +#else + KviSockaddr sa(m_szLocalIp.toUtf8().data(),m_uLocalPort,false,m_bUdp); +#endif + if(!sa.socketAddress()) + { + c->warning(__tr2qs_ctx("Invalid socket address","objects")); + reset(); + c->returnValue()->setBoolean(false); + return true; + } + + if(!kvi_socket_bind(m_sock,sa.socketAddress(),((int)(sa.addressLength())))) + { + c->warning(__tr2qs_ctx("Bind failure","objects")); + 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_ctx("Invalid socket address","objects")); + reset(); + c->returnValue()->setBoolean(false); + return true; + } + + if(!kvi_socket_bind(m_sock,sa.socketAddress(),((int)(sa.addressLength())))) + { + c->warning(__tr2qs_ctx("Bind failure","objects")); + reset(); + c->returnValue()->setBoolean(false); + return true; + } + } + + if(!kvi_socket_listen(m_sock,5)) + { + c->warning(__tr2qs_ctx("Listen failure","objects")); + 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 KvsObject_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(!KviNetUtils::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(!KviNetUtils::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 KvsObject_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 KvsObject_socket::delayedConnect() +{ + if(m_pDelayTimer)delete m_pDelayTimer; + m_pDelayTimer = new QTimer(); + connect(m_pDelayTimer,SIGNAL(timeout()),this,SLOT(doConnect())); + m_pDelayTimer->setInterval(0); + m_pDelayTimer->setSingleShot(true); + m_pDelayTimer->start(); +} + +void KvsObject_socket::doConnect() +{ + qDebug("doConnect function"); + if(m_pDelayTimer)delete m_pDelayTimer; + m_pDelayTimer = 0; + + + KviSockaddr sa(m_szRemoteIp.toUtf8().data(),m_uRemotePort,!KviNetUtils::isValidStringIp(m_szRemoteIp),m_bUdp); + + if(!sa.socketAddress()) + { + unsigned int uOldConnectionId = m_uConnectionId; + QString ipAddressError=__tr2qs_ctx("Invalid IP address ","objects"); + + ipAddressError.append(m_szRemoteIp); + + KviKvsVariantList params; + QString tmp; + KviQString::sprintf(tmp,__tr2qs_ctx("Invalid IP address (%Q)","objects"),&m_szRemoteIp); + params.append(new KviKvsVariant(tmp)); + callFunction(this,"connectFailedEvent",¶ms); + if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! + return; + } +qDebug("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; + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(__tr2qs_ctx("Failed to create the socket","objects"))); + callFunction(this,"connectFailedEvent",&lParams); + if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! + return; + } + qDebug("Valid socket"); + + if(!kvi_socket_setNonBlocking(m_sock)) + { + unsigned int uOldConnectionId = m_uConnectionId; + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(__tr2qs_ctx("Failed to setup a nonblocking socket","objects"))); + callFunction(this,"connectFailedEvent",&lParams); + 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_ctx("Connect failure: ","objects"); + + callBackError.append((KviError::getDescription(KviError::translateSystemError(sockError)).toUtf8().data())); + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(callBackError)); + callFunction(this,"connectFailedEvent",&lParams); + if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! + return; + } + } + qDebug("Socket connected"); + m_pDelayTimer = new QTimer(); + connect(m_pDelayTimer,SIGNAL(timeout()),this,SLOT(connectTimeoutSlot())); + m_pDelayTimer->setInterval(m_uConnectTimeout); + m_pDelayTimer->setSingleShot(true); + m_pDelayTimer->start(); + + 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 KvsObject_socket::connectTimeoutSlot() +{ + unsigned int uOldConnectionId = m_uConnectionId; + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(__tr2qs_ctx("Connect attempt timed out","objects"))); + callFunction(this,"connectFailedEvent",&lParams); + if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! +} + +void KvsObject_socket::delayedLookupRemoteIp() +{ + if(m_pDelayTimer)delete m_pDelayTimer; + m_pDelayTimer = new QTimer(); + connect(m_pDelayTimer,SIGNAL(timeout()),this,SLOT(lookupRemoteIp())); + + m_pDelayTimer->setInterval(0); + m_pDelayTimer->setSingleShot(true); + m_pDelayTimer->start(); +} + +void KvsObject_socket::lookupRemoteIp() +{ + qDebug("Resolve dns"); + if(m_pDelayTimer)delete m_pDelayTimer; + m_pDelayTimer = 0; + if(m_pDns)delete m_pDns; + m_pDns = new KviDnsResolver(); + connect(m_pDns,SIGNAL(lookupDone(KviDnsResolver *)),this,SLOT(lookupDone(KviDnsResolver *))); + if(!m_pDns->lookup(m_szRemoteIp,KviDnsResolver::Any)) + { + unsigned int uOldConnectionId = m_uConnectionId; + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(__tr2qs_ctx("Can't start the DNS thread","objects"))); + callFunction(this,"connectFailedEvent",&lParams); + if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! + } +} + +void KvsObject_socket::lookupDone(KviDnsResolver *pDns) +{ + + if(pDns->state() != KviDnsResolver::Success) + { + unsigned int uOldConnectionId = m_uConnectionId; + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(KviError::getDescription(pDns->error()))); + callFunction(this,"connectFailedEvent",&lParams); + + if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! + return; + } + m_szRemoteIp = pDns->firstIpAddress(); + qDebug("Dns resolved in %s",m_szRemoteIp.toUtf8().data()); + + delete m_pDns; + m_pDns = 0; + doConnect(); +} + +void KvsObject_socket::writeNotifierFired(int) +{ + 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) + { + //qDebug("Failed here %d",sockError); + //failed + KviError::Code eError; + if(sockError > 0) + eError = KviError::translateSystemError(sockError); + else + eError = KviError::UnknownError; //Error 0 ? + unsigned int uOldConnectionId = m_uConnectionId; + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(KviError::getDescription(eError))); + callFunction(this,"connectFailedEvent",&lParams); + 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 KvsObject_socket::readNotifierFired(int) +{ + //read da + if((m_uInBufferLen - m_uInDataLen) < KVI_READ_CHUNK) + { + m_uInBufferLen += KVI_IN_BUFFER_ALLOC_CHUNK; + //m_pInBuffer->resize(m_uInBufferLen); + m_pInBuffer = (char *)KviMemory::reallocate(m_pInBuffer,m_uInBufferLen); + } + + //int readLength = kvi_socket_recv(m_sock,m_pInBuffer->data() + m_uInDataLen,KVI_READ_CHUNK); + 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(); +#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) + 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); + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant((kvs_int_t)KviError::translateSystemError(err))); + callFunction(this,"disconnectEvent",&lParams); + } else { + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(KviError::getDescription(KviError::RemoteEndClosedConnection))); + callFunction(this,"disconnectEvent",&lParams); + + } + 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; + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant((kvs_int_t)readLength)); + callFunction(this,"dataAvailableEvent",&lParams); + unsigned int uOldConnectionId = m_uConnectionId; + if(m_uConnectionId == uOldConnectionId) + { + if(m_uInDataLen > (4096 * 1024)) // too much data in buffer (not reading) + { + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(new KviKvsVariant(__tr2qs_ctx("Too much unprocessed incoming data (you've left this socket unmanaged ?)","objects")))); + callFunction(this,"disconnectEvent",&lParams); + reset(); + } + } +} + +void KvsObject_socket::eatInData(unsigned int uLen) +{ + if(uLen > m_uInDataLen)uLen = m_uInDataLen; + + m_uInDataLen -= uLen; + + if(m_uInDataLen > 0) + { + KviMemory::move(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 *)KviMemory::reallocate(m_pInBuffer,m_uInBufferLen); + } +} + +void KvsObject_socket::delayedFlush(unsigned int uTimeout) +{ + if(m_pFlushTimer->isActive())m_pFlushTimer->stop(); + m_pFlushTimer->start(uTimeout); +} + +void KvsObject_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(); +#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) + 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; + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(KviError::getDescription(KviError::translateSystemError(err)))); + callFunction(this,"disconnectEvent",&lParams); + if(m_uConnectionId == uOldConnectionId)reset(); + // else it has already been called! + return; + } + } +} +void KvsObject_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) + { + KviMemory::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; +} + + + +//-------------- + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_socket.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES + + + + diff --git a/src/modules/objects/KvsObject_socket.h b/src/modules/objects/KvsObject_socket.h new file mode 100644 index 000000000..4b5704620 --- /dev/null +++ b/src/modules/objects/KvsObject_socket.h @@ -0,0 +1,113 @@ +#ifndef _CLASS_SOCKET_H_ +#define _CLASS_SOCKET_H_ +//============================================================================= +// +// File : KvsObject_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 "KviPointerList.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 KviDnsResolver; +class KviDataBuffer; +#include "object_macros.h" + + +class KvsObject_socket : public KviKvsObject +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_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; + KviDnsResolver * 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 status(KviKvsObjectFunctionCall *c); + bool remotePort(KviKvsObjectFunctionCall *c); + bool remoteIp(KviKvsObjectFunctionCall *c); + bool localPort(KviKvsObjectFunctionCall *c); + bool localIp(KviKvsObjectFunctionCall *c); + bool functionConnect(KviKvsObjectFunctionCall *c); + bool setConnectTimeout(KviKvsObjectFunctionCall *c); + bool connectTimeout(KviKvsObjectFunctionCall *c); + + bool close(KviKvsObjectFunctionCall *c); + bool read(KviKvsObjectFunctionCall *c); + bool write(KviKvsObjectFunctionCall *c); + + + bool setProtocol(KviKvsObjectFunctionCall *c); + + bool listen(KviKvsObjectFunctionCall *c); + bool accept(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(KviDnsResolver * pDns); + void connectTimeoutSlot(); + void writeNotifierFired(int); + void readNotifierFired(int); + void tryFlush(); + void incomingConnection(int); +}; +#endif //_CLASS_SOCKET_H_ diff --git a/src/modules/objects/KvsObject_spinBox.cpp b/src/modules/objects/KvsObject_spinBox.cpp new file mode 100644 index 000000000..080cddc0e --- /dev/null +++ b/src/modules/objects/KvsObject_spinBox.cpp @@ -0,0 +1,267 @@ +//============================================================================= +// +// File : KvsObject_spinBox.cpp +// 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_spinBox.h" +#include "KviError.h" +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KviIconManager.h" + +#include +/* + @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(KvsObject_spinBox,"spinbox","widget") + + + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox,setValue); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox,setMinValue); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox,setMaxValue); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox,setLineStep); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox,setSpecialValueText); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox,value); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox,minValue); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox,maxValue); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox,lineStep); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox,specialValueText); + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox,setPrefix); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox,setSuffix); + + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_spinBox,valueChangedEvent); +KVSO_END_REGISTERCLASS(KvsObject_spinBox) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_spinBox,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_spinBox) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_spinBox) + +KVSO_END_CONSTRUCTOR(KvsObject_spinBox) + +bool KvsObject_spinBox::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT(QSpinBox) + connect(widget(),SIGNAL(valueChanged(int)),this,SLOT(valueChanged(int))); + return true; +} + + + +KVSO_CLASS_FUNCTION(spinBox,setValue) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iValue; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("value",KVS_PT_INT,0,iValue) + KVSO_PARAMETERS_END(c) + ((QSpinBox *)widget())->setValue(iValue); + return true; +} +KVSO_CLASS_FUNCTION(spinBox,setMinValue) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iMinvalue; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("min_value",KVS_PT_INT,0,iMinvalue) + KVSO_PARAMETERS_END(c) + ((QSpinBox *)widget())->setMinimum(iMinvalue); + return true; +} +KVSO_CLASS_FUNCTION(spinBox,setMaxValue) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iMaxvalue; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("max_value",KVS_PT_INT,0,iMaxvalue) + KVSO_PARAMETERS_END(c) + ((QSpinBox *)widget())->setMaximum(iMaxvalue); + return true; +} + +KVSO_CLASS_FUNCTION(spinBox,setLineStep) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iLinestep; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("line_step",KVS_PT_INT,0,iLinestep) + KVSO_PARAMETERS_END(c) + ((QSpinBox *)widget())->setSingleStep(iLinestep); + return true; +} + + +KVSO_CLASS_FUNCTION(spinBox,value) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QSpinBox *)widget())->value()); + return true; +} + +KVSO_CLASS_FUNCTION(spinBox,minValue) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QSpinBox *)widget())->minimum()); + return true; +} +KVSO_CLASS_FUNCTION(spinBox,maxValue) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QSpinBox *)widget())->maximum()); + return true; +} +KVSO_CLASS_FUNCTION(spinBox,lineStep) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QSpinBox *)widget())->singleStep()); + return true; +} + + +KVSO_CLASS_FUNCTION(spinBox,specialValueText) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setString(((QSpinBox *)widget())->specialValueText()); + return true; +} + + +KVSO_CLASS_FUNCTION(spinBox,setSpecialValueText) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + ((QSpinBox *)widget())->setSpecialValueText(szText); + return true; +} +KVSO_CLASS_FUNCTION(spinBox,setPrefix) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szPrefix; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szPrefix) + KVSO_PARAMETERS_END(c) + ((QSpinBox *)widget())->setPrefix(szPrefix); + return true; +} +KVSO_CLASS_FUNCTION(spinBox,setSuffix) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szSuffix; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szSuffix) + KVSO_PARAMETERS_END(c) + ((QSpinBox *)widget())->setSuffix(szSuffix); + return true; +} + +KVSO_CLASS_FUNCTION(spinBox,valueChangedEvent) +{ + emitSignal("valueChanged",c,c->params()); + return true; +} + +void KvsObject_spinBox::valueChanged(int value) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)value)); + callFunction(this,"valueChangedEvent",¶ms); +} + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_spinBox.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES + diff --git a/src/modules/objects/KvsObject_spinBox.h b/src/modules/objects/KvsObject_spinBox.h new file mode 100644 index 000000000..c85b4e295 --- /dev/null +++ b/src/modules/objects/KvsObject_spinBox.h @@ -0,0 +1,64 @@ +#ifndef _CLASS_SPINBOX_H_ +#define _CLASS_SPINBOX_H_ +//============================================================================= +// +// File : KvsObject_spinBox.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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_widget.h" +#include "object_macros.h" + +class KvsObject_spinBox : public KvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_spinBox) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool setTracking(KviKvsObjectFunctionCall *c); + + bool setValue(KviKvsObjectFunctionCall *c); + bool setMinValue(KviKvsObjectFunctionCall *c); + bool setMaxValue(KviKvsObjectFunctionCall *c); + bool setLineStep(KviKvsObjectFunctionCall *c); + bool setPrefix(KviKvsObjectFunctionCall *c); + bool setSuffix(KviKvsObjectFunctionCall *c); + bool value(KviKvsObjectFunctionCall *c); + bool minValue(KviKvsObjectFunctionCall *c); + bool maxValue(KviKvsObjectFunctionCall *c); + bool lineStep(KviKvsObjectFunctionCall *c); + bool setSpecialValueText(KviKvsObjectFunctionCall *c); + bool specialValueText(KviKvsObjectFunctionCall *c); + + bool valueChangedEvent(KviKvsObjectFunctionCall *c); + +protected slots: + void valueChanged(int); +}; + +#endif //!_CLASS_SPINBOX_H_ diff --git a/src/modules/objects/KvsObject_sql.cpp b/src/modules/objects/KvsObject_sql.cpp new file mode 100644 index 000000000..2c7b32438 --- /dev/null +++ b/src/modules/objects/KvsObject_sql.cpp @@ -0,0 +1,603 @@ +//============================================================================= +// +// File : KvsObject_sql.cpp +// Creation date : Wed Gen 28 2009 21:07:55 by Alessandro Carbone +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================ + +#include "kvi_debug.h" +#include "KviMemory.h" +#include "KviLocale.h" +#include "KvsObject_sql.h" +#include +#include "KvsObject_memoryBuffer.h" +#include +#include + +static KviPointerList sql_instances; + +static bool checkDuplicatedConnection(QString &szConnectionName) +{ + if(!sql_instances.count()) return false; + bool bFound=false; + for(KvsObject_sql *i = sql_instances.first(); i; i = sql_instances.next()) + { + QSqlQuery *q=i->getQueryConnectionsDict().value(szConnectionName); + if (q) + { + i->closeQueryConnection(q); + bFound=true; + break; + } + } + return bFound; +} +static void KviKvsSqlInstanceRegister(KvsObject_sql *instance) +{ + sql_instances.setAutoDelete(false); + sql_instances.append(instance); +} +static void KviKvsSqlInstanceUnregister(KvsObject_sql *instance) +{ + int idx=sql_instances.findRef(instance); + sql_instances.remove(idx); +} + +#define CHECK_QUERY_IS_INIT if (!m_pCurrentSQlQuery)\ + {\ + c->error("No query has been initialized!");\ + return false;} + + +/* + @doc: sql + @keyterms: + Sql database. + @title: + sql class + @type: + class + @short: + A sql database interface. + @inherits: + [class]object[/class] + @description: + This class permits KVIrc to have an interface with a SQL database supported by Qt library drivers. + @functions: + !fn: $setConnection(,,[,,,]) + Connects to the DBMS using the connection and selecting the database .[br] + If the optional parameter is passed, it will be used the corresponding driver (if present), otherwise Sqlite will be used. + Returns true if the operation is successful, false otherwise. + !fn:: $connectionNames([:'s']) + Returns as array or, if the flag 's' is passed, as a comma separate string all the database active connection's names. + !fn: $tablesList() + Returns as array the database tables list. + !fn: $queryInit() + Initialize the query for the database which has to be already connected. + !fn: $transaction() + Begin a transaction. + !fn: $commit() + Commit the transaction. + !fn: $setCurrentQuery() + Sets the query for the database connection , which has to be already connected, as current query. + !fn: $currentQuery() + Returns the name of the database connection for the current query, or an empty string if there aren't any initialized queries. + !fn: $closeConnection() + Closes the connection . + !fn: $queryResultsSize() + Returns the query size in rows or -1 if the query is empty or the database driver doesn' support the function. + !fn: $lastError() + Returns last error occurred. Use the more_details flag for more info about the error. + !fn: $queryExec([]) + Execs the current query . The string must follow the right syntax against the database in use. + If there are no parameters, it will exec the query previously done. + After the execution, the query will positioned on the first resulting record. + Returns true if the operation is successful, false otherwise. + See also [classfnc]$queryPrepare[/classfnc]() + !fn: $queryPrepare() + Prepare the query to execute. The string must follow the right syntax against the database in use. + It's possible to use the placeholders. It's supported either the identifier ':' and '?' but it's not possible to use them together. + Returns true if the operation is successful, false otherwise. + See also [classfnc]$queryExec[/classfnc]and[classfnc]$queryBindValue[/classfnc. + !fn: $queryBindValue() + Sets the placeholder to be bound to the value in the prepared statement. + Note that the placeholder mark (e.g :) must be included when specifing the placeholder name. + !fn: $queryPrevious() + Sets the current query position to the previous resulting record. + Returns true if the operation is successful, false otherwise. + !fn: $queryNext() + Sets the current query position to the next resulting record. + Returns true if the operation is successful, false otherwise. + !fn: $queryLast() + Sets the current query position to the last resulting record. + Returns true if the operation is successful, false otherwise. + !fn: $queryFirst() + Sets the current query position to the first resulting record. + Returns true if the operation is successful, false otherwise. + !fn: $queryRecord() + Returns a hash containing the current query's record fields. + !fn: $queryFinish() + Sets the current query to inactive. +*/ + + + +KVSO_BEGIN_REGISTERCLASS(KvsObject_sql,"sql","object") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,queryLastInsertId) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,commit) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,beginTransaction) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,setConnection) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,connectionNames) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,setCurrentQuery) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,tablesList) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,currentQuery) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,closeConnection) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,queryInit) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,queryFinish) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,queryResultsSize) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,queryExec) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,queryPrepare) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,queryBindValue) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,queryPrevious) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,queryNext) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,queryLast) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,queryFirst) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,queryRecord) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,lastError) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_sql,features) +KVSO_END_REGISTERCLASS(KvsObject_sql) + + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_sql,KviKvsObject) +m_pCurrentSQlQuery=0; +KviKvsSqlInstanceRegister(this); +KVSO_END_CONSTRUCTOR(KvsObject_sql) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_sql) +QHashIterator t(queryConnectionsDict); +while (t.hasNext()) +{ + t.next(); + QString szConnectionName=t.key(); + queryConnectionsDict.value(szConnectionName)->finish(); + delete queryConnectionsDict.value(szConnectionName); + QSqlDatabase::removeDatabase(szConnectionName); +} +KviKvsSqlInstanceUnregister(this); +queryConnectionsDict.clear(); + +KVSO_END_DESTRUCTOR(KvsObject_sql) + +KVSO_CLASS_FUNCTION(sql,setConnection) +{ + QString szConnectionName,szDbName,szDbDriver,szUserName,szHostName,szPassword; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("connection_name",KVS_PT_STRING,0,szConnectionName) + KVSO_PARAMETER("database_name",KVS_PT_STRING,0,szDbName) + KVSO_PARAMETER("user_name",KVS_PT_STRING,KVS_PF_OPTIONAL,szUserName) + KVSO_PARAMETER("host_name",KVS_PT_STRING,KVS_PF_OPTIONAL,szHostName) + KVSO_PARAMETER("password",KVS_PT_STRING,KVS_PF_OPTIONAL,szPassword) + KVSO_PARAMETER("database_type",KVS_PT_STRING,KVS_PF_OPTIONAL,szDbDriver) + KVSO_PARAMETERS_END(c) + if(!szDbDriver.isEmpty()) + { + QStringList drivers = QSqlDatabase::drivers(); + if (!drivers.contains(szDbDriver)) + { + c->error(__tr2qs_ctx("Missing Qt plugin for database %Q","objects"),&szDbDriver); + return false; + } + } + else szDbDriver="QSQLITE"; + if (checkDuplicatedConnection(szConnectionName)) + { + c->warning(__tr2qs_ctx("Duplicate connection name '%Q', old query connection removed","objects"),&szConnectionName); + } + QSqlDatabase db=QSqlDatabase::addDatabase(szDbDriver,szConnectionName); + db.setDatabaseName(szDbName); + db.setHostName(szHostName); + db.setUserName(szUserName); + db.setPassword(szPassword); + + c->returnValue()->setBoolean(db.open()); + return true; +} + +KVSO_CLASS_FUNCTION(sql,connectionNames) +{ + + QString szFlag; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("stringreturnflag",KVS_PT_STRING,KVS_PF_OPTIONAL,szFlag) + KVSO_PARAMETERS_END(c) + QStringList szConnectionsList=QSqlDatabase::connectionNames(); + if(szFlag.indexOf('s',0,Qt::CaseInsensitive) != -1) + { + QString szConnections=szConnectionsList.join(","); + c->returnValue()->setString(szConnections); + } + else + { + KviKvsArray *pArray=new KviKvsArray(); + for(int i=0;iset(i,new KviKvsVariant(szConnectionsList.at(i))); + } + c->returnValue()->setArray(pArray); + } + return true; +} + +KVSO_CLASS_FUNCTION(sql,queryLastInsertId) +{ + CHECK_QUERY_IS_INIT + QVariant value=m_pCurrentSQlQuery->lastInsertId(); + if (value.type()==QVariant::LongLong){ + c->returnValue()->setInteger((kvs_int_t) value.toLongLong()); + } + return true; + } +KVSO_CLASS_FUNCTION(sql,features) +{ + QString szConnectionName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("connectionName",KVS_PT_STRING,0,szConnectionName) + KVSO_PARAMETERS_END(c) + + QStringList connections = QSqlDatabase::connectionNames(); + if (!connections.contains(szConnectionName)) + { + c->warning(__tr2qs_ctx("Connection %Q does not exists","objects"),&szConnectionName); + return true; + } + QSqlDatabase db=QSqlDatabase::database(szConnectionName); + QSqlDriver *sqlDriver=db.driver(); + QStringList features; + if (sqlDriver->hasFeature(QSqlDriver::Transactions)) features.append("transactions"); + if (sqlDriver->hasFeature(QSqlDriver::QuerySize)) features.append("querysize"); + if (sqlDriver->hasFeature(QSqlDriver::BLOB)) features.append("blob"); + if (sqlDriver->hasFeature(QSqlDriver::PreparedQueries)) features.append("preparedqueries"); + if (sqlDriver->hasFeature(QSqlDriver::NamedPlaceholders)) features.append("namedplaceholders"); + if (sqlDriver->hasFeature(QSqlDriver::PositionalPlaceholders)) features.append("positionaplaceholders"); + if (sqlDriver->hasFeature(QSqlDriver::LastInsertId)) features.append("lastinsertid"); + if (sqlDriver->hasFeature(QSqlDriver::BatchOperations)) features.append("batchoperations"); + if (sqlDriver->hasFeature(QSqlDriver::SimpleLocking)) features.append("simplelocking"); + if (sqlDriver->hasFeature(QSqlDriver::LowPrecisionNumbers)) features.append("lowprecisionnumbers"); + if (sqlDriver->hasFeature(QSqlDriver::EventNotifications)) features.append("eventnotifications"); + if (sqlDriver->hasFeature(QSqlDriver::FinishQuery)) features.append("finishquery"); + if (sqlDriver->hasFeature(QSqlDriver::MultipleResultSets)) features.append("multipleresults"); + c->returnValue()->setString(features.join(",")); + return true; +} + +KVSO_CLASS_FUNCTION(sql,beginTransaction) +{ + QString szConnectionName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("connectionName",KVS_PT_STRING,0,szConnectionName) + KVSO_PARAMETERS_END(c) + + QStringList connections = QSqlDatabase::connectionNames(); + if (!connections.contains(szConnectionName)) + { + c->warning(__tr2qs_ctx("Connection %Q does not exists","objects"),&szConnectionName); + return true; + } + QSqlDatabase db=QSqlDatabase::database(szConnectionName); + db.transaction(); + return true; +} +KVSO_CLASS_FUNCTION(sql,commit) +{ + QString szConnectionName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("connectionName",KVS_PT_STRING,0,szConnectionName) + KVSO_PARAMETERS_END(c) + + QStringList connections = QSqlDatabase::connectionNames(); + if (!connections.contains(szConnectionName)) + { + c->warning(__tr2qs_ctx("Connection %Q does not exists","objects"),&szConnectionName); + return true; + } + QSqlDatabase db=QSqlDatabase::database(szConnectionName); + db.commit(); + return true; +} +KVSO_CLASS_FUNCTION(sql,closeConnection) +{ + QString szConnectionName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("connectionName",KVS_PT_STRING,0,szConnectionName) + KVSO_PARAMETERS_END(c) + + QStringList connections = QSqlDatabase::connectionNames(); + if (!connections.contains(szConnectionName)) + { + c->warning(__tr2qs_ctx("Connection %Q does not exists","objects"),&szConnectionName); + return true; + } + QSqlQuery *q=queryConnectionsDict.value(szConnectionName); + if (q) closeQueryConnection(q); + QSqlDatabase::removeDatabase(szConnectionName); + return true; +} +KVSO_CLASS_FUNCTION(sql,tablesList) +{ + QString szConnectionName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("connectionName",KVS_PT_STRING,0,szConnectionName) + KVSO_PARAMETERS_END(c) + QStringList connections = QSqlDatabase::connectionNames(); + if (!connections.contains(szConnectionName)) + { + c->warning(__tr2qs_ctx("Connection %Q does not exists","objects"),&szConnectionName); + return true; + } + QSqlDatabase db=QSqlDatabase::database(szConnectionName); + QStringList tables=db.tables(); + KviKvsArray *pArray=new KviKvsArray(); + for(int i=0;iset(i,new KviKvsVariant(tables.at(i))); + } + c->returnValue()->setArray(pArray); + return true; +} +KVSO_CLASS_FUNCTION(sql,setCurrentQuery) +{ + QString szConnectionName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("connection_name",KVS_PT_STRING,0,szConnectionName) + KVSO_PARAMETERS_END(c) + QSqlQuery *q=queryConnectionsDict.value(szConnectionName); + if(!q) + { + c->warning(__tr2qs_ctx("Connection query %Q does not exists","objects"),&szConnectionName); + return true; + } + m_pCurrentSQlQuery=q; + return true; +} +KVSO_CLASS_FUNCTION(sql,queryFinish) +{ + QString szConnectionName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("connection_name",KVS_PT_STRING,KVS_PF_OPTIONAL,szConnectionName) + KVSO_PARAMETERS_END(c) + QSqlQuery *q; + if(szConnectionName.isEmpty()) + { + q=m_pCurrentSQlQuery; + if (!q) + { + c->warning(__tr2qs_ctx("No query connection is open","objects")); + return true; + } + } + else + { + q=queryConnectionsDict.value(szConnectionName); + if(!q) + { + c->warning(__tr2qs_ctx("Query for connection %Q does not exists","objects"),&szConnectionName); + return true; + } + } + q->finish(); + return true; +} +KVSO_CLASS_FUNCTION(sql,currentQuery) +{ + if (!m_pCurrentSQlQuery) c->returnValue()->setString(QString()); + else + { + QString szKey=queryConnectionsDict.key(m_pCurrentSQlQuery); + c->returnValue()->setString(szKey); + } + return true; +} +KVSO_CLASS_FUNCTION(sql,queryInit) +{ + QString szConnectionName; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("connection_name",KVS_PT_STRING,0,szConnectionName) + KVSO_PARAMETERS_END(c) + if (queryConnectionsDict.value(szConnectionName)) + { + c->warning(__tr2qs_ctx("Query %Q already initialized","objects"),&szConnectionName); + return true; + } + if(!QSqlDatabase::connectionNames().contains(szConnectionName)) + { + c->error(__tr2qs_ctx("Connection %Q is not open!","objects"),&szConnectionName); + return false; + } + m_pCurrentSQlQuery=new QSqlQuery(QSqlDatabase::database(szConnectionName)); + queryConnectionsDict[szConnectionName]=m_pCurrentSQlQuery; + return true; +} + + +KVSO_CLASS_FUNCTION(sql,queryPrepare) +{ + CHECK_QUERY_IS_INIT + QString szQuery; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("query",KVS_PT_STRING,0,szQuery) + KVSO_PARAMETERS_END(c) + c->returnValue()->setBoolean(m_pCurrentSQlQuery->prepare(szQuery)); + return true; +} +KVSO_CLASS_FUNCTION(sql,queryBindValue) +{ + CHECK_QUERY_IS_INIT + QString szFieldName; + KviKvsVariant *v; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bindName",KVS_PT_STRING,0,szFieldName) + KVSO_PARAMETER("value",KVS_PT_VARIANT,0,v) + KVSO_PARAMETERS_END(c) + QString szType; + v->getTypeName(szType); + if (v->isString()|| v->isNothing()) + { + QString szText; + v->asString(szText); + m_pCurrentSQlQuery->bindValue(szFieldName,QVariant(szText)); + } + else if (v->isReal()) + { + kvs_real_t i; + v->asReal(i); + m_pCurrentSQlQuery->bindValue(szFieldName,QVariant((double)i)); + } + else if (v->isInteger()) + { + kvs_int_t i; + v->asInteger(i); + m_pCurrentSQlQuery->bindValue(szFieldName,QVariant((int)i)); + } + else if (v->isBoolean()) + { + bool b=v->asBoolean(); + m_pCurrentSQlQuery->bindValue(szFieldName,QVariant(b)); + } + else if (v->isHObject()) + { + kvs_hobject_t hOb; + v->asHObject(hOb); + KviKvsObject *pObject; + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hOb); + if (pObject->inheritsClass("memorybuffer")) + m_pCurrentSQlQuery->bindValue(szFieldName,QVariant(*((KvsObject_memoryBuffer *)pObject)->pBuffer())); + else c->warning(__tr2qs_ctx("Only memorybuffer class object is supported","objects")); + } + else + { + QString szTypeName; + v->getTypeName(szTypeName); + c->warning(__tr2qs_ctx("Type value %Q not supported","objects"),&szTypeName); + } + return true; +} + +KVSO_CLASS_FUNCTION(sql,queryExec) +{ + CHECK_QUERY_IS_INIT + QString szQuery; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("query",KVS_PT_STRING,KVS_PF_OPTIONAL,szQuery) + KVSO_PARAMETERS_END(c) + bool bOk; + if (szQuery.isEmpty()) bOk=m_pCurrentSQlQuery->exec(); + else bOk=m_pCurrentSQlQuery->exec(szQuery.toLatin1()); + c->returnValue()->setBoolean(bOk); + return true; +} +KVSO_CLASS_FUNCTION(sql,queryNext) +{ + CHECK_QUERY_IS_INIT + if (m_pCurrentSQlQuery->isActive() && m_pCurrentSQlQuery->isSelect()) c->returnValue()->setBoolean(m_pCurrentSQlQuery->next()); + else c->returnValue()->setNothing(); + return true; +} +KVSO_CLASS_FUNCTION(sql,queryPrevious) +{ + CHECK_QUERY_IS_INIT + if (m_pCurrentSQlQuery->isActive() && m_pCurrentSQlQuery->isSelect()) c->returnValue()->setBoolean(m_pCurrentSQlQuery->previous()); + else c->returnValue()->setNothing(); + return true; +} +KVSO_CLASS_FUNCTION(sql,queryResultsSize) +{ + CHECK_QUERY_IS_INIT + c->returnValue()->setInteger(m_pCurrentSQlQuery->size()); + return true; +} +KVSO_CLASS_FUNCTION(sql,queryFirst) +{ + CHECK_QUERY_IS_INIT + if (m_pCurrentSQlQuery->isActive() && m_pCurrentSQlQuery->isSelect()) c->returnValue()->setBoolean(m_pCurrentSQlQuery->first()); + return true; +} +KVSO_CLASS_FUNCTION(sql,queryLast) +{ + CHECK_QUERY_IS_INIT + if (m_pCurrentSQlQuery->isActive() && m_pCurrentSQlQuery->isSelect()) c->returnValue()->setBoolean(m_pCurrentSQlQuery->last()); + return true; +} +KVSO_CLASS_FUNCTION(sql,queryRecord) +{ + CHECK_QUERY_IS_INIT + KviKvsHash *pHash=new KviKvsHash(); + QSqlRecord record=m_pCurrentSQlQuery->record(); + for(int i=0;iobjectController()->lookupClass("memoryBuffer"); + KviKvsVariantList params(new KviKvsVariant(QString())); + KviKvsObject * pObject = pClass->allocateInstance(0,"",c->context(),¶ms); + *((KvsObject_memoryBuffer *)pObject)->pBuffer()=value.toByteArray(); + pValue=new KviKvsVariant(pObject->handle()); + } + else pValue=new KviKvsVariant(QString()); + pHash->set(record.fieldName(i),pValue); + KviKvsVariant *value2=pHash->get(record.fieldName(i)); + value2->type(); + } + c->returnValue()->setHash(pHash); + return true; +} + +KVSO_CLASS_FUNCTION(sql,lastError) +{ + CHECK_QUERY_IS_INIT + bool bMoreErrorDetails; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("more",KVS_PT_BOOLEAN,KVS_PF_OPTIONAL,bMoreErrorDetails) + KVSO_PARAMETERS_END(c) + QString szError; + QSqlError error=m_pCurrentSQlQuery->lastError(); + if (bMoreErrorDetails) szError=error.text(); + else + { + if (error.type()==QSqlError::StatementError) szError="SyntaxError"; + else if (error.type()==QSqlError::ConnectionError) szError="ConnectionError"; + else if (error.type()==QSqlError::TransactionError) szError="TransactionError"; + else szError="UnkonwnError"; + } + c->returnValue()->setString(szError); + return true; +} +void KvsObject_sql::closeQueryConnection(QSqlQuery * query) +{ + if (query==m_pCurrentSQlQuery) m_pCurrentSQlQuery=0; + query->finish(); + queryConnectionsDict.remove(queryConnectionsDict.key(query)); + delete query; + } + diff --git a/src/modules/objects/KvsObject_sql.h b/src/modules/objects/KvsObject_sql.h new file mode 100644 index 000000000..51ade479b --- /dev/null +++ b/src/modules/objects/KvsObject_sql.h @@ -0,0 +1,79 @@ +#ifndef _CLASS_SQLITE_H_ +#define _CLASS_SQLITE_H_ +//============================================================================= +// +// File : class_sqlite.h +// Creation date : Wed Gen 28 2009 21:07:55 by Alessandro Carbone +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "kvi_settings.h" +#include "KviCString.h" +#include "KviPointerList.h" +#include "KviKvsVariant.h" +#include "object_macros.h" +#include +#include + +class KvsObject_sql : public KviKvsObject +{ +public: + KVSO_DECLARE_OBJECT(KvsObject_sql) +protected: + QSqlQuery *m_pCurrentSQlQuery; + QHash queryConnectionsDict; + + public: + QHash & getQueryConnectionsDict(){return queryConnectionsDict;}; + void closeQueryConnection(QSqlQuery *); + QSqlQuery & getQuery() + { + //if (currentSQlQuery) return *currentSQlQuery; + return *m_pCurrentSQlQuery; + }; + bool setConnection(KviKvsObjectFunctionCall *c); + bool connectionNames(KviKvsObjectFunctionCall *c); + bool features(KviKvsObjectFunctionCall *c); + bool queryLastInsertId(KviKvsObjectFunctionCall *c); + + bool tablesList(KviKvsObjectFunctionCall *c); + bool beginTransaction(KviKvsObjectFunctionCall *c); + bool commit(KviKvsObjectFunctionCall *c); + + bool queryResultsSize(KviKvsObjectFunctionCall *c); + bool queryNext(KviKvsObjectFunctionCall *c); + bool queryPrevious(KviKvsObjectFunctionCall *c); + bool queryFirst(KviKvsObjectFunctionCall *c); + bool queryLast(KviKvsObjectFunctionCall *c); + bool queryExec(KviKvsObjectFunctionCall *c); + bool queryRecord(KviKvsObjectFunctionCall *c); + bool queryPrepare(KviKvsObjectFunctionCall *c); + bool queryBindValue(KviKvsObjectFunctionCall *c); + bool setCurrentQuery(KviKvsObjectFunctionCall *c); + bool currentQuery(KviKvsObjectFunctionCall *c); + bool queryFinish(KviKvsObjectFunctionCall *c); + bool queryInit(KviKvsObjectFunctionCall *c); + bool closeConnection(KviKvsObjectFunctionCall *c); + bool lastError(KviKvsObjectFunctionCall *c); + +}; + + +#endif //_CLASS_SQLITE_H_ diff --git a/src/modules/objects/KvsObject_tabWidget.cpp b/src/modules/objects/KvsObject_tabWidget.cpp new file mode 100644 index 000000000..0d7cc8a34 --- /dev/null +++ b/src/modules/objects/KvsObject_tabWidget.cpp @@ -0,0 +1,456 @@ +//============================================================================= +// +// File : KvsObject_tabWidget.cpp +// 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_tabWidget.h" +#include "KviError.h" +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KviIconManager.h" + +#include + +/* + @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: $tabLabel() + Returns the tab label of the . + !fn: $widgetAt() + Returns the tab widget of the or 0 if index is out of the tabs count. + !fn: $currentTabLabel() + Returns the label of the current tab. + !fn: $removePage() + Remove the page . + !fn: $setTabPosition() + Sets TabPosition. Valid parameters are : Top, Bottom. + !fn: $count() + Returns the number of tabs in the tab bar. + !fn: $setTabsClosable() + Sets whether close buttons are automatically added to each tab + !fn: $currentChangedEvent() + This function is invoched when the current tab was changed.[br] + The default implementation emits the [classfnc]$currentChange[/classfnc]() signal. + !fn: $tabCloseRequestEvent() + This function is invoched when when the close button on a tab is clicked. + The index is the index of the tab that should be removed.[br] + The default implementation emits the [classfnc]$tabCloseRequest[/classfnc]() signal. + See also [classfnc]$setTabsClosable[/classfnc](). + @examples: + [example] + // First we'll create the main tabWidget. + %Tabwidget=$new(tabWidget) + %Tabwidget->$setToolTip("Example of TabWidget class") + %Tabwidget->$setTabPosition(Top) + %Tabwidget->$resize(300,200) + // Now we'll create the new widgets and put they in to the main tabWidget. + %firsttab=$new(vbox) + %secondtab=$new(vbox) + // Now we'll create the item to put in to tab's pages. + // First tab + %hbox=$new(hbox,%firsttab) + %labelbt=$new(label,%hbox) + %labelbt->$settext(Botton Tab) + %labeltt=$new(label,%hbox) + %labeltt->$settext(Top Tab) + %hbox=$new(hbox,%firsttab) + %buttontb=$new(button,%hbox) + %buttontb->$settext("To &Botton") + %buttontt=$new(button,%hbox) + %buttontt->$settext("To &Top") + // Now we'll give a layout to all items. + // This also allows to use privateimpl without making buttons global variables + // 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. + %labelwp=$new(label,%secondtab) + %labelwp->$settext("Enjoy the new Class provided by") + %labelwp->$setalignment("Center") + %labelgen=$new(label,%secondtab) + %labelgen->$settext(Grifisx \& Noldor) + %labelgen->$setalignment("Center") + %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] + !sg: $tabCloseRequest() + This signal is emitted by the default implementation of [classfnc]tabCloseRequestEvent[/classfnc]().[br] +*/ + +KVSO_BEGIN_REGISTERCLASS(KvsObject_tabWidget,"tabWidget","widget") + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tabWidget,addTab) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tabWidget,insertTab) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tabWidget,setTabToolTip) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tabWidget,removeTabToolTip) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tabWidget,setTabLabel) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tabWidget,changeTab) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tabWidget,setCurrentPage) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tabWidget,currentPageIndex) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tabWidget,tabLabel) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tabWidget,currentTabLabel) + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tabWidget,count) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tabWidget,removePage) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tabWidget,widgetAt) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tabWidget,setTabPosition) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tabWidget,setTabsClosable) + + // events + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tabWidget,currentChangedEvent) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tabWidget,tabCloseRequestEvent) + + + +KVSO_END_REGISTERCLASS(KvsObject_tabWidget) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_tabWidget,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_tabWidget) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_tabWidget) +tabsList.clear();; +KVSO_END_CONSTRUCTOR(KvsObject_tabWidget) + +bool KvsObject_tabWidget::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT(QTabWidget) + connect(widget(),SIGNAL(currentChanged(int)),this,SLOT(slotCurrentChanged(int))); + connect(widget(),SIGNAL(tabCloseRequested(int)),this,SLOT(slotTabCloseRequest(int))); + + return true; +} +KVSO_CLASS_FUNCTION(tabWidget,setTabsClosable) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bClosable; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bool_flag",KVS_PT_BOOLEAN,0,bClosable) + KVSO_PARAMETERS_END(c) + ((QTabWidget *)widget())->setTabsClosable(bClosable); + return true; +} + +KVSO_CLASS_FUNCTION(tabWidget,addTab) +{ + CHECK_INTERNAL_POINTER(widget()) + KviKvsObject *pObject; + 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) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + CHECK_HOBJECT_IS_WIDGET(pObject) + QPixmap * pix = g_pIconManager->getImage(szIcon); + if(pix){ + ((QTabWidget *)widget())->addTab(((QWidget *)(pObject->object())),QIcon(*pix),szLabel); + } + else((QTabWidget *)widget())->addTab(((QWidget *)(pObject->object())),szLabel); + tabsList.append(hObject); + return true; +} +KVSO_CLASS_FUNCTION(tabWidget,widgetAt) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_INTEGER,0,iIndex) + KVSO_PARAMETERS_END(c) + if (iIndex>=tabsList.count()||iIndex<0) c->returnValue()->setHObject((kvs_hobject_t)0); + else c->returnValue()->setHObject(tabsList.at(iIndex)); + return true; +} + +KVSO_CLASS_FUNCTION(tabWidget,insertTab) +{ + CHECK_INTERNAL_POINTER(widget()) + KviKvsObject *pObject; + 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) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + CHECK_HOBJECT_IS_WIDGET(pObject) + QPixmap * pix = g_pIconManager->getImage(szIcon); + if(pix){ + ((QTabWidget *)widget())->insertTab(uIndex,(QWidget *)(pObject->object()),QIcon(*pix),szLabel); + } + else ((QTabWidget *)widget())->insertTab(uIndex,((QWidget *)(pObject->object())),szLabel); + tabsList.insert(uIndex,hObject); + return true; +} + +KVSO_CLASS_FUNCTION(tabWidget,setCurrentPage) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t iIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,iIndex) + KVSO_PARAMETERS_END(c) + ((QTabWidget *)widget())->setCurrentIndex(iIndex); + return true; +} +KVSO_CLASS_FUNCTION(tabWidget,setTabToolTip) +{ + CHECK_INTERNAL_POINTER(widget()) + KviKvsObject *pObject; + 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) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + CHECK_HOBJECT_IS_WIDGET(pObject) + int iIdx = ((QTabWidget *)widget())->indexOf (((QWidget *)(pObject->object()))); + if (iIdx == -1) + { + c->warning(__tr2qs_ctx("Can't find the tab ","objects")); + return true; + } + ((QTabWidget *)widget())->setTabToolTip(iIdx,szTooltip); + return true; +} +KVSO_CLASS_FUNCTION(tabWidget,removeTabToolTip) +{ + CHECK_INTERNAL_POINTER(widget()) + KviKvsObject *pObject; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("tab_widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + CHECK_HOBJECT_IS_WIDGET(pObject) + int iIdx = ((QTabWidget *)widget())->indexOf (((QWidget *)(pObject->object()))) ; + if (iIdx==-1) + { + c->warning(__tr2qs_ctx("Can't find the tab ","objects")); + return true; + } + ((QTabWidget *)widget())->setTabToolTip(iIdx,QString()); + return true; +} + +KVSO_CLASS_FUNCTION(tabWidget,setTabLabel) +{ + CHECK_INTERNAL_POINTER(widget()) + KviKvsObject *pObject; + 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) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + CHECK_HOBJECT_IS_WIDGET(pObject) + int iIdx = ((QTabWidget *)widget())->indexOf (((QWidget *)(pObject->object()))); + if (iIdx == -1) + { + c->warning(__tr2qs_ctx("Can't find the tab ","objects")); + return true; + } + ((QTabWidget *)widget())->setTabText(iIdx,szLabel); + return true; +} +KVSO_CLASS_FUNCTION(tabWidget,currentPageIndex) +{ + CHECK_INTERNAL_POINTER(widget()) + int index=((QTabWidget *)widget())->currentIndex(); + c->returnValue()->setInteger(index); + return true; +} +KVSO_CLASS_FUNCTION(tabWidget,tabLabel) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t uIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_INT,0,uIndex) + KVSO_PARAMETERS_END(c) + QString label=((QTabWidget *)widget())->tabText(uIndex); + c->returnValue()->setString(label); + return true; +} + + +KVSO_CLASS_FUNCTION(tabWidget,count) +{ + CHECK_INTERNAL_POINTER(widget()) + int count = ((QTabWidget *)widget())->count(); + c->returnValue()->setInteger(count); + return true; +} + +KVSO_CLASS_FUNCTION(tabWidget,currentTabLabel) +{ + CHECK_INTERNAL_POINTER(widget()) + int i= ((QTabWidget *)widget())->currentIndex(); + QString label=((QTabWidget *)widget())->tabText(i); + c->returnValue()->setString(label); + return true; +} +KVSO_CLASS_FUNCTION(tabWidget,removePage) +{ + CHECK_INTERNAL_POINTER(widget()) + KviKvsObject *pObject; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("tab_widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + CHECK_HOBJECT_IS_WIDGET(pObject) + int iIdx = ((QTabWidget *)widget())->indexOf (((QWidget *)(pObject->object()))); + if (iIdx == -1) + { + c->warning(__tr2qs_ctx("Can't find the tab ","objects")); + return true; + } + ((QTabWidget *)widget())->removeTab(iIdx); + tabsList.removeAt(iIdx); + return true; +} + +KVSO_CLASS_FUNCTION(tabWidget,changeTab) +{ + CHECK_INTERNAL_POINTER(widget()) + KviKvsObject *pObject; + 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) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + CHECK_HOBJECT_IS_WIDGET(pObject) + int iIdx = ((QTabWidget *)widget())->indexOf (((QWidget *)(pObject->object()))); + if (iIdx == -1) + { + c->warning(__tr2qs_ctx("Can't find the tab","objects")); + return true; + } + QPixmap * pix = g_pIconManager->getImage(szIcon); + if(pix)((QTabWidget *)widget())->setTabIcon(iIdx,QIcon(*pix)); + ((QTabWidget *)widget())->setTabText(iIdx,szLabel); + return true; +} + +KVSO_CLASS_FUNCTION(tabWidget,setTabPosition) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szPos; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("tab_position",KVS_PT_STRING,0,szPos) + KVSO_PARAMETERS_END(c) + if(KviQString::equalCI(szPos,"Top")) + ((QTabWidget *)widget())->setTabPosition(QTabWidget::North); + else if(KviQString::equalCI(szPos,"Bottom")) + ((QTabWidget *)widget())->setTabPosition(QTabWidget::South); + else c->warning( __tr2qs_ctx("Unknown position '%Q'","objects"),&szPos); + return true; +} + +KVSO_CLASS_FUNCTION(tabWidget,currentChangedEvent) +{ + + emitSignal("currentChanged",c,c->params()); + return true; +} + +void KvsObject_tabWidget::slotCurrentChanged(int value) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)value)); + callFunction(this,"currentChangedEvent",¶ms); +} + +KVSO_CLASS_FUNCTION(tabWidget,tabCloseRequestEvent) +{ + + emitSignal("tabCloseRequested",c,c->params()); + return true; +} + +void KvsObject_tabWidget::slotTabCloseRequest(int iIndex) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)iIndex)); + callFunction(this,"tabCloseRequestEvent",¶ms); +} +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_tabWidget.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES + diff --git a/src/modules/objects/KvsObject_tabWidget.h b/src/modules/objects/KvsObject_tabWidget.h new file mode 100644 index 000000000..72f893758 --- /dev/null +++ b/src/modules/objects/KvsObject_tabWidget.h @@ -0,0 +1,67 @@ +#ifndef _CLASS_TABWIDGET_H_ +#define _CLASS_TABWIDGET_H_ +//============================================================================= +// +// File : KvsObject_tabWidget.cpp +// 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_widget.h" +#include "object_macros.h" + +class KvsObject_tabWidget : public KvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_tabWidget) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + QList tabsList; + + bool addTab(KviKvsObjectFunctionCall *c); + bool insertTab(KviKvsObjectFunctionCall *c); + bool setTabToolTip(KviKvsObjectFunctionCall *c); + bool removeTabToolTip(KviKvsObjectFunctionCall *c); + bool setTabLabel(KviKvsObjectFunctionCall *c); + bool setCurrentPage(KviKvsObjectFunctionCall *c); + bool currentPageIndex(KviKvsObjectFunctionCall *c); + bool tabLabel(KviKvsObjectFunctionCall *c); + bool currentTabLabel(KviKvsObjectFunctionCall *c); + bool count(KviKvsObjectFunctionCall *c); + bool changeTab(KviKvsObjectFunctionCall *c); + bool removePage(KviKvsObjectFunctionCall *c); + bool setTabPosition(KviKvsObjectFunctionCall *c); + bool setTabsClosable(KviKvsObjectFunctionCall *c); + bool widgetAt(KviKvsObjectFunctionCall *c); + + // events + bool currentChangedEvent(KviKvsObjectFunctionCall *c); + bool tabCloseRequestEvent(KviKvsObjectFunctionCall *c); + +protected slots: + void slotCurrentChanged(int); + void slotTabCloseRequest(int); +}; + +#endif //!_CLASS_TABWIDGET_H_ diff --git a/src/modules/objects/KvsObject_tableWidget.cpp b/src/modules/objects/KvsObject_tableWidget.cpp new file mode 100644 index 000000000..6bda1f64a --- /dev/null +++ b/src/modules/objects/KvsObject_tableWidget.cpp @@ -0,0 +1,796 @@ +//============================================================================= +// +// File : KvsObject_tableWidget.cpp +// Creation date : Wed 04 Feb 2009 09:30:05 CEST by Carbone Alessandro +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "KvsObject_tableWidget.h" +#include "KvsObject_painter.h" +#include "KvsObject_pixmap.h" + +#include "kvi_debug.h" +#include "KviApplication.h" +#include "KviLocale.h" +#include "KviError.h" +#include "KviIconManager.h" +#include "KviFile.h" +#include "KviKvsArrayCast.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const int item_flags[] = { + Qt::NoItemFlags, + Qt::ItemIsSelectable, + Qt::ItemIsEditable, + Qt::ItemIsDragEnabled, + Qt::ItemIsDropEnabled, + Qt::ItemIsUserCheckable, + Qt::ItemIsEnabled, + Qt::ItemIsTristate +}; + +const char * const itemflags_tbl[] = { + "noitemflag", + "selectable", + "editable", + "dragEnabled", + "dropEnabled", + "userCheckable", + "enabled", + "tristate" +}; + +#define itemflags_num (sizeof(itemflags_tbl) / sizeof(itemflags_tbl[0])) + +/* + @doc:tablewidget + @title: + tablewidget class + @type: + class + @short: + Tablewidget widget. + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + This widget provides a table. + @functions: + !fn: $setText(,,[]) + Sets the contents of the cell pointeid by row and col to text. + !fn: $setTooltip(,,[]) + Sets the tooltip of the cell pointeid by row and col to text. + !fn: $setNumber(,,[]). + Sets the contents of the cell pointeid by row and col to number. + !fn: $text(,) + Returns the text of the cell pointed by row and col. + !fn: $setHorizontalHeaderLabels() + Sets the horizontal header labels using labels. + !fn: $showHorizontalHeader() + Shows the horizontal header. + !fn: $hideHorizontalHeader() + Hides the horizontal header. + !fn: $setVerticalHeaderLabels() + Sets the vertical header labels using labels. + !fn: $showVerticalHeader() + Shows the vertical header. + !fn: $hideVerticalHeader() + Hides the vertical header. + !fn: $setRowCount() + Sets the number of rows in the table. + !fn: $rowCount() + Returns the number of rows in the table. + !fn: $currentRow() + Returns the current row. + Useful in the [classfnc]customContextMenuRequestedEvent[/classfnc]. + !fn: $insertRow() + Insert an empty row at . + !fn: $removeRow() + Remove the row at and all its items from the table. + !fn: $insertColumn() + Insert an empty column at . + !fn: $removeColumn() + Remove the column at and all its items from the table. + !fn: $setColumnCount() + Sets the number of columns in the table. + !fn: $columnCount() + Returns the number of columns in the table. + !fn: $currentRow() + Returns the current column. + Useful in the [classfnc]customContextMenuRequestedEvent[/classfnc] + !fn: $setFlag(,,, , ...) + Sets the flags for the cell pointed by row and col to the given flags. + These determine whether the cell can be selected or modified. + Supported flags are: + - noitemflag : no flag sets; + - selectable : cell is selecatble; + - editable : cell is editable; + - dragEnabled : cell can dragged; + - dropEnabled : cell can used as drop target; + - userCheckable : cell is checkable; + - enabled :cell is enabled; + - tristate : cell is checkable with three separate states. + !fn: $setCellWidget(,,) + Sets the given widget to be displayed in the cell in the given row and column, passing the ownership of the widget to the table. + !fn: $setIcon(,,) + Sets the cell icon pointed by ,. + Icon parameter can be a standard KVIrc [doc:image_id]image identifier[/doc] icon or a KVS pixmap's object. + !fn: $hideRow() + Hides the row . + !fn: $showRow() + Shows the row . + !fn: $hideColumn() + Hides the column . + !fn: $showColumn() + Shows the column . + !fn: $clear() + Clears the table. + !fn: $itemEnteredEvent() + This event is triggered when the mouse cursor enters an cell. + !fn: $cellActivatedEvent() + This event is triggered when the cell specified by row and column has been activated + !fn: $cellDoubleClickedEvent() + This event is triggered whenever a cell in the table is double clicked. + !fn: $paintCellEvent(,,,,) + This event handler can be reimplemented to repaint cells. + The framework will pass the row/col coordinates, cell's width and height, and, as parameter, a [class]painter[/class]object. + You don't need to begin/end/delete the painter. + !fn: $sizeHintCellRequestEvent() + This event handler can be reimplemented to pass a custom size hint for this cell to the table layout + !fn; $resizeRowsToContents() + This function will try to redistribute the available space according to the space requirement of each row + !fn; $resizeColumnsToContents() + This function will try to redistribute the available space according to the space requirement of each column + @signals: + !sg: $clicked() + This signal is emitted by the default implementation of [classfnc]$clickEvent[/classfnc](). + +*/ + + +KVSO_BEGIN_REGISTERCLASS(KvsObject_tableWidget,"tablewidget","widget") + + // Horizontal Header + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,setHorizontalHeaderLabels) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,hideHorizontalHeader) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,hideVerticalHeader) + + // Vertical Header + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,setVerticalHeaderLabels) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,showHorizontalHeader) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,showVerticalHeader) + + // Rows-Columns + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,setRowCount) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,insertRow) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,insertColumn) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,removeRow) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,removeColumn) + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,rowCount) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,currentRow) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,setColumnCount) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,columnCount) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,currentColumn) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,itemRowColAt) + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,hideRow) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,showRow) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,hideColumn) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,showColumn) + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,resizeRowsToContents) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,resizeColumnsToContents) + + // Item (text. icon, widget) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,setText) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,setNumber) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,setToolTip) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,text) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,setCellWidget) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,setIcon) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,clear) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_tableWidget,setItemFlags); + + KVSO_REGISTER_HANDLER(KvsObject_tableWidget,"itemEnteredEvent",itemEnteredEvent); + KVSO_REGISTER_HANDLER(KvsObject_tableWidget,"cellActivatedEvent",cellActivatedEvent); + KVSO_REGISTER_HANDLER(KvsObject_tableWidget,"cellDoubleClickedEvent",cellDoubleClickedEvent); + KVSO_REGISTER_STANDARD_TRUERETURN_HANDLER(KvsObject_tableWidget,"paintCellEvent") + KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KvsObject_tableWidget,"sizeHintCellRequestEvent") + + + +KVSO_END_REGISTERCLASS(KvsObject_tableWidget) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_tableWidget,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_tableWidget) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_tableWidget) +/*if (m_pCellItemDelegate) +{ + delete m_pCellItemDelegate; + m_pCellItemDelegate=0; +}*/ +KVSO_END_DESTRUCTOR(KvsObject_tableWidget) + +bool KvsObject_tableWidget::init(KviKvsRunTimeContext *c,KviKvsVariantList *) +{ + + SET_OBJECT(QTableWidget) + m_pCellItemDelegate=new KviCellItemDelegate(((QTableWidget *)widget()),this); + + m_pContext=c; + ((QTableWidget *)widget())->setItemDelegate(m_pCellItemDelegate); + ((QTableWidget *)widget())->verticalHeader()->resizeSections(QHeaderView::Custom ); + ((QTableWidget *)widget())->horizontalHeader()->resizeSections(QHeaderView::Custom ); + + connect(widget(),SIGNAL(itemEntered(QTableWidgetItem *)),this,SLOT(slotItemEntered(QTableWidgetItem *))); + connect(widget(),SIGNAL(cellActivated(int,int)),this,SLOT(cellActivated(int,int))); + connect(widget(),SIGNAL(cellDoubleClicked(int,int)),this,SLOT(cellDoubleClicked(int,int))); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,clear) +{ + CHECK_INTERNAL_POINTER(widget()) + ((QTableWidget *)widget())->clear(); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,resizeRowsToContents) +{ + CHECK_INTERNAL_POINTER(widget()) + //qDebug("resize row to contents"); + + ((QTableWidget *)widget())->resizeRowsToContents(); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,resizeColumnsToContents) +{ + CHECK_INTERNAL_POINTER(widget()) + //qDebug("resize coluns to contents"); + ((QTableWidget *)widget())->resizeColumnsToContents(); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,setText) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uCol,uRow; + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow) + KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if(uRow >= (uint)((QTableWidget *)widget())->rowCount() || uRow >= (uint)((QTableWidget *)widget())->rowCount()) + c->warning(__tr2qs_ctx("Item out of the tablewidget size","objects")); + QTableWidgetItem * pItem = ((QTableWidget *)widget())->item(uRow,uCol); + if(!pItem) + { + pItem = new QTableWidgetItem(); + ((QTableWidget *)widget())->setItem(uRow,uCol,pItem); + } + pItem->setText(szText); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,setNumber) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uCol,uRow; + kvs_int_t iNumber; + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow) + KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("number",KVS_PT_INT,0,iNumber) + KVSO_PARAMETERS_END(c) + if(uRow >= (uint)((QTableWidget *)widget())->rowCount() || uRow >= (uint)((QTableWidget *)widget())->rowCount()) + c->warning(__tr2qs_ctx("Item out of the tablewidget size","objects")); + QTableWidgetItem * pItem = ((QTableWidget *)widget())->item(uRow,uCol); + if(!pItem) + { + pItem = new QTableWidgetItem(); + ((QTableWidget *)widget())->setItem(uRow,uCol,pItem); + } + pItem->setData(0,(int)iNumber); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,insertRow) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uRow; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow) + KVSO_PARAMETERS_END(c) + ((QTableWidget *)widget())->insertRow(uRow); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,insertColumn) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETERS_END(c) + ((QTableWidget *)widget())->insertColumn(uCol); + return true; +} +KVSO_CLASS_FUNCTION(tableWidget,removeRow) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uRow; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow) + KVSO_PARAMETERS_END(c) + ((QTableWidget *)widget())->removeRow(uRow); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,removeColumn) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETERS_END(c) + ((QTableWidget *)widget())->removeColumn(uCol); + return true; +} + + +KVSO_CLASS_FUNCTION(tableWidget,setIcon) +{ + kvs_uint_t uCol,uRow; + KviKvsObject *obPixmap; + kvs_hobject_t obHpixmap; + KviKvsVariant * vPixmap; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow) + KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("icon",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->inheritsClass("pixmap")) + { + c->warning(__tr2qs_ctx("Pixmap object or image Id required","objects")); + return true; + } + pix=((KvsObject_pixmap *)obPixmap)->getPixmap(); + } else { + QString szPix; + vPixmap->asString(szPix); + pix=g_pIconManager->getImage(szPix); + if(!pix) + { + c->warning(__tr2qs_ctx("Error occured: the suitable file '%Q' is not of the correct format or it is not a valid icon number.","objects"),&szPix); + return true; + } + } + QTableWidgetItem * pItem = ((QTableWidget *)widget())->item(uRow,uCol); + if(!pItem) + { + pItem = new QTableWidgetItem(); + ((QTableWidget *)widget())->setItem(uRow,uCol,pItem); + } + pItem->setIcon(QIcon(*pix)); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,text) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uCol,uRow; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow) + KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETERS_END(c) + QTableWidgetItem * pItem = ((QTableWidget *)widget())->item(uRow,uCol); + if(!pItem) c->returnValue()->setNothing(); + else c->returnValue()->setString(((QTableWidget *)widget())->item(uRow,uCol)->text()); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,setRowCount) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uRow; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow) + KVSO_PARAMETERS_END(c) + ((QTableWidget *)widget())->setRowCount(uRow); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,rowCount) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QTableWidget *)widget())->rowCount()); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,currentRow) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QTableWidget *)widget())->currentRow()); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,currentColumn) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QTableWidget *)widget())->currentColumn()); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,columnCount) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setInteger(((QTableWidget *)widget())->columnCount()); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,itemRowColAt) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iXpos,iYpos; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x_pos",KVS_PT_INT,0,iXpos) + KVSO_PARAMETER("y_pos",KVS_PT_INT,0,iYpos) + KVSO_PARAMETERS_END(c) + KviKvsArray *pArray; + QPoint pPoint=((QTableWidget *)widget())->viewport()->mapFromGlobal(QPoint(iXpos,iYpos)); + QTableWidgetItem *pItem=((QTableWidget *)widget())->itemAt(pPoint.x(),pPoint.y()); + pArray=new KviKvsArray; + if (!pItem) { + pArray->set(0,new KviKvsVariant((kvs_int_t)-1)); + pArray->set(1,new KviKvsVariant((kvs_int_t)-1)); + } + else { + pArray->set(0,new KviKvsVariant((kvs_int_t)pItem->row())); + pArray->set(1,new KviKvsVariant((kvs_int_t)pItem->column())); + } + c->returnValue()->setArray(pArray); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,setToolTip) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szTooltip; + kvs_uint_t uRow,uCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow) + KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("tooltip",KVS_PT_STRING,0,szTooltip) + KVSO_PARAMETERS_END(c) + QTableWidgetItem *pItem=((QTableWidget *)widget())->item(uRow,uCol); + if (pItem) pItem->setToolTip(szTooltip); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,setColumnCount) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETERS_END(c) + ((QTableWidget *)widget())->setColumnCount(uCol); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,hideColumn) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETERS_END(c) + ((QTableWidget *)widget())->hideColumn(uCol); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,showColumn) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETERS_END(c) + ((QTableWidget *)widget())->showColumn(uCol); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,hideRow) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uRow; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,uRow) + KVSO_PARAMETERS_END(c) + ((QTableWidget *)widget())->hideRow(uRow); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,showRow) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_uint_t uRow; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("col",KVS_PT_UNSIGNEDINTEGER,0,uRow) + KVSO_PARAMETERS_END(c) + ((QTableWidget *)widget())->showRow(uRow); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,setHorizontalHeaderLabels) +{ + CHECK_INTERNAL_POINTER(widget()) + KviKvsArrayCast ac; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("labels",KVS_PT_ARRAYCAST,0,ac) + KVSO_PARAMETERS_END(c) + QStringList szColumns; + if(KviKvsArray * a = ac.array()) + { + kvs_int_t uIdx = 0; + kvs_int_t uSize = a->size(); + while(uIdx < uSize) + { + KviKvsVariant * v = a->at(uIdx); + if(v) + { + QString tmp; + v->asString(tmp); + szColumns.append(tmp); + } + else szColumns.append(""); + uIdx++; + } + } + ((QTableWidget *)object())->setHorizontalHeaderLabels(szColumns); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,setVerticalHeaderLabels) +{ + CHECK_INTERNAL_POINTER(widget()) + KviKvsArrayCast ac; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("labels",KVS_PT_ARRAYCAST,0,ac) + KVSO_PARAMETERS_END(c) + QStringList szColumns; + if(KviKvsArray * a = ac.array()) + { + kvs_int_t uIdx = 0; + kvs_int_t uSize = a->size(); + while(uIdx < uSize) + { + KviKvsVariant * v = a->at(uIdx); + if(v) + { + QString tmp; + v->asString(tmp); + szColumns.append(tmp); + } + else szColumns.append(""); + uIdx++; + } + } + ((QTableWidget *)object())->setVerticalHeaderLabels(szColumns); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,setCellWidget) +{ + CHECK_INTERNAL_POINTER(widget()) + KviKvsObject * pObject; + kvs_hobject_t hObject; + kvs_uint_t uRow,uCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,uRow) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + CHECK_HOBJECT_IS_WIDGET(pObject) + ((QTableWidget *)object())->setCellWidget(uRow,uCol,((QWidget *)(pObject->object()))); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,hideHorizontalHeader) +{ + Q_UNUSED(c); + ((QTableWidget *)widget())->horizontalHeader()->hide(); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,hideVerticalHeader) +{ + Q_UNUSED(c); + ((QTableWidget *)widget())->verticalHeader()->hide(); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,showHorizontalHeader) +{ + Q_UNUSED(c); + ((QTableWidget *)widget())->horizontalHeader()->show(); + return true; +} + +KVSO_CLASS_FUNCTION(tableWidget,showVerticalHeader) +{ + Q_UNUSED(c); + ((QTableWidget *)widget())->verticalHeader()->show(); + return true; +} +KVSO_CLASS_FUNCTION(tableWidget,setItemFlags) +{ + CHECK_INTERNAL_POINTER(widget()) + + QStringList itemflags; + kvs_uint_t iRow,iCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("row",KVS_PT_UNSIGNEDINTEGER,0,iRow) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,iCol) + KVSO_PARAMETER("flags",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,itemflags) + KVSO_PARAMETERS_END(c) + int flag,sum=0; + for ( int i=0;isetCheckState(0,Qt::Unchecked); + sum = sum | flag; + } else { + c->warning(__tr2qs_ctx("Unknown item flag '%Q'","objects"),&itemflags.at(i)); + } + } + QTableWidgetItem *pItem=((QTableWidget *)widget())->item(iRow,iCol); + if(pItem) pItem->setFlags((Qt::ItemFlags)sum); + return true; +} + +void KvsObject_tableWidget::slotItemEntered(QTableWidgetItem * i) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)i->row()),new KviKvsVariant((kvs_int_t)i->column())); + callFunction(this,"itemEnteredEvent",0,¶ms); +} + +KVSO_CLASS_FUNCTION(tableWidget,itemEnteredEvent) +{ + emitSignal("itemEntered",c,c->params()); + return true; +} + +void KvsObject_tableWidget::cellActivated(int iRow,int iCol) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)iRow),new KviKvsVariant((kvs_int_t)iCol)); + callFunction(this,"cellActivatedEvent",0,¶ms); +} + +KVSO_CLASS_FUNCTION(tableWidget,cellActivatedEvent) +{ + emitSignal("cellActivated",c,c->params()); + return true; +} + +void KvsObject_tableWidget::cellDoubleClicked(int iRow,int iCol) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)iRow),new KviKvsVariant((kvs_int_t)iCol)); + callFunction(this,"cellDoubleClickedEvent",0,¶ms); +} + +KVSO_CLASS_FUNCTION(tableWidget,cellDoubleClickedEvent) +{ + emitSignal("cellDoubleClicked",c,c->params()); + return true; +} +bool KvsObject_tableWidget::paint(QPainter * p, const QStyleOptionViewItem & option, const QModelIndex & index) +{ + p->save(); + KviKvsObjectClass * pClass = KviKvsKernel::instance()->objectController()->lookupClass("painter"); + KviKvsVariantList params; + KviKvsObject * pObject = pClass->allocateInstance(0,"internalpainter",m_pContext,¶ms); + ((KvsObject_painter *)pObject)->setInternalPainter(p); + p->setClipRect(option.rect); + p->translate(option.rect.x(),option.rect.y()); + int col=index.column(); + int row=index.row(); + kvs_hobject_t handle=pObject->handle(); + kvs_int_t cell_height=(kvs_int_t)option.rect.height(); + kvs_int_t cell_width=(kvs_int_t)option.rect.width(); + KviKvsVariantList parameters(new KviKvsVariant(handle),new KviKvsVariant((kvs_int_t) row),new KviKvsVariant((kvs_int_t) col),new KviKvsVariant(cell_width),new KviKvsVariant(cell_height)); + bool ret=false; + KviKvsVariant *retv=new KviKvsVariant(ret); + callFunction(this,"paintCellEvent",retv,¶meters); + pObject=KviKvsKernel::instance()->objectController()->lookupObject(handle); + if (pObject) pObject->dieNow(); + p->restore(); + return retv->asBoolean(); +} + +KviCellItemDelegate::KviCellItemDelegate(QAbstractItemView * pWidget,KvsObject_tableWidget * parent) +: QItemDelegate(pWidget), m_pParentScript(parent) +{ +} + +KviCellItemDelegate::~KviCellItemDelegate() +{ +} + +void KviCellItemDelegate::paint(QPainter * pPainter, const QStyleOptionViewItem & option, const QModelIndex & index) const +{ + if (m_pParentScript->paint(pPainter,option,index)) + QItemDelegate::paint(pPainter,option,index); +} + +QSize KviCellItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex & index) const +{ + KviKvsVariant *sizeret=new KviKvsVariant(); + //qDebug("sizehint cell"); + KviKvsVariantList parameters(new KviKvsVariant((kvs_int_t) index.row()),new KviKvsVariant((kvs_int_t) index.column())); + m_pParentScript->callFunction(m_pParentScript,"sizeHintCellRequestEvent",sizeret,¶meters); + if (sizeret->isArray()) + { + if (sizeret->array()->size()==2) + { + kvs_int_t w,h; + if (sizeret->array()->at(0)->asInteger(w) && sizeret->array()->at(1)->asInteger(h))return QSize(w,h); + } + } + return QItemDelegate::sizeHint(option,index); +} + + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_tableWidget.moc" +#endif //COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/KvsObject_tableWidget.h b/src/modules/objects/KvsObject_tableWidget.h new file mode 100644 index 000000000..a0c5df848 --- /dev/null +++ b/src/modules/objects/KvsObject_tableWidget.h @@ -0,0 +1,116 @@ +#ifndef _CLASS_TABLEWIDGET_H_ +#define _CLASS_TABLEWIDGET_H_ +//============================================================================= +// +// File : KvsObject_tableWidget.h +// Creation date : Wed 4 Feb 2009 09:30:05 CEST by Carbone Alessandro +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2000 Krzysztof Godlewski +// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "KvsObject_widget.h" +#include "object_macros.h" + +#include "KviKvsRunTimeContext.h" + +#include +#include +#include +#include + +class KvsObject_tableWidget; + +class KviCellItemDelegate : public QItemDelegate +{ +public: + KviCellItemDelegate(QAbstractItemView * pWidget = 0,KvsObject_tableWidget *pParent=0); + ~KviCellItemDelegate(); +protected: +// QAbstractItemView * m_pParent; + KvsObject_tableWidget *m_pParentScript; +public: + QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const; + void paint(QPainter * pPainter, const QStyleOptionViewItem & option, const QModelIndex & index) const; +}; + +class KvsObject_tableWidget : public KvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_tableWidget) +public: + QWidget * widget() { return (QWidget *)object(); }; + bool paint(QPainter * pPainter, const QStyleOptionViewItem & option, const QModelIndex & index); + +protected: + QSqlQueryModel * model; + KviKvsRunTimeContext * m_pContext; + KviCellItemDelegate * m_pCellItemDelegate; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool setText(KviKvsObjectFunctionCall *c); + bool setNumber(KviKvsObjectFunctionCall *c); + bool setToolTip(KviKvsObjectFunctionCall *c); + bool text(KviKvsObjectFunctionCall *c); + bool setIcon(KviKvsObjectFunctionCall *c); + bool setItemFlags(KviKvsObjectFunctionCall *c); + + bool setColumnCount(KviKvsObjectFunctionCall *c); + bool columnCount(KviKvsObjectFunctionCall *c); + bool setRowCount(KviKvsObjectFunctionCall *c); + bool currentRow(KviKvsObjectFunctionCall *c); + bool currentColumn(KviKvsObjectFunctionCall *c); + bool itemRowColAt(KviKvsObjectFunctionCall *c); + + bool rowCount(KviKvsObjectFunctionCall *c); + + bool insertRow(KviKvsObjectFunctionCall *c); + bool insertColumn(KviKvsObjectFunctionCall *c); + bool removeRow(KviKvsObjectFunctionCall *c); + bool removeColumn(KviKvsObjectFunctionCall *c); + + + bool setHorizontalHeaderLabels(KviKvsObjectFunctionCall *c); + bool setVerticalHeaderLabels(KviKvsObjectFunctionCall *c); + bool setCellWidget(KviKvsObjectFunctionCall *c); + + bool hideHorizontalHeader(KviKvsObjectFunctionCall *c); + bool showHorizontalHeader(KviKvsObjectFunctionCall *c); + bool hideVerticalHeader(KviKvsObjectFunctionCall *c); + bool showVerticalHeader(KviKvsObjectFunctionCall *c); + bool clear(KviKvsObjectFunctionCall *c); + bool itemEnteredEvent(KviKvsObjectFunctionCall *c); + bool cellActivatedEvent(KviKvsObjectFunctionCall *c); + bool cellDoubleClickedEvent(KviKvsObjectFunctionCall *c); + + bool hideColumn(KviKvsObjectFunctionCall *c); + bool showColumn(KviKvsObjectFunctionCall *c); + bool hideRow(KviKvsObjectFunctionCall *c); + bool showRow(KviKvsObjectFunctionCall *c); + bool resizeRowsToContents(KviKvsObjectFunctionCall *c); + bool resizeColumnsToContents(KviKvsObjectFunctionCall *c); +protected slots: + void slotItemEntered(QTableWidgetItem *); + void cellActivated(int iRow,int iCol); + void cellDoubleClicked(int iRow,int iCol); +}; + +#endif // !_CLASS_TABLEWIDGET_H_ diff --git a/src/modules/objects/KvsObject_textBrowser.cpp b/src/modules/objects/KvsObject_textBrowser.cpp new file mode 100644 index 000000000..44fb40973 --- /dev/null +++ b/src/modules/objects/KvsObject_textBrowser.cpp @@ -0,0 +1,155 @@ +//============================================================================= +// +// File : KvsObject_textBrowser.cpp +// 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_textBrowser.h" +#include "KviError.h" +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KviIconManager.h" + +#include +#include +#include +/* + @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(KvsObject_textBrowser,"textBrowser","multilineedit") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_textBrowser,setSource) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_textBrowser,forward) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_textBrowser,backward) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_textBrowser,home) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_textBrowser,reload) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_textBrowser,linkClickedEvent) +KVSO_END_REGISTERCLASS(KvsObject_textBrowser) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_textBrowser,KvsObject_textedit) + +KVSO_END_CONSTRUCTOR(KvsObject_textBrowser) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_textBrowser) + +KVSO_END_CONSTRUCTOR(KvsObject_textBrowser) + +bool KvsObject_textBrowser::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT(QTextBrowser); + connect(obj,SIGNAL(anchorClicked(const QUrl &)),this,SLOT(anchorClicked(const QUrl &))); + return true; +} + +KVSO_CLASS_FUNCTION(textBrowser,setSource) +{ + CHECK_INTERNAL_POINTER(widget()) + 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_ctx("I can't find the specified file '%Q'.","objects"),&szFile); + return true; + } + QUrl url; + url.setPath(szFile); + ((QTextBrowser *)widget())->setSource(url); + return true; +} + +KVSO_CLASS_FUNCTION(textBrowser,forward) +{ + CHECK_INTERNAL_POINTER(widget()) + ((QTextBrowser *)widget())->forward(); + return true; +} + +KVSO_CLASS_FUNCTION(textBrowser,backward) +{ + CHECK_INTERNAL_POINTER(widget()) + ((QTextBrowser *)widget())->backward(); + return true; +} + +KVSO_CLASS_FUNCTION(textBrowser,home) +{ + CHECK_INTERNAL_POINTER(widget()) + ((QTextBrowser *)widget())->home(); + return true; +} + +KVSO_CLASS_FUNCTION(textBrowser,reload) +{ + CHECK_INTERNAL_POINTER(widget()) + ((QTextBrowser *)widget())->reload(); + return true; +} + +void KvsObject_textBrowser::anchorClicked(const QUrl &url) +{ + KviKvsVariantList parms(new KviKvsVariant(url.path())); + callFunction(this,"linkClickedEvent",0,&parms); +} + +KVSO_CLASS_FUNCTION(textBrowser,linkClickedEvent) +{ + emitSignal("linkClicked",c,c->params()); + return true; +} + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_textBrowser.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES + diff --git a/src/modules/objects/KvsObject_textBrowser.h b/src/modules/objects/KvsObject_textBrowser.h new file mode 100644 index 000000000..50645e6f3 --- /dev/null +++ b/src/modules/objects/KvsObject_textBrowser.h @@ -0,0 +1,53 @@ +#ifndef _CLASS_TBROWSER_H_ +#define _CLASS_TBROWSER_H_ +//============================================================================= +// +// File : KvsObject_textBrowser.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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_widget.h" +#include "KvsObject_multiLineEdit.h" +#include "object_macros.h" +#include + +class KvsObject_textBrowser : public KvsObject_textedit +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_textBrowser) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool setSource(KviKvsObjectFunctionCall *c); + bool forward(KviKvsObjectFunctionCall *c); + bool backward(KviKvsObjectFunctionCall *c); + bool home(KviKvsObjectFunctionCall *c); + bool reload(KviKvsObjectFunctionCall *c); + bool linkClickedEvent(KviKvsObjectFunctionCall *c); +protected slots: + void anchorClicked(const QUrl &); +}; + +#endif //!_CLASS_TBROWSER_H_ diff --git a/src/modules/objects/KvsObject_toolBar.cpp b/src/modules/objects/KvsObject_toolBar.cpp new file mode 100644 index 000000000..4dbacc19b --- /dev/null +++ b/src/modules/objects/KvsObject_toolBar.cpp @@ -0,0 +1,128 @@ +//============================================================================= +// +// File : KvsObject_toolBar.cpp +// 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_toolBar.h" +#include "KviError.h" +#include "kvi_debug.h" +#include "KviTalToolBar.h" +#include "KviTalMainWindow.h" +#include "KviLocale.h" +#include "KviIconManager.h" +#include "KvsObject_mainWindow.h" + +/* + @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: $clear() + Deletes all the toolbar's child widgets. + +*/ + + +KVSO_BEGIN_REGISTERCLASS(KvsObject_toolBar,"toolbar","widget") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolBar,addSeparator) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolBar,setLabel) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolBar,label) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolBar,clear) +KVSO_END_REGISTERCLASS(KvsObject_toolBar) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_toolBar,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_toolBar) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_toolBar) + +KVSO_END_CONSTRUCTOR(KvsObject_toolBar) + +bool KvsObject_toolBar::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *) +{ + if (!parentObject()) + { + pContext->warning(__tr2qs_ctx("The toolbar cannot be a parent-widget!","objects")); + return true; + } + if(parentObject()->inheritsClass("mainwindow")) + { + setObject(new KviTalToolBar(getName(), ((KviTalMainWindow *)parentScriptWidget())), true); + } + else + { + pContext->warning(__tr2qs_ctx("The parent-widget isn't a MainWindow.","objects")); + } + + return true; +} + +KVSO_CLASS_FUNCTION(toolBar,addSeparator) +{ + CHECK_INTERNAL_POINTER(widget()) + ((KviTalToolBar *)widget())->addSeparator(); + return true; +} +KVSO_CLASS_FUNCTION(toolBar,setLabel) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szLabel; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("label",KVS_PT_STRING,0,szLabel) + KVSO_PARAMETERS_END(c) + ((KviTalToolBar *)widget())->setWindowTitle(szLabel); + return true; +} +KVSO_CLASS_FUNCTION(toolBar,label) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setString(((KviTalToolBar *)widget())->windowTitle()); + return true; +} +KVSO_CLASS_FUNCTION(toolBar,clear) +{ + CHECK_INTERNAL_POINTER(widget()) + ((KviTalToolBar *)object())->clear(); + return true; +} + + + diff --git a/src/modules/objects/KvsObject_toolBar.h b/src/modules/objects/KvsObject_toolBar.h new file mode 100644 index 000000000..ad537df43 --- /dev/null +++ b/src/modules/objects/KvsObject_toolBar.h @@ -0,0 +1,48 @@ +#ifndef _CLASS_TOOLBAR_H_ +#define _CLASS_TOOLBAR_H_ +//============================================================================= +// +// File : KvsObject_toolBar.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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_widget.h" +#include "object_macros.h" + +class KvsObject_toolBar : public KvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KvsObject_toolBar) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool addSeparator(KviKvsObjectFunctionCall *c); + bool setLabel(KviKvsObjectFunctionCall *c); + bool label(KviKvsObjectFunctionCall *c); + bool setStretchableWidget(KviKvsObjectFunctionCall *c); + bool clear(KviKvsObjectFunctionCall *c); +}; + + +#endif //!_CLASS_TOOLBAR_H_ diff --git a/src/modules/objects/KvsObject_toolButton.cpp b/src/modules/objects/KvsObject_toolButton.cpp new file mode 100644 index 000000000..884a3e92d --- /dev/null +++ b/src/modules/objects/KvsObject_toolButton.cpp @@ -0,0 +1,344 @@ +//============================================================================= +// +// File : KvsObject_toolButton.cpp +// 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_toolButton.h" +#include "KviError.h" +#include "kvi_debug.h" + +#include "KviLocale.h" +#include "KviIconManager.h" +#include "KviTalPopupMenu.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. + !fn:$setPopup () + Associates the given with this tool button. + !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(KvsObject_toolButton,"toolbutton","widget") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolButton,setImage) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolButton,setUsesBigPixmap) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolButton,usesBigPixmap) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolButton,setUsesTextLabel) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolButton,usesTextLabel) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolButton,setAutoRaise) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolButton,autoRaise) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolButton,setTextLabel) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolButton,textLabel) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolButton,setPopup) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolButton,openPopup) + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolButton,setToggleButton) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolButton,toggle) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolButton,setOn) + + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolButton,setTextPosition) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolButton,textPosition) + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_toolButton,clickEvent) +KVSO_END_REGISTERCLASS(KvsObject_toolButton) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_toolButton,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_toolButton) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_toolButton) + +KVSO_END_CONSTRUCTOR(KvsObject_toolButton) + +bool KvsObject_toolButton::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + SET_OBJECT(QToolButton); + connect(widget(),SIGNAL(clicked()),this,SLOT(slotClicked())); + return true; +} + +KVSO_CLASS_FUNCTION(toolButton,setImage) +{ + CHECK_INTERNAL_POINTER(widget()) + QString icon; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("icon_id",KVS_PT_STRING,0,icon) + KVSO_PARAMETERS_END(c) + QPixmap * pix = g_pIconManager->getImage(icon); + if(pix){ + ((QToolButton *)widget())->setIcon(QIcon(*pix)); + } + else + ((QToolButton *)widget())->setIcon(QIcon()); + return true; +} + +KVSO_CLASS_FUNCTION(toolButton,setUsesBigPixmap) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + ((QToolButton *)widget())->setIconSize(bEnabled ? QSize(32,32) : QSize(22,22)); + return true; +} + +KVSO_CLASS_FUNCTION(toolButton,usesBigPixmap) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setBoolean(((QToolButton *)widget())->iconSize().height() > 22); + return true; +} + +KVSO_CLASS_FUNCTION(toolButton,setUsesTextLabel) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + ((QToolButton *)widget())->setToolButtonStyle(bEnabled?Qt::ToolButtonTextUnderIcon : Qt::ToolButtonIconOnly); + return true; +} + +KVSO_CLASS_FUNCTION(toolButton,usesTextLabel) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setBoolean(((QToolButton *)widget())->toolButtonStyle() != Qt::ToolButtonIconOnly); + return true; +} + +KVSO_CLASS_FUNCTION(toolButton,setAutoRaise) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + ((QToolButton *)widget())->setAutoRaise(bEnabled); + return true; +} + +KVSO_CLASS_FUNCTION(toolButton,autoRaise) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setBoolean(((QToolButton *)widget())->autoRaise()); + return true; +} + +KVSO_CLASS_FUNCTION(toolButton,setOn) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + ((QToolButton *)widget())->setChecked(bEnabled); + return true; +} + +KVSO_CLASS_FUNCTION(toolButton,setToggleButton) +{ + CHECK_INTERNAL_POINTER(widget()) + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + ((QToolButton *)widget())->setCheckable(bEnabled); + return true; +} + +KVSO_CLASS_FUNCTION(toolButton,toggle) +{ + CHECK_INTERNAL_POINTER(widget()) + ((QToolButton *)widget())->toggle(); + return true; +} + +KVSO_CLASS_FUNCTION(toolButton,setTextLabel) +{ + CHECK_INTERNAL_POINTER(widget()) + 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) + ((QToolButton *)widget())->setText(szLabel); + if (!szTip.isEmpty()) ((QToolButton *)widget())->setToolTip(szTip); + return true; +} + +KVSO_CLASS_FUNCTION(toolButton,textLabel) +{ + CHECK_INTERNAL_POINTER(widget()) + c->returnValue()->setString(((QToolButton *)widget())->text()); + return true; +} + +KVSO_CLASS_FUNCTION(toolButton,setPopup) +{ + CHECK_INTERNAL_POINTER(widget()) + 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_ctx("Widget parameter is not an object","objects")); + return true; + } + if (!ob->object()) + { + c->warning(__tr2qs_ctx("Widget parameter is not a valid object","objects")); + return true; + } + if(!ob->inheritsClass("popupmenu")) + { + c->warning(__tr2qs_ctx("Can't add a non-popupmenu object","objects")); + return true; + } + ((QToolButton *)widget())->setMenu(((KviTalPopupMenu *)(ob->object()))); + return true; +} + +KVSO_CLASS_FUNCTION(toolButton,openPopup) +{ + CHECK_INTERNAL_POINTER(widget()) + ((QToolButton *)widget())->showMenu(); + return true; +} +/* +KVSO_CLASS_FUNCTION(toolButton,setPopupDelay) +{ + 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; +} +KVSO_CLASS_FUNCTION(toolButton,popupDelay) +{ + if (widget()) + c->returnValue()->setInteger(((QToolButton *)widget())->popupDelay()); + return true; +} +*/ +KVSO_CLASS_FUNCTION(toolButton,setTextPosition) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szPos; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("position",KVS_PT_STRING,0,szPos) + KVSO_PARAMETERS_END(c) + if(KviQString::equalCI(szPos,"BesideIcon")) + ((QToolButton *)widget())->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + else if(KviQString::equalCI(szPos,"BelowIcon")) + ((QToolButton *)widget())->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + else c->warning(__tr2qs_ctx("Unknown text position '%Q'","objects"),&szPos); + return true; +} + +KVSO_CLASS_FUNCTION(toolButton,textPosition) +{ + CHECK_INTERNAL_POINTER(widget()) + QString szPos="BelowIcon"; + if ((((QToolButton *)widget())->toolButtonStyle())==(Qt::ToolButtonTextBesideIcon)) + szPos="BesideIcon"; + c->returnValue()->setString(szPos); + return true; +} + +KVSO_CLASS_FUNCTION(toolButton,clickEvent) +{ + emitSignal("clicked",c); + return true; +} + +void KvsObject_toolButton::slotClicked() +{ + KviKvsVariantList *params=0; + callFunction(this,"clickEvent",params); +} + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_toolButton.moc" +#endif //COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/KvsObject_toolButton.h b/src/modules/objects/KvsObject_toolButton.h new file mode 100644 index 000000000..041b5612b --- /dev/null +++ b/src/modules/objects/KvsObject_toolButton.h @@ -0,0 +1,70 @@ +#ifndef _CLASS_TOOLBUTTON_H_ +#define _CLASS_TOOLBUTTON_H_ +//============================================================================= +// +// File : KvsObject_toolButton.cpp +// 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_widget.h" +#include "object_macros.h" + +class KvsObject_toolButton : public KvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_toolButton) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool setImage(KviKvsObjectFunctionCall *c); + bool setUsesBigPixmap(KviKvsObjectFunctionCall *c); + bool usesBigPixmap(KviKvsObjectFunctionCall *c); + bool setUsesTextLabel(KviKvsObjectFunctionCall *c); + bool usesTextLabel(KviKvsObjectFunctionCall *c); + bool setTextLabel(KviKvsObjectFunctionCall *c); + bool textLabel(KviKvsObjectFunctionCall *c); + bool setPopup(KviKvsObjectFunctionCall *c); + bool openPopup(KviKvsObjectFunctionCall *c); + bool setOn(KviKvsObjectFunctionCall *c); + bool setToggleButton(KviKvsObjectFunctionCall *c); + bool toggle(KviKvsObjectFunctionCall *c); +// bool setPopupDelay(KviKvsObjectFunctionCall *c); +// bool popupDelay(KviKvsObjectFunctionCall *c); + bool setTextPosition(KviKvsObjectFunctionCall *c); + bool textPosition(KviKvsObjectFunctionCall *c); + + bool setAutoRaise(KviKvsObjectFunctionCall *c); + bool autoRaise(KviKvsObjectFunctionCall *c); + bool clickEvent(KviKvsObjectFunctionCall *c); +signals: + void clicked(); +protected slots: + void slotClicked(); +}; + + +#endif //!_CLASS_TOOLBUTTON_H_ diff --git a/src/modules/objects/KvsObject_trayIcon.cpp b/src/modules/objects/KvsObject_trayIcon.cpp new file mode 100644 index 000000000..67fb17c43 --- /dev/null +++ b/src/modules/objects/KvsObject_trayIcon.cpp @@ -0,0 +1,243 @@ +//============================================================================= +// +// File : KvsObject_trayIcon.cpp +// Creation date : Wed Ago 25 17:28:45 2010 GMT by Carbone Alesssandro +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2009 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KvsObject_trayIcon.h" +#include "KvsObject_popupMenu.h" +#include "KviIconManager.h" +#include "kvi_debug.h" +#include "KviError.h" +#include "KviLocale.h" + +#include + + + + +/* + @doc: trayicon + @keyterms: + trayicon object class + @title: + trayicon class + @type: + class + @short: + An implementation of the the system tray icon. + @inherits: + [class]object[/class] + @description: + This class provides a standard trayicon functionality.[br] + @functions: + !fn: setIcon(). + Sets the tray icon. + See the [doc:image_id]image identifier[/doc] documentation for the explaination of the parameter. + !fn: setTooltip(). + Sets the tray icon tooltip. + !fn: show() + Shows the tray icon. + !fn: hide() + Hides the tray icon. + !fn: isVisible() + Returns '1' if the tray icon is currently visible. + !fn: showMessage(,,,) + Shows a balloon message for the entry with the given title, message and message_icon for the time specified in millisecondsTimeoutHint. title and message must be plain text strings. + Message can be clicked by the user; the messageClickedEvent() will be triggered when this occurs. + Valid values for message_icon are: + - NoIcon : No icon is shown. + - Information : An information icon is shown. + - Warning : A standard warning icon is shown. + - Critical : A critical warning icon is shown. + !fn: setContextMenu(). + Associates the given with the tray icon. + !fn: activatedEvent() + This event is triggered when the user click the tray icon. + If you reimplement this function the reason parameter will be passed as $0. + Values for reason are: + - Unknown : Unknown reason. + - Context : The context menu for the tray icon was requested. + - DoubleClick : The tray icon was double clicked. + - Trigger : The tray icon was clicked. + - MiddleClick : The tray icon was clicked with the middle mouse button. + The default implementation emits the [classfnc]$activated[/classfnc]() signal. + !fn: messageClickedEvent() + This event is triggered when the message displayed using [classfnc]$showMessage[/classfnc]() was clicked by the user. + The default implementation emits the [classfnc]$messageClicked[/classfnc]() signal. + + + @signals: + !sg: $activated() + This signal is emitted by the default implementation of [classfnc]$activatedEvent[/classfnc]. + !sg: $messageClicked() + This signal is emitted by the default implementation of [classfnc]$messageClickedEvent[/classfnc]. +*/ + +KVSO_BEGIN_REGISTERCLASS(KvsObject_trayIcon,"trayicon","object") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_trayIcon,show) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_trayIcon,hide) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_trayIcon,isVisible) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_trayIcon,setIcon) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_trayIcon,setTooltip) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_trayIcon,showMessage) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_trayIcon,setContextMenu) + // events + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_trayIcon,activatedEvent) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_trayIcon,messageClickedEvent) +KVSO_END_REGISTERCLASS(KvsObject_trayIcon) + + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_trayIcon,KviKvsObject) + m_pTrayIcon = new QSystemTrayIcon(0); + connect(m_pTrayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(slotActivated(QSystemTrayIcon::ActivationReason))); + connect(m_pTrayIcon,SIGNAL(messageClicked()),this,SLOT(slotMessageClicked())); + +KVSO_END_CONSTRUCTOR(KvsObject_trayIcon) + +KVSO_BEGIN_DESTRUCTOR(KvsObject_trayIcon) + delete m_pTrayIcon; +KVSO_END_DESTRUCTOR(KvsObject_trayIcon) + + +KVSO_CLASS_FUNCTION(trayIcon,setIcon) +{ + CHECK_INTERNAL_POINTER(m_pTrayIcon) + QString szIcon; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("icon",KVS_PT_STRING,0,szIcon) + KVSO_PARAMETERS_END(c) + QPixmap * pix = g_pIconManager->getImage(szIcon); + if(pix) m_pTrayIcon->setIcon(*pix); + return true; +} +KVSO_CLASS_FUNCTION(trayIcon,setTooltip) +{ + CHECK_INTERNAL_POINTER(m_pTrayIcon) + QString szTooltip; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("icon",KVS_PT_STRING,0,szTooltip) + KVSO_PARAMETERS_END(c) + m_pTrayIcon->setToolTip(szTooltip); + return true; +} +KVSO_CLASS_FUNCTION(trayIcon,show) +{ + CHECK_INTERNAL_POINTER(m_pTrayIcon) + m_pTrayIcon->show(); + return true; +} +KVSO_CLASS_FUNCTION(trayIcon,hide) +{ + CHECK_INTERNAL_POINTER(m_pTrayIcon) + m_pTrayIcon->show(); + return true; +} +KVSO_CLASS_FUNCTION(trayIcon,isVisible) +{ + CHECK_INTERNAL_POINTER(m_pTrayIcon) + c->returnValue()->setBoolean(m_pTrayIcon->isVisible()); + return true; +} + +KVSO_CLASS_FUNCTION(trayIcon,showMessage) +{ + CHECK_INTERNAL_POINTER(m_pTrayIcon) + QString szMessage,szTitle,szMessageIcon; + kvs_uint_t uTimeout; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("title",KVS_PT_STRING,0,szTitle) + KVSO_PARAMETER("message",KVS_PT_STRING,0,szMessage) + KVSO_PARAMETER("icon",KVS_PT_STRING,0,szMessageIcon) + KVSO_PARAMETER("timeout",KVS_PT_UINT,0,uTimeout) + KVSO_PARAMETERS_END(c) + QSystemTrayIcon::MessageIcon message=QSystemTrayIcon::NoIcon; + if(KviQString::equalCI(szMessageIcon,"NoIcon")) message= QSystemTrayIcon::NoIcon; + else if(KviQString::equalCI(szMessageIcon,"Information"))message= QSystemTrayIcon::Information; + else if(KviQString::equalCI(szMessageIcon,"Warning")) message= QSystemTrayIcon::Warning; + else if(KviQString::equalCI(szMessageIcon,"Critical")) message= QSystemTrayIcon::Critical; + else c->warning(__tr2qs_ctx("Invalid message Icon: switch to default NoIcon '%Q'","objects"),&szMessageIcon); + m_pTrayIcon->showMessage(szTitle,szMessage,message,uTimeout); + return true; +} + +KVSO_CLASS_FUNCTION(trayIcon,setContextMenu) +{ + CHECK_INTERNAL_POINTER(m_pTrayIcon) + 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_ctx("Widget parameter is not an object","objects")); + return true; + } + if (!ob->object()) + { + c->warning(__tr2qs_ctx("Widget parameter is not a valid object","objects")); + return true; + } + if(!ob->inheritsClass("popupmenu")) + { + c->warning(__tr2qs_ctx("Can't add a non-popupmenu object","objects")); + return true; + } + m_pTrayIcon->setContextMenu(((QMenu *)(ob->object()))); + return true; +} +KVSO_CLASS_FUNCTION(trayIcon,activatedEvent) +{ + emitSignal("activated",c,c->params()); + return true; +} +KVSO_CLASS_FUNCTION(trayIcon,messageClickedEvent) +{ + emitSignal("messageClicked",c,c->params()); + return true; +} +void KvsObject_trayIcon::slotMessageClicked() +{ + KviKvsVariantList *lParams=0; + callFunction(this,"messageClickedEvent",0,lParams); +} + +void KvsObject_trayIcon::slotActivated(QSystemTrayIcon::ActivationReason reason) +{ + QString szReason; + if (reason==QSystemTrayIcon::Unknown) + szReason="Unknown"; + else if(reason==QSystemTrayIcon::Context) + szReason="Context"; + else if(reason==QSystemTrayIcon::DoubleClick) + szReason="DoubleClick"; + else if(reason==QSystemTrayIcon::Trigger) + szReason="Trigger"; + else szReason="MiddleClick"; + KviKvsVariantList lParams; + lParams.append(new KviKvsVariant(szReason)); + callFunction(this,"activatedEvent",0,&lParams); +} +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_trayIcon.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/KvsObject_trayIcon.h b/src/modules/objects/KvsObject_trayIcon.h new file mode 100644 index 000000000..4bec98e67 --- /dev/null +++ b/src/modules/objects/KvsObject_trayIcon.h @@ -0,0 +1,58 @@ +#ifndef _CLASS_TRAYICON_H_ +#define _CLASS_TRAYICON_H_ +//============================================================================= +// +// File : KvsObject_trayIcon.h +// Creation date : Wed Ago 25 17:28:45 2010 GMT by Carbone Alesssandro +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "object_macros.h" +#include +#include + +class KvsObject_trayIcon : public KviKvsObject +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_trayIcon) +protected: + QSystemTrayIcon *m_pTrayIcon; +protected: + bool setIcon(KviKvsObjectFunctionCall *c); + bool show(KviKvsObjectFunctionCall *c); + bool hide(KviKvsObjectFunctionCall *c); + bool isVisible(KviKvsObjectFunctionCall *c); + bool setTooltip(KviKvsObjectFunctionCall *c); + bool showMessage(KviKvsObjectFunctionCall *c); + bool setContextMenu(KviKvsObjectFunctionCall *c); + bool activatedEvent(KviKvsObjectFunctionCall *c); + bool messageClickedEvent(KviKvsObjectFunctionCall *c); + + +protected slots: + void slotActivated(QSystemTrayIcon::ActivationReason); + void slotMessageClicked(); +}; +#endif //_CLASS_TRAYICON_H_ diff --git a/src/modules/objects/KvsObject_treeWidget.cpp b/src/modules/objects/KvsObject_treeWidget.cpp new file mode 100644 index 000000000..c12649bfb --- /dev/null +++ b/src/modules/objects/KvsObject_treeWidget.cpp @@ -0,0 +1,666 @@ +//============================================================================= +// +// File : KvsObject_treeWidget.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) 2005-2008 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 "KvsObject_treeWidget.h" + +#include "KviError.h" +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KviIconManager.h" +#include + + #include + +#include +#include +#include +#include +#include + +/* + @doc: listview + @keyterms: + listview widget class + @title: + listview class + @type: + class + @short: + A listview widget 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]listviewtitem[/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 in ascending order if sort_order is "ascending" or descending order if it is "descending". + !fn: $setSortingEnabled() + If is true, user sorting is enabled for the tree. The default value is false. + In order to avoid performance issues, it is recommended that sorting is enabled after inserting the items into the tree. + !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: $selectedItems() + 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: $itemAt(,) + Returns the listviewitem object at the x,y globals coordinates or $null if no item at. + + !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: $topLevelItem() + Returns the child [class]listviewitem[/class] of this listview or $null if it does not exists. + + !fn: $topLevelItemCount() + Returns the number of top level items of this listview. + + !fn: setAcceptDrops() + If is true, user can drop files for this listview. The default value is true. + + !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: $itemActivatedEvent() + This s signal is emitted when the user activates an item by single- or double-clicking or pressing 'Enter'.[br] + In its argument the currrent item.[br] + The default implementation emits the [classfnc]$itemActivated[/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: $itemChangedEvent(,,) + 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]$itemChanged[/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: $itemActivated() + This signal is emitted by the default implementation of [classfnc]$itemActivatedEvent[/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: $itemChanged() + This signal is emitted by the default implementation of [classfnc]$itemChangedEvent[/classfnc](). + !sg: $rightButtonClicked() + This signal is emitted by the default implementation of [classfnc]$rightButtonClickedEvent[/classfnc](). + + +*/ + + + +//--------------------------------------------------------------------------------- + +KVSO_BEGIN_REGISTERCLASS(KvsObject_treeWidget,"listview","widget") + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,setHeaderLabels) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,addColumn) + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,setColumnText) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,setColumnCount) + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,setSorting) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,setSortingEnabled) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,setRootIsDecorated) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,setAllColumnsShowFocus) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,clear) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,selectedItems) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,currentItem) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,setSelectionMode) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,listViewHeaderIsVisible) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,itemAt) + + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,hideListViewHeader) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,showListViewHeader) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,firstChild) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,topLevelItem) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,topLevelItemCount) + + + + + //events + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,selectionChangedEvent); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,currentChangedEvent); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,itemActivatedEvent); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,onItemEvent); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,itemClickedEvent); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,itemExpandedEvent); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,itemCollapsedEvent); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,itemChangedEvent); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidget,setAcceptDrops); + KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KvsObject_treeWidget,"fileDroppedEvent") + +KVSO_END_REGISTERCLASS(KvsObject_treeWidget) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_treeWidget,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_treeWidget) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_treeWidget) + +KVSO_END_CONSTRUCTOR(KvsObject_treeWidget) + +bool KvsObject_treeWidget::init(KviKvsRunTimeContext *,KviKvsVariantList *) +{ + setObject(new KviKvsTreeWidget(parentScriptWidget(),getName().toUtf8().data(),this),true); + // hack for compatibility with "old" addColumn method; + ((QTreeWidget*) widget())->setColumnCount(0); + + connect(widget(),SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(slotClicked(QTreeWidgetItem *,int))); + connect(widget(),SIGNAL(itemSelectionChanged()),this,SLOT(slotSelectionChanged())); + connect(widget(),SIGNAL(currentItemChanged(QTreeWidgetItem *,QTreeWidgetItem *)),this,SLOT(slotCurrentChanged(QTreeWidgetItem *,QTreeWidgetItem *))); + connect(widget(),SIGNAL(itemActivated(QTreeWidgetItem *,int)),this,SLOT(slotItemActivated(QTreeWidgetItem *,int))); + connect(widget(),SIGNAL(itemEntered(QTreeWidgetItem *,int)),this,SLOT(slotOnItemEntered(QTreeWidgetItem *,int))); + connect(widget(),SIGNAL(itemExpanded(QTreeWidgetItem *)),this,SLOT(slotItemExpanded(QTreeWidgetItem *))); + connect(widget(),SIGNAL(itemCollapsed(QTreeWidgetItem *)),this,SLOT(slotItemCollapsed(QTreeWidgetItem *))); + connect(widget(),SIGNAL(itemChanged(QTreeWidgetItem *,int)),this,SLOT(slotItemChanged(QTreeWidgetItem *,int))); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidget,setHeaderLabels) +{ + QStringList columns; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("labels",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,columns) + KVSO_PARAMETERS_END(c) + if (widget()){ + ((QTreeWidget *)object())->setHeaderLabels(columns); + } + return true; +} + +KVSO_CLASS_FUNCTION(treeWidget,setColumnText) +{ + if (!widget()) return true; + QString szLabel; + kvs_int_t iCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_INT,0,iCol) + KVSO_PARAMETER("label",KVS_PT_STRING,0,szLabel) + KVSO_PARAMETERS_END(c) + QTreeWidgetItem *header=((QTreeWidget *)widget())->headerItem(); + header->setText(iCol,szLabel); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidget,topLevelItem) +{ + if (!widget()) return true; + kvs_int_t iIdx; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_INT,0,iIdx) + KVSO_PARAMETERS_END(c) + QTreeWidgetItem *pItem=((QTreeWidget *)widget())->topLevelItem(iIdx); + if (!pItem) c->returnValue()->setHObject((kvs_hobject_t)0); + else c->returnValue()->setHObject(KvsObject_treeWidgetItem::itemToHandle(pItem)); + return true; +} +KVSO_CLASS_FUNCTION(treeWidget,itemAt) +{ + if (!widget()) return true; + kvs_int_t iXpos,iYpos; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x_pos",KVS_PT_INT,0,iXpos) + KVSO_PARAMETER("y_pos",KVS_PT_INT,0,iYpos) + KVSO_PARAMETERS_END(c) + QPoint pPoint=((QTreeWidget *)widget())->viewport()->mapFromGlobal(QPoint(iXpos,iYpos)); + QTreeWidgetItem *pItem=((QTreeWidget *)widget())->itemAt(pPoint); + if (!pItem) c->returnValue()->setHObject((kvs_hobject_t)0); + else c->returnValue()->setHObject(KvsObject_treeWidgetItem::itemToHandle(pItem)); + return true; +} +KVSO_CLASS_FUNCTION(treeWidget,topLevelItemCount) +{ + if (!widget()) return true; + c->returnValue()->setInteger(((QTreeWidget *)widget())->topLevelItemCount()); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidget,addColumn) +{ + if (!widget()) return true; + QString szLabel; + kvs_int_t iW; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("label",KVS_PT_STRING,0,szLabel) + KVSO_PARAMETER("width",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETERS_END(c) + int col=((QTreeWidget *)widget())->columnCount(); + QTreeWidgetItem *header=((QTreeWidget *)widget())->headerItem(); + header->setText(col,szLabel); + if(iW) ((QTreeWidget *)widget())->setColumnWidth(col,iW); + col++; + ((QTreeWidget *)widget())->setColumnCount(col); + //col++; + return true; +} + +KVSO_CLASS_FUNCTION(treeWidget,setAcceptDrops) +{ + bool bEnable; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnable",KVS_PT_BOOLEAN,0,bEnable) + KVSO_PARAMETERS_END(c) + if (widget()) + ((QTreeWidget *)object())->setAcceptDrops(bEnable); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidget,clear) +{ + Q_UNUSED(c); + if (widget()) + ((QTreeWidget *)object())->clear(); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidget,selectedItems) +{ + if(widget()) + { + QList list=((QTreeWidget *)widget())->selectedItems(); + KviKvsArray * pArray = new KviKvsArray(); + c->returnValue()->setArray(pArray); + for (int i=0;iset(i,new KviKvsVariant(KvsObject_treeWidgetItem::itemToHandle((QTreeWidgetItem*)list.at(i)))); + } + else + c->returnValue()->setHObject((kvs_hobject_t)0); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidget,firstChild) +{ + if(widget()) + c->returnValue()->setHObject(KvsObject_treeWidgetItem::itemToHandle((QTreeWidgetItem*)((QTreeWidget *)widget())->topLevelItem(0))); + else + c->returnValue()->setHObject((kvs_hobject_t)0); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidget,currentItem) +{ + if(widget()) + c->returnValue()->setHObject(KvsObject_treeWidgetItem::itemToHandle((QTreeWidgetItem*)((QTreeWidget *)widget())->currentItem())); + else + c->returnValue()->setHObject((kvs_hobject_t)0); + return true; +} +/* +KVSO_CLASS_FUNCTION(treeWidget,setColumnText) +{ + 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())((QTreeWidget *)widget())->setColumnText(uCol,szText); + return true; +} +*/ +KVSO_CLASS_FUNCTION(treeWidget,setColumnCount) +{ + kvs_uint_t uCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETERS_END(c) + if (widget())((QTreeWidget *)widget())->setColumnCount(uCol); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidget,setSelectionMode) +{ + 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")) + ((QTreeWidget *)widget())->setSelectionMode(QAbstractItemView::NoSelection); + else if(KviQString::equalCI(szMode,"Multi")) + ((QTreeWidget *)widget())->setSelectionMode(QTreeWidget::MultiSelection); + else if(KviQString::equalCI(szMode,"Extended")) + ((QTreeWidget *)widget())->setSelectionMode(QTreeWidget::ExtendedSelection); + else if(KviQString::equalCI(szMode,"Single")) + ((QTreeWidget *)widget())->setSelectionMode(QTreeWidget::SingleSelection); + else c->warning(__tr2qs_ctx("Invalid selection mode '%Q'","objects"),&szMode); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidget,setSorting) +{ + kvs_int_t iCol; + QString szOrder; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_INT,0,iCol) + KVSO_PARAMETER("sort_order",KVS_PT_STRING,0,szOrder) + KVSO_PARAMETERS_END(c) + if (!widget())return true; + if (KviQString::equalCI(szOrder,"ascending")) ((QTreeWidget *)widget())->sortItems(iCol,Qt::AscendingOrder); + else if (KviQString::equalCI(szOrder,"descending")) ((QTreeWidget *)widget())->sortItems(iCol,Qt::DescendingOrder); + else c->warning(__tr2qs_ctx("Unknown '%Q' sort order: switching to ascending order","objects"),&szOrder); + return true; +} +KVSO_CLASS_FUNCTION(treeWidget,setSortingEnabled) +{ + bool bEnables; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnables",KVS_PT_BOOLEAN,0,bEnables) + KVSO_PARAMETERS_END(c) + if (!widget())return true; + ((QTreeWidget *)widget())->setSortingEnabled(bEnables); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidget,setRootIsDecorated) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if (widget()) ((QTreeWidget *)widget())->setRootIsDecorated(bEnabled); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidget,setAllColumnsShowFocus) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bAllColumnsShowFocus",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if (widget())((QTreeWidget *)widget())->setAllColumnsShowFocus(bEnabled); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidget,hideListViewHeader) +{ + Q_UNUSED(c); + ((QTreeWidget *)widget())->header()->hide(); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidget,showListViewHeader) +{ + Q_UNUSED(c); + ((QTreeWidget *)widget())->header()->show(); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidget,listViewHeaderIsVisible) +{ + c->returnValue()->setBoolean(((QTreeWidget *)widget())->header()->isVisible()); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidget,itemClickedEvent) +{ + emitSignal("itemClicked",c,c->params()); + return true; +} + +void KvsObject_treeWidget::slotClicked(QTreeWidgetItem * i,int col) +{ + KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col); + + KviKvsVariantList params(new KviKvsVariant(KvsObject_treeWidgetItem::itemToHandle(i)),column); + callFunction(this,"itemClickedEvent",0,¶ms); +} + +KVSO_CLASS_FUNCTION(treeWidget,selectionChangedEvent) +{ + emitSignal("selectionChanged",c,c->params()); + return true; +} + +void KvsObject_treeWidget::slotSelectionChanged() +{ + if (((QTreeWidget *)widget())->selectionMode()==QTreeWidget::SingleSelection) + { + QTreeWidgetItem *it=(QTreeWidgetItem *) ((QTreeWidget *)widget())->currentItem(); + KviKvsVariantList params(new KviKvsVariant(KvsObject_treeWidgetItem::itemToHandle(it))); + callFunction(this,"selectionChangedEvent",0,¶ms); + } + else{ + KviKvsVariantList params(new KviKvsVariant((kvs_hobject_t)0)); + callFunction(this,"selectionChangedEvent",0,¶ms); + } +} + +KVSO_CLASS_FUNCTION(treeWidget,currentChangedEvent) +{ + emitSignal("currentChanged",c,c->params()); + return true; +} + +void KvsObject_treeWidget::slotCurrentChanged(QTreeWidgetItem * i,QTreeWidgetItem *prev) +{ + KviKvsVariantList params(new KviKvsVariant(KvsObject_treeWidgetItem::itemToHandle(i)),new KviKvsVariant(KvsObject_treeWidgetItem::itemToHandle(prev))); + callFunction(this,"currentChangedEvent",0,¶ms); +} + +KVSO_CLASS_FUNCTION(treeWidget,itemActivatedEvent) +{ + emitSignal("itemActivated",c,c->params()); + return true; +} + +void KvsObject_treeWidget::slotItemActivated(QTreeWidgetItem * i,int col) +{ + KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col); + KviKvsVariantList params(new KviKvsVariant(KvsObject_treeWidgetItem::itemToHandle(i)),column); + callFunction(this,"itemActivatedEvent",0,¶ms); +} + +KVSO_CLASS_FUNCTION(treeWidget,onItemEvent) +{ + + emitSignal("onItem",c,c->params()); + return true; +} + +void KvsObject_treeWidget::slotOnItemEntered(QTreeWidgetItem * i,int col) +{ + KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col); + + KviKvsVariantList params(new KviKvsVariant(KvsObject_treeWidgetItem::itemToHandle(i)),column); + callFunction(this,"onItemEvent",0,¶ms); +} + +KVSO_CLASS_FUNCTION(treeWidget,itemExpandedEvent) +{ + emitSignal("itemExpanded",c,c->params()); + return true; +} + +void KvsObject_treeWidget::slotItemExpanded(QTreeWidgetItem * i) +{ + KviKvsVariantList params(new KviKvsVariant(KvsObject_treeWidgetItem::itemToHandle(i))); + callFunction(this,"itemExpandedEvent",0,¶ms); +} + +KVSO_CLASS_FUNCTION(treeWidget,itemCollapsedEvent) +{ + emitSignal("itemCollapsed",c,c->params()); + return true; +} + +void KvsObject_treeWidget::slotItemCollapsed(QTreeWidgetItem * i) +{ + KviKvsVariantList params(new KviKvsVariant(KvsObject_treeWidgetItem::itemToHandle(i))); + callFunction(this,"itemCollapsedEvent",0,¶ms); +} + + + +KVSO_CLASS_FUNCTION(treeWidget,itemChangedEvent) +{ + emitSignal("itemChanged",c,c->params()); + return true; +} + +void KvsObject_treeWidget::slotItemChanged(QTreeWidgetItem *item,int col) +{ + KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col); + KviKvsVariantList params(new KviKvsVariant(KvsObject_treeWidgetItem::itemToHandle(item)),column); + callFunction(this,"itemChangedEvent",0,¶ms); +} + +void KvsObject_treeWidget::fileDropped(QString &szFile,QTreeWidgetItem *item) +{ + KviKvsVariant *file=new KviKvsVariant(szFile); + KviKvsVariantList params(new KviKvsVariant(KvsObject_treeWidgetItem::itemToHandle(item)),file); + callFunction(this,"fileDroppedEvent",0,¶ms); +} + +KviKvsTreeWidget::KviKvsTreeWidget(QWidget * par,const char *,KvsObject_treeWidget *parent) +:QTreeWidget(par) +{ + m_pParentScript=parent; + setAcceptDrops(true); + setDragEnabled(true); + setDropIndicatorShown(true); + setDragDropMode(QAbstractItemView::DragDrop); + viewport()->setAcceptDrops(true); +} + +KviKvsTreeWidget::~KviKvsTreeWidget() +{ +} + +void KviKvsTreeWidget::dragEnterEvent( QDragEnterEvent * e ) +{ + if(!e->mimeData()->hasUrls()) + { + e->ignore(); + return; + } + e->acceptProposedAction(); +} + +void KviKvsTreeWidget::dragMoveEvent( QDragMoveEvent * ) +{ + // ?#! +} + +void KviKvsTreeWidget::dropEvent(QDropEvent * e) +{ + qDebug("Drop event"); + QList list; + if(e->mimeData()->hasUrls()) + { + list = e->mimeData()->urls(); + + if(!list.isEmpty()) + { + QList::Iterator it = list.begin(); + for( ; it != list.end(); ++it ) + { + QUrl url = *it; + QString path = url.toLocalFile(); + qDebug("path %s",path.toUtf8().data()); + QTreeWidgetItem *i = itemAt( e->pos() ); + m_pParentScript->fileDropped(path,i); + } + } + } +} + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_KvsObject_treeWidget.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/KvsObject_treeWidget.h b/src/modules/objects/KvsObject_treeWidget.h new file mode 100644 index 000000000..05fb3f4cc --- /dev/null +++ b/src/modules/objects/KvsObject_treeWidget.h @@ -0,0 +1,100 @@ +#ifndef _CLASS_TREEWIDGET_H_ +#define _CLASS_TREEWIDGET_H_ +//============================================================================= +// +// File : KvsObject_treeWidget.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) 2005-2008 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 "KvsObject_widget.h" +#include "KvsObject_treeWidgeteItem.h" +#include "object_macros.h" + +#include + +class KvsObject_treeWidget : public KvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KvsObject_treeWidget) + +public: + QWidget * widget() { return (QWidget *)object(); }; + void fileDropped(QString &,QTreeWidgetItem *); +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool addColumn(KviKvsObjectFunctionCall *c); + bool setColumnText(KviKvsObjectFunctionCall *c); + bool takeItem(KviKvsObjectFunctionCall *c); + bool setSorting(KviKvsObjectFunctionCall *c); + bool setSortingEnabled(KviKvsObjectFunctionCall *c); + bool setRootIsDecorated(KviKvsObjectFunctionCall *c); + bool clear(KviKvsObjectFunctionCall *c); + bool setAllColumnsShowFocus(KviKvsObjectFunctionCall *c); + bool itemClickedEvent(KviKvsObjectFunctionCall *c); + bool selectionChangedEvent(KviKvsObjectFunctionCall *c); + bool currentChangedEvent(KviKvsObjectFunctionCall *c); + bool itemActivatedEvent(KviKvsObjectFunctionCall *c); + bool onItemEvent(KviKvsObjectFunctionCall *c); + bool itemExpandedEvent(KviKvsObjectFunctionCall *c); + bool itemCollapsedEvent(KviKvsObjectFunctionCall *c); + bool itemChangedEvent(KviKvsObjectFunctionCall *c); + bool selectedItems(KviKvsObjectFunctionCall *c); + bool currentItem(KviKvsObjectFunctionCall *c); + bool setSelectionMode(KviKvsObjectFunctionCall *c); + bool firstChild(KviKvsObjectFunctionCall *c); + bool listViewHeaderIsVisible(KviKvsObjectFunctionCall *c); + bool showListViewHeader(KviKvsObjectFunctionCall *c); + bool hideListViewHeader(KviKvsObjectFunctionCall *c); + bool setAcceptDrops(KviKvsObjectFunctionCall *c); + bool setHeaderLabels(KviKvsObjectFunctionCall *c); + bool setColumnCount(KviKvsObjectFunctionCall *c); + bool topLevelItem(KviKvsObjectFunctionCall *c); + bool topLevelItemCount(KviKvsObjectFunctionCall *c); + bool itemAt(KviKvsObjectFunctionCall *c); +protected slots: + void slotClicked(QTreeWidgetItem *,int); + void slotSelectionChanged(); + void slotCurrentChanged(QTreeWidgetItem *,QTreeWidgetItem *); + void slotItemActivated(QTreeWidgetItem *,int col); + void slotOnItemEntered(QTreeWidgetItem *,int col); + void slotItemExpanded(QTreeWidgetItem *); + void slotItemCollapsed(QTreeWidgetItem *); + void slotItemChanged(QTreeWidgetItem *,int); +}; + +class KviKvsTreeWidget : public QTreeWidget +{ + Q_OBJECT +public: + KviKvsTreeWidget(QWidget * par, const char * name, KvsObject_treeWidget *); + virtual ~KviKvsTreeWidget(); +protected: + KvsObject_treeWidget * m_pParentScript; +protected: + void dropEvent(QDropEvent * e); + void dragEnterEvent(QDragEnterEvent * e); + void dragMoveEvent( QDragMoveEvent * e ); +}; + +#endif // _CLASS_TREEWIDGET_H_ diff --git a/src/modules/objects/KvsObject_treeWidgeteItem.cpp b/src/modules/objects/KvsObject_treeWidgeteItem.cpp new file mode 100644 index 000000000..da7422687 --- /dev/null +++ b/src/modules/objects/KvsObject_treeWidgeteItem.cpp @@ -0,0 +1,429 @@ +//============================================================================= +// +// File : KvsObject_treeWidgeteItem.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) 2005-2008 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 "KvsObject_treeWidgeteItem.h" +#include "KvsObject_pixmap.h" + +#include "KviError.h" +#include "kvi_debug.h" +#include "KviLocale.h" +#include "KviIconManager.h" +#include + +const int item_flags[] = { + Qt::NoItemFlags, + Qt::ItemIsSelectable, + Qt::ItemIsEditable, + Qt::ItemIsDragEnabled, + Qt::ItemIsDropEnabled, + Qt::ItemIsUserCheckable, + Qt::ItemIsEnabled, + Qt::ItemIsTristate +}; + +const char * const itemflags_tbl[] = { + "noitemflag", + "selectable", + "editable", + "dragEnabled", + "dropEnabled", + "userCheckable", + "enabled", + "tristate" +}; + +#define itemflags_num (sizeof(itemflags_tbl) / sizeof(itemflags_tbl[0])) + + + +/* + @doc: listviewitem + @keyterms: + listview tlistviewitem class + @title: + listviewtitem 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: $setItemEditable() + If bEnabled is TRUE (1), this item can be in-place editable by the user; otherwise it cannot be editable in-place. + + !fn: $isItemEditable() + Returns $true if this item is editable and $false otherwise. + + !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: $setFlags(, , ...) + Sets the flags for the item to the given flags. These determine whether the item can be selected or modified. This is often used to disable an item. + Supported flags are: + - noitemflag : no flag sets; + - selectable : item is selecatble; + - editable : item is editable; + - dragEnabled : item can dragged; + - dropEnabled : item can used as drop target; + - userCheckable : item is checkable; + - enabled :item is enabled; + - tristate : item is checkable with three separate states. + + +*/ + + +//=========================================================================================== + +KVSO_BEGIN_REGISTERCLASS(KvsObject_treeWidgetItem,"listviewitem","object") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,setText) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,text) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,setPixmap); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,setItemEditable); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,isItemEditable); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,setEnabled); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,isEnabled); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,setOpen); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,isOpen); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,setCheckable); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,isCheckable); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,setChecked); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,isChecked); + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,setFlags); + +KVSO_END_REGISTERCLASS(KvsObject_treeWidgetItem) + + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_treeWidgetItem,KviKvsObject) + + m_pTreeWidgetItem = 0; + +KVSO_END_CONSTRUCTOR(KvsObject_treeWidgetItem) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_treeWidgetItem) + + if(m_pTreeWidgetItem)delete m_pTreeWidgetItem; + +KVSO_END_CONSTRUCTOR(KvsObject_treeWidgetItem) + +bool KvsObject_treeWidgetItem::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *) +{ + if (!parentObject()) + { + pContext->error(__tr2qs_ctx("The listviewitem cannot be parentless","objects")); + return false; + } + if(parentObject()->inheritsClass("listviewitem")) + { + m_pTreeWidgetItem = new KviKvsStandardTreeWidgetItem(this,((KvsObject_treeWidgetItem *)parentObject())->m_pTreeWidgetItem); + } else { + if(parentObject()->inheritsClass("listview")) + m_pTreeWidgetItem = new KviKvsStandardTreeWidgetItem(this,((QTreeWidget *)parentScriptWidget())); + else { + pContext->error(__tr2qs_ctx("The parent of the listviewitem must be either another listviewitem or a listview","objects")); + return false; + } + } + return true; +} + +void KvsObject_treeWidgetItem::childDestroyed() +{ + if(m_pTreeWidgetItem == 0)return; + m_pTreeWidgetItem = 0; + die(); +} + +KviKvsStandardTreeWidgetItem::KviKvsStandardTreeWidgetItem(KvsObject_treeWidgetItem * ob,QTreeWidget * par) +:QTreeWidgetItem(par), m_pMasterObject(ob) +{ +} + +KviKvsStandardTreeWidgetItem::KviKvsStandardTreeWidgetItem(KvsObject_treeWidgetItem * ob,QTreeWidgetItem * par) +:QTreeWidgetItem(par), m_pMasterObject(ob) +{ +} + +KviKvsStandardTreeWidgetItem::~KviKvsStandardTreeWidgetItem() +{ + if(m_pMasterObject)m_pMasterObject->childDestroyed(); +} + +kvs_hobject_t KvsObject_treeWidgetItem::itemToHandle(QTreeWidgetItem * it) +{ + if(!it)return (kvs_hobject_t)0; + KvsObject_treeWidgetItem * pObject; + pObject = ((KviKvsStandardTreeWidgetItem *)it)->masterObject(); + if(!pObject)return (kvs_hobject_t)0; + return pObject->handle(); +} + +KVSO_CLASS_FUNCTION(treeWidgetItem,setText) +{ + 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_pTreeWidgetItem) + m_pTreeWidgetItem->setText(uCol,szText); + return true; +} + + +KVSO_CLASS_FUNCTION(treeWidgetItem,setItemEditable) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(m_pTreeWidgetItem) + m_pTreeWidgetItem->setFlags(bEnabled?m_pTreeWidgetItem->flags()|Qt::ItemIsEditable:m_pTreeWidgetItem->flags()&~Qt::ItemIsEditable); + return true; +} +KVSO_CLASS_FUNCTION(treeWidgetItem,isItemEditable) +{ + if(!m_pTreeWidgetItem) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(m_pTreeWidgetItem->flags()&Qt::ItemIsEditable); + return true; +} +KVSO_CLASS_FUNCTION(treeWidgetItem,setFlags) +{ + QStringList itemflags; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("flags",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,itemflags) + KVSO_PARAMETERS_END(c) + int flag,sum=0; + for ( int i=0;isetCheckState(0,Qt::Unchecked); + sum = sum | flag; + } + else + c->warning(__tr2qs_ctx("Unknown item flag '%Q'","objects"),&itemflags.at(i)); + } + if(m_pTreeWidgetItem) + m_pTreeWidgetItem->setFlags((Qt::ItemFlags)sum); + + return true; +} + +KVSO_CLASS_FUNCTION(treeWidgetItem,setEnabled) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(m_pTreeWidgetItem) + m_pTreeWidgetItem->setFlags(bEnabled?m_pTreeWidgetItem->flags()|Qt::ItemIsEnabled:m_pTreeWidgetItem->flags()&~Qt::ItemIsEnabled); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidgetItem,isEnabled) +{ + if(!m_pTreeWidgetItem) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(m_pTreeWidgetItem->flags()&Qt::ItemIsEnabled); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidgetItem,setOpen) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(m_pTreeWidgetItem) + m_pTreeWidgetItem->setExpanded(bEnabled); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidgetItem,isOpen) +{ + if(!m_pTreeWidgetItem) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(m_pTreeWidgetItem->isExpanded()); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidgetItem,setChecked) +{ + bool bChecked; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bChecked",KVS_PT_BOOL,0,bChecked) + KVSO_PARAMETERS_END(c) + if(!m_pTreeWidgetItem)return true; + ((QTreeWidgetItem *)m_pTreeWidgetItem)->setCheckState(0,bChecked?Qt::Checked:Qt::Unchecked); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidgetItem,isChecked) +{ + if(!m_pTreeWidgetItem) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(((QTreeWidgetItem *)m_pTreeWidgetItem)->checkState(0)==Qt::Checked?1:0); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidgetItem,setCheckable) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bCheckable",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(!m_pTreeWidgetItem)return true; + m_pTreeWidgetItem->setFlags(bEnabled?m_pTreeWidgetItem->flags()|Qt::ItemIsUserCheckable:m_pTreeWidgetItem->flags()&~Qt::ItemIsUserCheckable); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidgetItem,isCheckable) +{ + if(!m_pTreeWidgetItem) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(m_pTreeWidgetItem->flags()&Qt::ItemIsUserCheckable); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidgetItem,text) +{ + kvs_uint_t uCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETERS_END(c) + if(m_pTreeWidgetItem) + c->returnValue()->setString(m_pTreeWidgetItem->text(uCol)); + return true; +} + +KVSO_CLASS_FUNCTION(treeWidgetItem,setPixmap) +{ + 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->isEmpty()) {m_pTreeWidgetItem->setIcon(uCol,QIcon());return true;} + if(vPixmap->isHObject()) + { + vPixmap->asHObject(obHpixmap); + obPixmap=KviKvsKernel::instance()->objectController()->lookupObject(obHpixmap); + if (!obPixmap->inheritsClass("pixmap")) + { + c->warning(__tr2qs_ctx("Pixmap object or image Id required","objects")); + return true; + } + pix=((KvsObject_pixmap *)obPixmap)->getPixmap(); + } else { + QString szPix; + vPixmap->asString(szPix); + pix=g_pIconManager->getImage(szPix); + if(!pix) + { + c->warning(__tr2qs_ctx("Error occured: the suitable file '%Q' is not of the correct format or it is not a valid icon number.","objects"),&szPix); + return true; + } + } + m_pTreeWidgetItem->setIcon(uCol,QIcon(*pix)); + return true; +} + diff --git a/src/modules/objects/KvsObject_treeWidgeteItem.h b/src/modules/objects/KvsObject_treeWidgeteItem.h new file mode 100644 index 000000000..d2c56b8c6 --- /dev/null +++ b/src/modules/objects/KvsObject_treeWidgeteItem.h @@ -0,0 +1,78 @@ +#ifndef _CLASS_TREEWIDGETITEM_H_ +#define _CLASS_TREEWIDGETITEM_H_ +//============================================================================= +// +// File : KvsObject_treeWidgeteItem.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) 2005-2008 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 "KvsObject_widget.h" +#include "object_macros.h" + +#include + +class KvsObject_treeWidgetItem : public KviKvsObject +{ +public: + KVSO_DECLARE_OBJECT(KvsObject_treeWidgetItem) + void childDestroyed(); +protected: + QTreeWidgetItem * m_pTreeWidgetItem; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); +protected: + bool setText(KviKvsObjectFunctionCall *c); + bool insertItem(KviKvsObjectFunctionCall *c); + bool setPixmap(KviKvsObjectFunctionCall *c); + bool setItemEditable(KviKvsObjectFunctionCall *c); + bool isItemEditable(KviKvsObjectFunctionCall *c); + bool setEnabled(KviKvsObjectFunctionCall *c); + bool isEnabled(KviKvsObjectFunctionCall *c); + bool setOpen(KviKvsObjectFunctionCall *c); + bool isOpen(KviKvsObjectFunctionCall *c); + bool text(KviKvsObjectFunctionCall *c); + bool setCheckable(KviKvsObjectFunctionCall *c); + bool isCheckable(KviKvsObjectFunctionCall *c); + bool setChecked(KviKvsObjectFunctionCall *c); + bool isChecked(KviKvsObjectFunctionCall *c); + bool setFlags(KviKvsObjectFunctionCall *c); + +public: + static kvs_hobject_t itemToHandle(QTreeWidgetItem * it); +}; + + +class KviKvsStandardTreeWidgetItem : public QTreeWidgetItem +{ +public: + KviKvsStandardTreeWidgetItem(KvsObject_treeWidgetItem * ob,QTreeWidget * par); + KviKvsStandardTreeWidgetItem(KvsObject_treeWidgetItem * ob,QTreeWidgetItem * par); + virtual ~KviKvsStandardTreeWidgetItem(); +protected: + KvsObject_treeWidgetItem * m_pMasterObject; +public: + KvsObject_treeWidgetItem * masterObject(){ return m_pMasterObject; } +}; + + +#endif // _CLASS_TREEWIDGETITEM_H_ diff --git a/src/modules/objects/KvsObject_vBox.cpp b/src/modules/objects/KvsObject_vBox.cpp new file mode 100644 index 000000000..65fced903 --- /dev/null +++ b/src/modules/objects/KvsObject_vBox.cpp @@ -0,0 +1,209 @@ +//============================================================================= +// +// File : KvsObject_vBox.cpp +// 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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KviLocale.h" + +#include "KvsObject_vBox.h" + +#include "KviTalVBox.h" + + +// Tables used in $setAlignment & $alignment +const char * const align_tbl[] = { + "Left", + "Right", + "HCenter", + "VCenter", + "Center", + "Top", + "Bottom", + "WordBreak" + }; + + + +const int align_cod[] = { + Qt::AlignLeft, + Qt::AlignRight, + Qt::AlignHCenter, + Qt::AlignVCenter, + Qt::AlignCenter, + Qt::AlignTop, + Qt::AlignBottom, + Qt::AlignJustify, + }; + +#define align_num (sizeof(align_tbl) / sizeof(align_tbl[0])) +/* + @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. + !fn: $addStretch() + Adds a stretchable space with zero minimum size and stretch factor stretch to the end of this box layout. + !fn: $setAlignment(, , ...) + Sets the alignment for widget w to flags, given as parameters. + Valid flags are:Right,Left,Top,Bottom,HCenter,VCenter,Center +*/ + + +KVSO_BEGIN_REGISTERCLASS(KvsObject_vBox,"vbox","widget") + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_vBox,setMargin) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_vBox,setSpacing) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_vBox,setStretchFactor) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_vBox,addStretch) + KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_vBox,setAlignment) +KVSO_END_REGISTERCLASS(KvsObject_vBox) + +KVSO_BEGIN_CONSTRUCTOR(KvsObject_vBox,KvsObject_widget) + +KVSO_END_CONSTRUCTOR(KvsObject_vBox) + + +KVSO_BEGIN_DESTRUCTOR(KvsObject_vBox) + +KVSO_END_CONSTRUCTOR(KvsObject_vBox) + +bool KvsObject_vBox::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + Q_UNUSED(pContext); + Q_UNUSED(pParams); + + SET_OBJECT(KviTalVBox); + return true; +} + +KVSO_CLASS_FUNCTION(vBox,setMargin) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iMargin; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("margin",KVS_PT_INT,0,iMargin) + KVSO_PARAMETERS_END(c) + ((KviTalVBox *)widget())->setMargin(iMargin); + return true; +} + +KVSO_CLASS_FUNCTION(vBox,setSpacing) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iSpacing; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("spacing",KVS_PT_INT,0,iSpacing) + KVSO_PARAMETERS_END(c) + ((KviTalVBox *)widget())->setSpacing(iSpacing); + return true; +} + +KVSO_CLASS_FUNCTION(vBox,setStretchFactor) +{ + CHECK_INTERNAL_POINTER(widget()) + 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); + return true; + CHECK_HOBJECT_IS_WIDGET(pObject) + if(((KvsObject_widget *)pObject)->widget()->parentWidget() != widget()) + { + c->warning(__tr2qs_ctx("The widget must be a child of this vbox","objects")); + return true; + } + ((KviTalVBox *)widget())->setStretchFactor(((QWidget *)(pObject->object())),uStretch); + return true; +} +KVSO_CLASS_FUNCTION(vBox,addStretch) +{ + CHECK_INTERNAL_POINTER(widget()) + kvs_int_t iStretch; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("stretch",KVS_PT_INT,0,iStretch) + KVSO_PARAMETERS_END(c) + ((KviTalVBox *)widget())->addStretch(iStretch); + return true; +} +KVSO_CLASS_FUNCTION(vBox,setAlignment) +{ + CHECK_INTERNAL_POINTER(widget()) + QStringList alignment; + KviKvsObject * pObject; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("alignment",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,alignment) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + CHECK_HOBJECT_IS_WIDGET(pObject) + if(((KvsObject_widget *)pObject)->widget()->parentWidget() != widget()) + { + c->warning(__tr2qs_ctx("The widget must be a child of this hbox","objects")); + 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_ctx("Unknown alignment: '%Q'","objects"),&(*it)); + + } + if (widget()) ((KviTalHBox *)widget())->setAlignment(((QWidget *)(pObject->object())),(Qt::Alignment)sum); + return true; +} + diff --git a/src/modules/objects/KvsObject_vBox.h b/src/modules/objects/KvsObject_vBox.h new file mode 100644 index 000000000..08342bea2 --- /dev/null +++ b/src/modules/objects/KvsObject_vBox.h @@ -0,0 +1,49 @@ +#ifndef _CLASS_VBOX_H_ +#define _CLASS_VBOX_H_ +//============================================================================= +// +// File : KvsObject_vBox.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) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your 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 "KviCString.h" +#include "KvsObject_widget.h" +#include "object_macros.h" + +class KvsObject_vBox : public KvsObject_widget +{ +public: + KVSO_DECLARE_OBJECT(KvsObject_vBox) +public: + QWidget * widget() { return (QWidget *)object(); }; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + bool setMargin(KviKvsObjectFunctionCall *c); + bool setSpacing(KviKvsObjectFunctionCall *c); + bool setStretchFactor(KviKvsObjectFunctionCall *c); + bool addStretch(KviKvsObjectFunctionCall *c); + bool setAlignment(KviKvsObjectFunctionCall *c); + +}; + + +#endif //_CLASS_HBOX_H_ diff --git a/src/modules/objects/KvsObject_widget.cpp b/src/modules/objects/KvsObject_widget.cpp new file mode 100644 index 000000000..c0598b7ae --- /dev/null +++ b/src/modules/objects/KvsObject_widget.cpp @@ -0,0 +1,2030 @@ +//============================================================================= +// +// File : KvsObject_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) 2000 Krzysztof Godlewski +// Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "KvsObject_widget.h" +#include "KvsObject_pixmap.h" + +#include "KviMemory.h" +#include "kvi_debug.h" +#include "KviError.h" +#include "KviLocale.h" +#include "KviIconManager.h" +#include "KviWindow.h" +#include "KviApplication.h" +#include "KviMainWindow.h" +#include "KviStatusBar.h" +#include "KvsObject_painter.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef COMPILE_WEBKIT_SUPPORT + #include +#endif + +KviKvsWidget::KviKvsWidget(KvsObject_widget * object,QWidget * par) +:QWidget(par), m_pObject(object) +{ +} + +KviKvsWidget::~KviKvsWidget() +{ +} + +QSize KviKvsWidget::sizeHint() const +{ + QSize size=QWidget::sizeHint(); + KviKvsVariant *tipret=new KviKvsVariant(); + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)size.width()),new KviKvsVariant((kvs_int_t)size.height())); + m_pObject->callFunction(m_pObject,"sizeHintRequestEvent",tipret,¶ms); + if (tipret->isArray()) + { + if (tipret->array()->size()==2) + { + kvs_int_t w,h; + if (tipret->array()->at(0)->asInteger(w) && tipret->array()->at(1)->asInteger(h))return QSize(w,h); + } + } + return QWidget::sizeHint(); +} + + + +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 QPalette::ColorRole colorrole_cod[] = { + QPalette::Window, + QPalette::Background, + QPalette::WindowText, + QPalette::Foreground, + QPalette::Base, + QPalette::AlternateBase, + QPalette::Text, + QPalette::Button, + QPalette::ButtonText, + QPalette::BrightText, + QPalette::Highlight, + QPalette::HighlightedText +}; + +const char * const colorrole_tbl[] = { + "Window", + "Background", + "WindowText", + "Foreground", + "Base", + "AlternateBase", + "Text", + "Button", + "ButtonText", + "BrightText", + "Highlight", + "HighlightedText" +}; + +#define colorrole_num (sizeof(colorrole_tbl) / sizeof(colorrole_tbl[0])) + + +const Qt::WindowType widgettypes_cod[] = { + Qt::Window, + Qt::Dialog, + Qt::Popup, + Qt::Desktop, + Qt::WindowTitleHint, + Qt::WindowStaysOnTopHint, + Qt::WindowSystemMenuHint, + Qt::WindowMinimizeButtonHint, + Qt::WindowMaximizeButtonHint, + Qt::SubWindow, + Qt::FramelessWindowHint +}; + + +const char * const widgettypes_tbl[] = { + "Window", + "Dialog", + "Popup", + "Desktop", + "Title", + "StaysOnTop", + "SysMenu", + "Minimize", + "Maximize", + "Subwindow", + "FramelessWindow" +}; + + +#define widgettypes_num (sizeof(widgettypes_tbl) / sizeof(widgettypes_tbl[0])) + + +#define QT_WIDGET_TABFOCUS Qt::TabFocus +#define QT_WIDGET_CLICKFOCUS Qt::ClickFocus +#define QT_WIDGET_STRONGFOCUS Qt::StrongFocus +#define QT_WIDGET_NOFOCUS Qt::NoFocus +/* + @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. + !fn: $update([,,,]) + Updates enterily the widget or a rectangle. + This function does not cause an immediate [classfnc]$paintEvent[/classfnc](); instead it schedules a paint event for processing when KVIrc returns to the main event loop. + !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: $setWindowTitle() + Sets the title 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: $windowTitle() + Returns the title 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(