From f4da8086b4ab698510290f92aa679a305a537a27 Mon Sep 17 00:00:00 2001 From: Robert Förster Date: Tue, 16 Sep 2008 11:43:31 +0000 Subject: pop in some EOL and svn properties fixes. - all textfiles were converted to unix line endings - svn:eol-style native has been set on that files so noone has to care about it again, now the svn client does take care of that, a checkout on unix will get unix lineendings, a checkout on windows will get windows lineendings - svn:executable fixup (some file had the executable bit set were they shouldn't) - svn:mime-type fixes for most of the files, which will probaly only affect trac in viewing that files - some typo fixup, the manpage seems to need some love, though. this will be pushed to the branches once i get to it today. git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@2469 17fca916-40b9-46aa-a4ea-0a15b648b75c --- src/modules/objects/class_buttongroup.cpp | 2 +- src/modules/objects/class_buttongroup.h | 82 +- src/modules/objects/class_ftp.h | 14 +- src/modules/objects/class_http.cpp | 298 +- src/modules/objects/class_listviewitem.cpp | 46 +- src/modules/objects/class_painter.cpp | 3288 +++++++++++----------- src/modules/objects/class_painter.h | 250 +- src/modules/objects/class_pixmap.cpp | 12 +- src/modules/objects/class_popupmenu.cpp | 788 +++--- src/modules/objects/class_widget.cpp | 3988 +++++++++++++-------------- src/modules/objects/class_widget.h | 282 +- src/modules/objects/objects.vcproj | 2564 ++++++++--------- src/modules/objects/objects_QT4_vc05.vcproj | 2550 ++++++++--------- 13 files changed, 7082 insertions(+), 7082 deletions(-) mode change 100755 => 100644 src/modules/objects/objects.vcproj (limited to 'src/modules/objects') diff --git a/src/modules/objects/class_buttongroup.cpp b/src/modules/objects/class_buttongroup.cpp index 54891838c..64021f65e 100644 --- a/src/modules/objects/class_buttongroup.cpp +++ b/src/modules/objects/class_buttongroup.cpp @@ -94,7 +94,7 @@ bool KviKvsObject_buttongroup::functionAddButton(KviKvsObjectFunctionCall *c) c->warning(__tr2qs("Can't add a non-widget object")); return true; } - if(pObject->inherits("KviKvsObject_radiobutton") || pObject->inherits("KviKvsObject_checkbox")){ + if(pObject->inherits("KviKvsObject_radiobutton") || pObject->inherits("KviKvsObject_checkbox")){ m_pButtonGroup->addButton(((QRadioButton *)(pObject->object())),m_iId); c->returnValue()->setInteger(m_iId); btnDict.insert(m_iId,pObject); diff --git a/src/modules/objects/class_buttongroup.h b/src/modules/objects/class_buttongroup.h index 49c3b2dfb..9322965a9 100644 --- a/src/modules/objects/class_buttongroup.h +++ b/src/modules/objects/class_buttongroup.h @@ -1,44 +1,44 @@ -#ifndef _CLASS_BUTTONGROUP_H_ -#define _CLASS_BUTTONGROUP_H_ -// -// File : class_buttongroup.h -// Creation date : Jan 23 CEST 2007 -// by Alessandro Carbone(Noldor) -// -// This file is part of the KVirc irc client distribution -// Copyright (C) 1999-2005 Szymon Stefanek (pragma at kvirc dot net) -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// - - - -#include -#include "object_macros.h" - -class KviKvsObject_buttongroup : public KviKvsObject -{ -public: - KVSO_DECLARE_OBJECT(KviKvsObject_buttongroup) -protected: - QButtonGroup *m_pButtonGroup; - int m_iId; - KviPointerHashTable btnDict; +#ifndef _CLASS_BUTTONGROUP_H_ +#define _CLASS_BUTTONGROUP_H_ +// +// File : class_buttongroup.h +// Creation date : Jan 23 CEST 2007 +// by Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2005 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// + + + +#include +#include "object_macros.h" + +class KviKvsObject_buttongroup : public KviKvsObject +{ +public: + KVSO_DECLARE_OBJECT(KviKvsObject_buttongroup) +protected: + QButtonGroup *m_pButtonGroup; + int m_iId; + KviPointerHashTable btnDict; bool functionAddButton(KviKvsObjectFunctionCall *c); bool functionCheckedButton(KviKvsObjectFunctionCall *c); -}; -#endif //!_CLASS_GROUPBOX_H_ - +}; +#endif //!_CLASS_GROUPBOX_H_ + diff --git a/src/modules/objects/class_ftp.h b/src/modules/objects/class_ftp.h index 465c18987..8a9c80bf0 100644 --- a/src/modules/objects/class_ftp.h +++ b/src/modules/objects/class_ftp.h @@ -51,13 +51,13 @@ protected: bool functionAbort(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 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/class_http.cpp b/src/modules/objects/class_http.cpp index 5978cef1d..6bbd8f1b1 100644 --- a/src/modules/objects/class_http.cpp +++ b/src/modules/objects/class_http.cpp @@ -26,35 +26,35 @@ #include "class_http.h" #include #include -#ifndef QT_NO_OPENSSL +#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", + "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" }; @@ -118,7 +118,7 @@ KVSO_BEGIN_REGISTERCLASS(KviKvsObject_http,"http","object") KVSO_REGISTER_HANDLER(KviKvsObject_http,"errorString",functionErrorString) KVSO_REGISTER_HANDLER(KviKvsObject_http,"setFollowRedirect",functionFollowRedirect) - #ifndef QT_NO_OPENSSL + #ifndef QT_NO_OPENSSL KVSO_REGISTER_HANDLER(KviKvsObject_http,"ignoreSSlErrors",functionIgnoreSslErrors) #endif // events @@ -130,7 +130,7 @@ KVSO_BEGIN_REGISTERCLASS(KviKvsObject_http,"http","object") KVSO_REGISTER_HANDLER(KviKvsObject_http,"dataSendProgressEvent",functionDataSendProgressEvent) KVSO_REGISTER_HANDLER(KviKvsObject_http,"stateChangedEvent",functionStateChangedEvent) KVSO_REGISTER_HANDLER(KviKvsObject_http,"readyReadEvent",functionReadyReadEvent) - #ifndef QT_NO_OPENSSL + #ifndef QT_NO_OPENSSL KVSO_REGISTER_HANDLER(KviKvsObject_http,"sslErrorsEvent",functionSslErrorsEvent) #endif @@ -157,19 +157,19 @@ KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_http,KviKvsObject) KVSO_END_CONSTRUCTOR(KviKvsObject_http) KVSO_BEGIN_DESTRUCTOR(KviKvsObject_http) - QHashIterator t(getDict); -/* - - while (t.hasNext()) - { - t.next(); - int key=t.key(); - QFile *pFile=getDict.value(key); - pFile->close(); - delete pFile; - } -*/ - delete m_pHttp; + QHashIterator t(getDict); +/* + + while (t.hasNext()) + { + t.next(); + int key=t.key(); + QFile *pFile=getDict.value(key); + pFile->close(); + delete pFile; + } +*/ + delete m_pHttp; getDict.clear(); KVSO_END_DESTRUCTOR(KviKvsObject_http) @@ -311,159 +311,159 @@ bool KviKvsObject_http::functionRequestFinishedEvent(KviKvsObjectFunctionCall *c return true; } -void KviKvsObject_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 ((m_pHttp->lastResponse().statusCode()==301 || m_pHttp->lastResponse().statusCode()==302 || m_pHttp->lastResponse().statusCode()==307) && m_bEnableForceRedirect) - redirect(name,m_pHttp->lastResponse()); - delete pFile; - } - callFunction(this,"requestFinishedEvent",0,new KviKvsVariantList(new KviKvsVariant((kvs_int_t) id),new KviKvsVariant(error))); - -} - +void KviKvsObject_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 ((m_pHttp->lastResponse().statusCode()==301 || m_pHttp->lastResponse().statusCode()==302 || m_pHttp->lastResponse().statusCode()==307) && m_bEnableForceRedirect) + redirect(name,m_pHttp->lastResponse()); + delete pFile; + } + callFunction(this,"requestFinishedEvent",0,new KviKvsVariantList(new KviKvsVariant((kvs_int_t) id),new KviKvsVariant(error))); + +} + bool KviKvsObject_http::functionRequestStartedEvent(KviKvsObjectFunctionCall *c) { emitSignal("requestStarted",c,c->params()); return true; -} -void KviKvsObject_http::slotRequestStarted ( int id ) -{ - callFunction(this,"requestStartedEvent",0,new KviKvsVariantList(new KviKvsVariant((kvs_int_t) id))); -} - -void KviKvsObject_http::slotDataReadProgress ( int done,int total ) -{ +} +void KviKvsObject_http::slotRequestStarted ( int id ) +{ + callFunction(this,"requestStartedEvent",0,new KviKvsVariantList(new KviKvsVariant((kvs_int_t) id))); +} + +void KviKvsObject_http::slotDataReadProgress ( int done,int total ) +{ callFunction(this,"dataReadProgressEvent",0,new KviKvsVariantList( - new KviKvsVariant((kvs_int_t)done),new KviKvsVariant((kvs_int_t)total))); -} + new KviKvsVariant((kvs_int_t)done),new KviKvsVariant((kvs_int_t)total))); +} bool KviKvsObject_http::functionDataReadProgressEvent(KviKvsObjectFunctionCall *c) { emitSignal("dataReadProgress",c,c->params()); return true; -} -void KviKvsObject_http::slotDataSendProgress ( int done,int total ) -{ +} +void KviKvsObject_http::slotDataSendProgress ( int done,int total ) +{ callFunction(this,"dataSendProgressEvent",0,new KviKvsVariantList( - new KviKvsVariant((kvs_int_t)done),new KviKvsVariant((kvs_int_t)total))); -} + new KviKvsVariant((kvs_int_t)done),new KviKvsVariant((kvs_int_t)total))); +} bool KviKvsObject_http::functionDataSendProgressEvent(KviKvsObjectFunctionCall *c) { emitSignal("dataSendProgress",c,c->params()); return true; -} -bool KviKvsObject_http::functionDoneEvent(KviKvsObjectFunctionCall *c) -{ +} +bool KviKvsObject_http::functionDoneEvent(KviKvsObjectFunctionCall *c) +{ emitSignal("done",c,c->params()); return true; -} -void KviKvsObject_http::slotDone ( bool error ) -{ - callFunction(this,"doneEvent",0,new KviKvsVariantList(new KviKvsVariant(error))); - -} - +} +void KviKvsObject_http::slotDone ( bool error ) +{ + callFunction(this,"doneEvent",0,new KviKvsVariantList(new KviKvsVariant(error))); + +} + bool KviKvsObject_http::functionResponseHeaderReceivedEvent(KviKvsObjectFunctionCall *c) { emitSignal("responseHeaderReceived",c,c->params()); return true; -} +} bool KviKvsObject_http::functionReadyReadEvent(KviKvsObjectFunctionCall *c) { emitSignal("readyRead",c,c->params()); return true; -} -void KviKvsObject_http::redirect(QString &file,const QHttpResponseHeader &r) -{ - QUrl url(r.value("location")); - m_pHttp->setHost(url.host()); +} +void KviKvsObject_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; - debug("exit redirect"); -} - + debug("exit redirect"); +} + void KviKvsObject_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; + 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; } callFunction(this,"responseHeaderReceivedEvent",0,new KviKvsVariantList( - new KviKvsVariant(szResponse))); - -} + new KviKvsVariant(szResponse))); + +} void KviKvsObject_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; + 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; } callFunction(this,"readyReadEvent",0,new KviKvsVariantList( - new KviKvsVariant(szResponse))); -} - - - - -void KviKvsObject_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"; + new KviKvsVariant(szResponse))); +} + + + + +void KviKvsObject_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"; callFunction(this,"stateChangedEvent",0,new KviKvsVariantList( - new KviKvsVariant(szState))); -} + new KviKvsVariant(szState))); +} bool KviKvsObject_http::functionStateChangedEvent(KviKvsObjectFunctionCall *c) { emitSignal("stateChanged",c,c->params()); return true; -} - -#ifndef QT_NO_OPENSSL +} + +#ifndef QT_NO_OPENSSL bool KviKvsObject_http::functionIgnoreSslErrors(KviKvsObjectFunctionCall *c) { @@ -478,16 +478,16 @@ void KviKvsObject_http::slotSslErrors(QList sslerrors) { pArray->set(i,new KviKvsVariant(ssl_errors_tbl[sslerrors.at(i).error()])); } - callFunction(this,"sslErrorsEvent",0,new KviKvsVariantList(new KviKvsVariant(pArray))); -} - + callFunction(this,"sslErrorsEvent",0,new KviKvsVariantList(new KviKvsVariant(pArray))); +} + bool KviKvsObject_http::functionSslErrorsEvent(KviKvsObjectFunctionCall *c) { emitSignal("sslErrors",c,c->params()); return true; -} -#endif +} +#endif #ifndef COMPILE_USE_STANDALONE_MOC_SOURCES #include "m_class_http.moc" #endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/class_listviewitem.cpp b/src/modules/objects/class_listviewitem.cpp index e9eacd56c..62adaf37c 100644 --- a/src/modules/objects/class_listviewitem.cpp +++ b/src/modules/objects/class_listviewitem.cpp @@ -27,28 +27,28 @@ #include "kvi_locale.h" #include "kvi_iconmanager.h" -const int item_flags[] = { - Qt::ItemIsSelectable, - Qt::ItemIsEditable, - Qt::ItemIsDragEnabled, - Qt::ItemIsDropEnabled, - Qt::ItemIsUserCheckable, - Qt::ItemIsEnabled, - Qt::ItemIsTristate -}; - -const char * const itemflags_tbl[] = { - "selectable", - "editable", - "dragEnabled", - "dropEnabled", - "userCheckable", - "enabled", - "tristate" -}; - -#define itemflags_num (sizeof(itemflags_tbl) / sizeof(itemflags_tbl[0])) - +const int item_flags[] = { + Qt::ItemIsSelectable, + Qt::ItemIsEditable, + Qt::ItemIsDragEnabled, + Qt::ItemIsDropEnabled, + Qt::ItemIsUserCheckable, + Qt::ItemIsEnabled, + Qt::ItemIsTristate +}; + +const char * const itemflags_tbl[] = { + "selectable", + "editable", + "dragEnabled", + "dropEnabled", + "userCheckable", + "enabled", + "tristate" +}; + +#define itemflags_num (sizeof(itemflags_tbl) / sizeof(itemflags_tbl[0])) + /* @@ -296,7 +296,7 @@ bool KviKvsObject_treewidgetitem::function_setFlags(KviKvsObjectFunctionCall *c) } } if(flag){ - if (flag==Qt::ItemIsUserCheckable) + if (flag==Qt::ItemIsUserCheckable) m_pListViewItem->setCheckState(0,Qt::Unchecked); sum = sum | flag; } diff --git a/src/modules/objects/class_painter.cpp b/src/modules/objects/class_painter.cpp index 48a078831..b3b1b196d 100644 --- a/src/modules/objects/class_painter.cpp +++ b/src/modules/objects/class_painter.cpp @@ -1,1647 +1,1647 @@ -//mdm: -// Painter : class_painter.cpp -// Creation date : Fri Mar 18 14:30:48 CEST 2005 -// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) -// Lucia Papini (^ashura^) English Translation. -// This file is part of the KVirc irc client distribution -// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net) -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// - -#include "class_painter.h" -#include "class_pixmap.h" -#include "class_widget.h" - -#include "kvi_debug.h" -#include "kvi_locale.h" -#include "kvi_error.h" -#include "kvi_iconmanager.h" -#include "kvi_malloc.h" - -#include -#include - -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: $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: $drawWinFocusRect(,,,) - Draws a Windows focus rectangle with upper left corner at (x, y) and with width w and height h.[br] - This function draws nothing if the coordinate system has been rotated or sheared. - !fn: $drawRoundRect(,,,,,) - Draws a rectangle with rounded corners at (x, y), with width w and height h.[rb] - The xCor and yCor arguments specify how rounded the corners should be (range is 0->99). - !fn: $drawPie(,,,,,) - Draws a pie defined by the rectangle (x, y, w, h), the start angle a and the arc length alen.[br] - The angles and are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). - !fn: $drawArc(,,,,,) - Draws an arc defined by the rectangle (x, y, w, h), the start angle a and the arc length alen.[br] - The angles and are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). - !fn: $drawPoint(,) - Draws a point at x and y coordinates. - !fn: $drawEllipse(,,,) - Draws an ellipse with center at (x + w/2, y + h/2) and size (w, h). - !fn: $drawChord(,,,,,) - Draws a chord defined by the rectangle (x, y, w, h), the start angle a and the arc length alen.[br] - The angles and are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). - !fn: $drawText(,,,[,]) - Draws the given at position , .[br] - If is -1 (the default) all the text is drawn, otherwise the first characters are drawn. - The text's direction is given by , valid flag are:[br] - [pre] - Auto [br] - RTL (right to left) [br] - LTR (left to right) [br] - [/pre] - !fn: $drawPixmap(,,,,,,) - Draws a pixmap at x,y coordinates[br] - !fn: $setFont(,,)[br] - Set the font's size, family and stile, valid flag for style are:[br] - [pre] - italic [br] - bold [br] - underline [br] - overline [br] - strikeout [br] - fixedpitch [br] - [/pre] - !fn: $setFontSize()[br] - Set the current painter font's size.[br] - !fn: $fontAscent() - Return the distance from the baseline to the highest position characters extend to. - !fn: $fontDescent() - Return the distance from the baseline to the lowest point characters extend to. - !fn: $fontMetricsWidth() - Returns the font metrics width for the painter's current font. - !fn: $fontMetricsHeight() - Returns the font metrics height for the painter's current font. - !fn: $rotate() - Rotates the coordinate system a degrees counterclockwise. - !fn: $translate(,) - Translates the coordinate system by , . - !fn: $shear(,) - Shears the coordinate system by , . - !fn: $scale(,) - Scales the coordinate system by , . - !fn: $setBackgroundMode() - Sets the background mode of the painter to : valid values are:[br] - - Transparent (that is the default value);[br] - - Opaque.[br] - !fn: $setOpacity() [QT4 ONLY] - Sets the painter opacity that affects all painter operations (drawpixmap, drawtext...). Valid values range are from 0 (total transparency) to 1 (total opacity)[br] - You must invoke the [classfnc]$begin[/classfnc] before using it. - !fn: $setTextAntialiasing() [QT4 ONLY] - Enable/disable antialias in text if possible. - You must call the [classfnc]$begin[/classfnc] before using it. - !fn: $setAntialiasing() [QT4 ONLY] - Enable/disable antialias in edges of primitives if possible. - You must call the [classfnc]$begin[/classfnc] before using it. - !fn: $setSmoothPixmapTransform() [QT4 ONLY] - Enable/disable smooth bilinear pixmap transformation algorithm (such as bilinear). - You must call the [classfnc]$begin[/classfnc] before using it. - Example:[br] - [br] - class (hello,widget)[br] - {[br] - constructor()[br] - {[br] - $$->%sintbl[]= $array( 0, 38, 71, 92, 100, 92, 71, 38,0, -38, -71, -92, -100, -92, -71, -38);[br] - $$->%index=0[br] - $$->$starttimer( 30 );[br] - $$->$resize(800,600 );[br] - $$->%string=$0[br] - $$->%waitfor=1;[br] - $$->%nextanim=0[br] - [br] - #zoom and rotation anim[br] - $$->%Zoomindex=11[br] - $$->%degree=0[br] - $$->%Noanim=0[br] - $$->%scrollright=-450[br] - [br] - #anim effect init[br] - $$->%xoffset=4[br] - $$->%yoffset=3[br] - $$->%xstart=270[br] - $$->%ystart=200[br] - $$->%b=0[br] - $$->%yoffs=400[br] - [br] - #parallax parameter[br] - $$->%Off=400[br] - $$->%roll=1[br] - }[br] - timerevent()[br] - {[br] - $$->%b = $(($$->%b + 1) & 15);[br] - if ($$->%nextanim == 1) $$->$repaint(1);[br] - $$->$repaint(0);[br] - }[br] - drawAnim()[br] - {[br] - %P->$setFont(32,"times",bold);[br] - %w=$(%P->$fontMetricsWidth($$->%string[$$->%index]) + 20);[br] - %h=$(%P->$fontMetricsHeight * 2);[br] - %pmx = $(($$->$width/2) -%w/2);[br] - %pmy = $(($$->$height()/2) - %h/2);[br] - %x = 10;[br] - %y= $((%h/2) + $$->$fontDescent());[br] - %i=0[br] - while ( $str.mid("Grifisx/Noldor",%i,1) != "") [br] - {[br] - %i16 = $(($$->%b+%i) & 15);[br] - %char=$str.mid("Grifisx/Noldor",%i,1)[br] - %P->$setPen($((15-%i16)*16),$((15-%i16)*16),$((15-%i16)*16) );[br] - %P->$drawText( $(%x+$$->%xstart),$($$->%ystart+%y-$$->%sintbl[%i16]*%h/800),%char,1,Auto);[br] - %x += %P->$fontMetricsWidth(%char);[br] - %i++;[br] - }[br] - }[br] - matrixeffect()[br] - {[br] - if (($$->%Zoomindex == 99) && ($$->%degree==360)) return %P->$drawPixmap($(400-32),$(300-32),"kvirc.png",0,0,-1,-1)[br] - %P->$scale(0.$$->%Zoomindex,0.$$->%Zoomindex)[br] - if ($$->%Zoomindex != 99) $$->%Zoomindex++;[br] - %P->$rotate($$->%degree)[br] - %P->$translate(400,300)[br] - %P->$drawPixmap(-32,-32,"kvirc.png",0,0,-1,-1)[br] - %P->$setFont(28,"times",bold);[br] - %P->$reset()[br] - if ($$->%scrollright >= 550) return[br] - %P->$scale(0.$$->%Zoomindex,0.$$->%Zoomindex)[br] - %P->$translate(400,350)[br] - %P->$drawText($$->%scrollright,10,"Another cool class brought to you by...",-1,Auto) [br] - $$->%scrollright += 3;[br] - %P->$reset()[br] - }[br] - nextanim()[br] - {[br] - %p=$new(painter)[br] - %p->$setBackgroundMode(Opaque)[br] - %p->$setBrush($rand(255),$rand(255),$rand(255))[br] - %p->$begin($$)[br] - %rand=$rand(5)[br] - %p->$drawrect($rand(800),$rand(400),120,200)[br] - %p->$drawArc($rand(800),$rand(400),120,200,20,$(16*20))[br] - %p->$drawPie($rand(800),$rand(400),120,200,20,$(16*20))[br] - %p->$drawChord($rand(800),$rand(400),120,200,20,$(16*20))[br] - %p->$drawEllipse($rand(800),$rand(400),100,30)[br] - %p->$end()[br] - delete %p[br] - }[br] - paintEvent()[br] - {[br] - if ($$->%nextanim ==1) return $$->$nextanim()[br] - # pixmap creation: every effect will be painted on it then copied on widget[br] - %pixmap=$new(pixmap)[br] - %pixmap->$resize($$->$width(),$$->$height())[br] - [br] - # painter creation [br] - %P=$new(painter);[br] - %P->$begin(%pixmap);[br] - $$->$drawanim[br] - $$->$matrixeffect[br] - %i=0[br] - while (%i != 100)[br] - {[br] - %i16 = $(($$->%b+%i) & 15);[br] - %P->$setPen($((15-%i16)*16),$((15-%i16)*16),$((15-%i16)*16) );[br] - %P->$drawpoint($rand(800),$rand(600))[br] - %i++[br] - }[br] - [br] - # sets the animations order to manage the parallax effect[br] - %P->$end[br] - objects.bitBlt $$ 0 0 %pixmap[br] - delete %pixmap[br] - delete %P[br] - if (%Pauseflag == 1) return[br] - [br] - # manage the animations parameters[br] - if (($$->%Off<=60) && ($$->%roll<182)) $$->%roll += 2;[br] - if ($$->%roll>182) $$->%waitfor=0[br] - if ($$->%Noanim != 1) $$->%degree += 16;[br] - if ($$->%degree >= 360)[br] - {[br] - $$->%degree=0;[br] - if ($$->%Zoomindex == 99) $$->%Noanim=1[br] - } [br] - if ($$->%Noanim != 1) return[br] - [br] - #sinusoid animation[br] - if (($$->%xstart <1) && ($$->%xoffset == -4)) $$->%xoffset=4;[br] - if (($$->%xstart >$($$->$width()-%P->$fontMetricsWidth("Grifisx/Noldor"))) && ($$->%xoffset == 4)) $$->%xoffset=-4;[br] - if (($$->%ystart <1) && ($$->%yoffset == -3)) $$->%yoffset=3;[br] - if (($$->%ystart >$($$->$height()-60)) && ($$->%yoffset == 3)) $$->%yoffset=-3;[br] - $$->%xstart += $$->%xoffset;[br] - $$->%ystart += $$->%yoffset;[br] - }[br] - }[br] - [br] - %Hello=$new(hello)[br] - %Hello->$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(KviKvsObject_painter,"painter","object") - - // Fonts - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setFont",functionSetFont) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setFontSize",functionSetFontSize) - - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setBrush",functionsetBrush) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setPen",functionsetPen) - - - - - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setPenStyle",functionsetPenStyle) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setBrushStyle",functionsetBrushStyle) - - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"fontAscent",functionfontAscent) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"fontDescent",functionfontDescent) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"fontMetricsHeight",functionfontMetricsHeight) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"fontMetricsWidth",functionfontMetricsWidth) - // Draws - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setBackGroundMode",functionsetBackGroundMode) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawRect",functiondrawRect) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawLine",functiondrawLine) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawRoundRect",functiondrawRoundRect) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawWinFocusRect",functiondrawWinFocusRect) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawPoint",functiondrawPoint) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawArc",functiondrawArc) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawEllipse",functiondrawEllipse) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawPie",functiondrawPie) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawChord",functiondrawChord) - - - // Text & Pixmap - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawText",functiondrawText) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawPixmap",functiondrawPixmap) - - - // MAtrix Operation - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"rotate",functionrotateMatrix) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"shear",functionshearMatrix) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"scale",functionscaleMatrix) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"translate",functiontranslateMatrix) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"reset",functionresetMatrix) - - // painter state - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"save",functionsave) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"restore",functionrestore) - - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"beginPdf",functionBeginPdf)// FIXME: needs doc! -//bool KviKvsObject_painter::functionBeginPdf(KviKvsObjectFunctionCall *c) -//QT4 - - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setOpacity",functionsetOpacity) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setTextAntialiasing",functionsetTextAntialiasing) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setAntialiasing",functionsetAntialiasing) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setSmoothPixmapTransform",functionsetSmoothPixmapTransform) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setGradientStart",functionsetGradientStart) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setGradientFinalStop",functionsetGradientStop) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setGradientColor",functionsetGradientColor) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setGradientAsBrush",functionsetGradientAsBrush) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"clearGradient",functionclearGradient) - - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setPenWidth",functionsetPenWidth) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawIcon",functiondrawIcon) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawHtmlText",functiondrawHtmlText) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"htmlTextSize",functionhtmlTextSize) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"fillRect",functionfillRect) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"colorNames",functioncolorNames) - - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawPath",functiondrawPath) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"resetPath",functionresetPath) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"pathAddText",functionpathAddText) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"pathMoveTo",functionpathMoveTo) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"pathLineTo",functionpathLineTo) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setPenJoinStyle",functionsetPenJoinStyle) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setPenCapStyle",functionsetPenCapStyle) - - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"painterDeviceWidth",functionwidth) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"painterDeviceHeight",functionheight) - -// - - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"begin",functionbegin) - KVSO_REGISTER_HANDLER(KviKvsObject_painter,"end",functionend) - - -KVSO_END_REGISTERCLASS(KviKvsObject_painter) - - -KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_painter,KviKvsObject) - - m_pPainter = new QPainter(); - m_pPrinter = 0 ; - m_pDeviceObject=0; - m_pPainterPath=0; - m_pGradient=0; - -KVSO_END_CONSTRUCTOR(KviKvsObject_painter) - -KVSO_BEGIN_DESTRUCTOR(KviKvsObject_painter) - -if (m_pPainterPath) delete m_pPainterPath; - m_pPainterPath=0; -if (m_pGradient) delete m_pGradient; - m_pGradient=0; -if (m_pPainter) delete m_pPainter; - m_pPainter = 0; -if (m_pPrinter) delete m_pPrinter; - m_pPrinter = 0; - -KVSO_END_CONSTRUCTOR(KviKvsObject_painter) - -#define KVSO_PARAMETERS_PAINTER(__pXOrArray,__iY,__iW,__iH)\ -if(__pXOrArray->isArray())\ - {\ - if(__pXOrArray->array()->size() < 4)\ - {\ - c->error(__tr2qs("The array passed as parameter must contain at least 4 elements"));\ - return false;\ - }\ - KviKvsVariant * pX = __pXOrArray->array()->at(0);\ - KviKvsVariant * pY = __pXOrArray->array()->at(1);\ - KviKvsVariant * pW = __pXOrArray->array()->at(2);\ - KviKvsVariant * pH = __pXOrArray->array()->at(3);\ - if(!(pX && pY && pW && pH))\ - {\ - c->error(__tr2qs("One of the geometry array parameters is empty"));\ - return false;\ - }\ - if(!(pX->asInteger(iX) && pY->asInteger(__iY) && pW->asInteger(__iW) && pH->asInteger(__iH)))\ - {\ - c->error(__tr2qs("One of the geometry array parameters didn't evaluate to an integer"));\ - return false;\ - }\ - } else {\ - if(c->params()->count() < 4)\ - {\ - QString error=function+__tr2qs(" requires either an array as first parameter or four integers");\ - c->error(error);\ - return false;\ - }\ - if(!__pXOrArray->asInteger(iX))\ - {\ - c->error(__tr2qs("The first parameter didn't evaluate to an array nor an integer"));\ - return false;\ - }\ - }\ - -#define KVSO_2ARRAYPARAMETERS(__pXOrArray,__iY)\ -if(__pXOrArray->isArray())\ - {\ - if(__pXOrArray->array()->size() < 2)\ - {\ - c->error(__tr2qs("The array passed as parameter must contain at least 2 elements"));\ - return false;\ - }\ - KviKvsVariant * pX = __pXOrArray->array()->at(0);\ - KviKvsVariant * pY = __pXOrArray->array()->at(1);\ - if(!(pX && pY ))\ - {\ - c->error(__tr2qs("One of the array parameters is empty"));\ - return false;\ - }\ - if(!(pX->asInteger(iX) && pY->asInteger(__iY)))\ - {\ - c->error(__tr2qs("One of the array parameters didn't evaluate to an integer"));\ - return false;\ - }\ - } else {\ - if(c->params()->count() < 2)\ - {\ - QString error=function+__tr2qs(" requires either an array as first parameter or two integers");\ - c->error(error);\ - return false;\ - }\ - if(!__pXOrArray->asInteger(iX))\ - {\ - c->error(__tr2qs("The first parameter didn't evaluate to an array nor an integer"));\ - return false;\ - }\ - }\ - -#define KVSO_3OR4ARRAYPARAMETERS(__pCol1OrArray,__iCol2,__iCol3,__iOpacity)\ -if(__pCol1OrArray->isArray())\ - {\ - if(__pCol1OrArray->array()->size() < 3)\ - {\ - c->error(__tr2qs("The array passed as parameter must contain at least 3 elements"));\ - return false;\ - }\ - KviKvsVariant * c1 = __pCol1OrArray->array()->at(0);\ - KviKvsVariant * c2 = __pCol1OrArray->array()->at(1);\ - KviKvsVariant * c3 = __pCol1OrArray->array()->at(2);\ - if(!(c1 && c2 && c3))\ - {\ - c->error(__tr2qs("One of the array parameters is empty"));\ - return false;\ - }\ - if(!(c1->asInteger(iCol1) && c2->asInteger(__iCol2) && c3->asInteger(__iCol3)))\ - {\ - c->error(__tr2qs("One of the array parameters didn't evaluate to an integer"));\ - return false;\ - }\ - if(__pCol1OrArray->array()->size() > 3)\ - {\ - KviKvsVariant * c4 = __pCol1OrArray->array()->at(3);\ - if(!(c4->asInteger(__iOpacity)))\ - {\ - c->error(__tr2qs("The opacity value didn't evaluate to an integer"));\ - return false;\ - }\ - }\ - } else {\ - if(c->params()->count() < 3)\ - {\ - QString error=function+__tr2qs(" requires either an array as first parameter or 3 integers");\ - c->error(error);\ - return false;\ - }\ - if(!__pCol1OrArray->asInteger(iCol1))\ - {\ - c->error(__tr2qs("The first parameter didn't evaluate to an array nor an integer"));\ - return false;\ - }\ - }\ - -bool KviKvsObject_painter::functionSetFont(KviKvsObjectFunctionCall *c) -{ - QString szFamily,szStyle; - kvs_int_t uSize; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("size",KVS_PT_UNSIGNEDINTEGER,0,uSize) - KVSO_PARAMETER("family",KVS_PT_STRING,0,szFamily) - KVSO_PARAMETER("style",KVS_PT_STRING,0,szStyle) - KVSO_PARAMETERS_END(c) - if(!m_pPainter)return true; - QFont font=m_pPainter->font(); - font.setFamily(szFamily); - font.setPointSize(uSize); - if(KviQString::equalCI(szStyle,"italic")) font.setItalic(TRUE); - if(KviQString::equalCI(szStyle,"bold")) font.setBold(TRUE); - if(KviQString::equalCI(szStyle,"underline"))font.setUnderline(TRUE); - if(KviQString::equalCI(szStyle,"overline")) font.setOverline(TRUE); - if(KviQString::equalCI(szStyle,"strikeout"))font.setStrikeOut(TRUE); - if(KviQString::equalCI(szStyle,"fixedpitch")) font.setFixedPitch(TRUE); - m_pPainter->setFont(font); - return true; -} - -bool KviKvsObject_painter::functionSetFontSize(KviKvsObjectFunctionCall *c) -{ - kvs_uint_t uSize; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("size",KVS_PT_UNSIGNEDINTEGER,0,uSize) - KVSO_PARAMETERS_END(c) - if(!m_pPainter)return true; - QFont font=m_pPainter->font(); - font.setPointSize(uSize); - m_pPainter->setFont(font); - return true; -} - -bool KviKvsObject_painter::functionsetBackGroundMode(KviKvsObjectFunctionCall *c) -{ - QString szMode; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("background mode",KVS_PT_STRING,0,szMode) - KVSO_PARAMETERS_END(c) - if(!m_pPainter)return true; - if(KviQString::equalCI(szMode,"Transparent")) m_pPainter->setBackgroundMode(Qt::TransparentMode); - else if(KviQString::equalCI(szMode,"Opaque")) m_pPainter->setBackgroundMode(Qt::OpaqueMode); - else c->warning( __tr2qs("Unknown orientation")); - return true; -} - -bool KviKvsObject_painter::functiondrawLine(KviKvsObjectFunctionCall *c) -{ - KviKvsVariant * pXOrArray; - kvs_int_t iX,iY,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; -} - -bool KviKvsObject_painter::functiondrawRect(KviKvsObjectFunctionCall *c) -{ - KviKvsVariant * pXOrArray; - kvs_int_t iX,iY,iW,iH; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) - KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) - KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) - KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) - KVSO_PARAMETERS_END(c) - QString function="$drawRect"; - KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) - if(m_pPainter) m_pPainter->drawRect(iX,iY,iW,iH); - return true; -} -//FIXME: REMOVE functiondrawWinFocusRect -bool KviKvsObject_painter::functiondrawWinFocusRect(KviKvsObjectFunctionCall *c) -{ - KviKvsVariant * pXOrArray; - kvs_int_t iX,iY,iW,iH; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) - KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) - KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) - KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) - KVSO_PARAMETERS_END(c) - QString function="$drawWinFocusRect"; - KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) - - return true; -} - -bool KviKvsObject_painter::functiondrawEllipse(KviKvsObjectFunctionCall *c) -{ - KviKvsVariant * pXOrArray; - kvs_int_t iX,iY,iW,iH; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) - KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) - KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) - KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) - KVSO_PARAMETERS_END(c) - QString function="$drawEllipse"; - KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) - if(m_pPainter) m_pPainter->drawEllipse(iX,iY,iW,iH); - return true; -} - -bool KviKvsObject_painter::functiondrawRoundRect(KviKvsObjectFunctionCall *c) -{ - KviKvsVariant * pXOrArray; - kvs_int_t iXrnd,iYrnd,iX,iY,iW,iH; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("x_round",KVS_PT_INT,0,iXrnd) - KVSO_PARAMETER("y_round",KVS_PT_INT,0,iYrnd) - KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) - KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) - KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) - KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) - KVSO_PARAMETERS_END(c) - QString function="$drawRoundRect"; - KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) - if(m_pPainter) - m_pPainter->drawRoundRect(iX,iY,iW,iH,iXrnd,iYrnd); - return true; -} - -bool KviKvsObject_painter::functiondrawArc(KviKvsObjectFunctionCall *c) -{ - KviKvsVariant * pXOrArray; - kvs_int_t iSangle,iLena,iX,iY,iW,iH; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("start_angle",KVS_PT_INT,0,iSangle) - KVSO_PARAMETER("a_lenght",KVS_PT_INT,0,iLena) - KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) - KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) - KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) - KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) - KVSO_PARAMETERS_END(c) - QString function="$drawArc"; - KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) - if(m_pPainter) - m_pPainter->drawArc(iX,iY,iW,iH,iSangle,iLena); - return true; -} - -bool KviKvsObject_painter::functiondrawChord(KviKvsObjectFunctionCall *c) -{ - KviKvsVariant * pXOrArray; - kvs_int_t iSangle,iLena,iX,iY,iW,iH; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("start_angle",KVS_PT_INT,0,iSangle) - KVSO_PARAMETER("a_lenght",KVS_PT_INT,0,iLena) - KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) - KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) - KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) - KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) - KVSO_PARAMETERS_END(c) - QString function="$drawChord"; - KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) - if(m_pPainter) - m_pPainter->drawChord(iX,iY,iW,iH,iSangle,iLena); - return true; -} - -bool KviKvsObject_painter::functionsetBrush(KviKvsObjectFunctionCall *c) -{ - 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(!m_pPainter) return true; - - if(var1->isHObject()) - { - kvs_hobject_t hObj; - var1->asHObject(hObj); - KviKvsObject *pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObj); - if (!pObject) - { - c->warning(__tr2qs("Pixmap parameter is not an object!")); - return true; - } - if(pObject->inherits("KviKvsObject_pixmap")) - m_pPainter->setBrush(*((KviKvsObject_pixmap *)pObject)->getPixmap()); - else c->warning(__tr2qs("Object Pixmap required!")); - return true; - } - if (!var1->asInteger(iCol1)) - { - var1->asString(szColor); - if (c->paramCount()<2) iOpacity=255; - else - { - if (!var2->asInteger(iOpacity)) - { - c->warning("The opacity parameter didn't evaluate to integer"); - return true; - } - } - QColor col(szColor); - col.setAlpha(iOpacity); - m_pPainter->setBrush(col); - } - else - { - if(c->paramCount()<3) - { - c->error(__tr2qs("Color name or triplette rgb/hsv value required")); - return true; - } - if (!var2->asInteger(iCol2)||!var3->asInteger(iCol3)) - { - c->error(__tr2qs("One of the triplette parameters didn't evaluate to an integer"));\ - 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; -} - -bool KviKvsObject_painter::functionsetPen(KviKvsObjectFunctionCall *c) -{ - 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(!m_pPainter) return true; - - if (!var1->asInteger(iCol1)) - { - var1->asString(szColor); - if (c->paramCount()<2) iOpacity=255; - else - { - if (!var2->asInteger(iOpacity)) - { - c->warning("The opacity parameter didn't evaluate to integer"); - return true; - } - } - QColor col(szColor); - col.setAlpha(iOpacity); - m_pPainter->setPen(col); - } - else - { - if(c->paramCount()<3) - { - c->error(__tr2qs("Color name or triplette rgb/hsv value required")); - return true; - } - if (!var2->asInteger(iCol2)||!var3->asInteger(iCol3)) - { - c->error(__tr2qs("One of the triplette parameters didn't evaluate to an integer"));\ - 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; -} - -bool KviKvsObject_painter::functiondrawPie(KviKvsObjectFunctionCall *c) -{ - KviKvsVariant * pXOrArray; - kvs_int_t iSangle,iLena,iX,iY,iW,iH; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("start_angle",KVS_PT_INT,0,iSangle) - KVSO_PARAMETER("a_lenght",KVS_PT_INT,0,iLena) - KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) - KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) - KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) - KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) - KVSO_PARAMETERS_END(c) - QString function="$drawPie"; - KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) - if(m_pPainter) - m_pPainter->drawPie(iX,iY,iW,iH,iSangle,iLena); - return true; -} - -bool KviKvsObject_painter::functiondrawPoint(KviKvsObjectFunctionCall *c) -{ - KviKvsVariant * pXOrArray; - kvs_int_t iX,iY; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) - KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) - KVSO_PARAMETERS_END(c) - QString function="$drawPoint"; - KVSO_2ARRAYPARAMETERS(pXOrArray,iY) - if(m_pPainter) - m_pPainter->drawPoint(iX,iY); - return true; -} - -bool KviKvsObject_painter::functionfontDescent(KviKvsObjectFunctionCall * c) -{ - if(m_pPainter) - c->returnValue()->setInteger(m_pPainter->fontMetrics().descent()); - return true; -} - -bool KviKvsObject_painter::functionfontAscent(KviKvsObjectFunctionCall * c) -{ - if(m_pPainter) - c->returnValue()->setInteger(m_pPainter->fontMetrics().ascent()); - return true; - -} - -bool KviKvsObject_painter::functionfontMetricsWidth(KviKvsObjectFunctionCall * c) -{ - QString szText; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) - KVSO_PARAMETERS_END(c) - if(m_pPainter) - { - if (m_pPainter->isActive()) - c->returnValue()->setInteger(m_pPainter->fontMetrics().width(szText)); - else c->warning("$fontMetricsWidth: the painter is not active!"); - } - return true; -} - -bool KviKvsObject_painter::functionfontMetricsHeight(KviKvsObjectFunctionCall * c) -{ - if(m_pPainter) - { - if (m_pPainter->isActive()) - c->returnValue()->setInteger(m_pPainter->fontMetrics().height()); - else c->warning("$fontMetricsHeight: the painter is not active!"); - } - return true; -} - -bool KviKvsObject_painter::functionbegin(KviKvsObjectFunctionCall *c) -{ - KviKvsObject * pObject; - kvs_hobject_t hObject; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("paint_device",KVS_PT_HOBJECT,0,hObject) - KVSO_PARAMETERS_END(c) - pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); - if(!m_pPainter)return true; - if (!pObject) - { - c->warning(__tr2qs("Pixmap or Widget parameter is not an object")); - return true; - } - QPaintDevice * pd; - if(pObject->inherits("KviKvsObject_pixmap"))pd=((KviKvsObject_pixmap *)pObject)->getPixmap(); - - else if (pObject->inherits("KviKvsObject_widget")) pd=((KviKvsObject_widget *)pObject)->widget(); - else{ - c->warning(__tr2qs("Widget or Pixmap required ")); - return true; - } - attachDevice(pObject,pd); - if (pObject->inherits("KviKvsObject_pixmap")) ((KviKvsObject_pixmap *)pObject)->pixmapChanged(); - return true; -} - -void KviKvsObject_painter::attachDevice(KviKvsObject * o,QPaintDevice * p) -{ - if(!m_pPainter)return; - if(m_pDeviceObject)detachDevice(); - m_pDeviceObject = o; - // KviKvsObject_pixmap and KviKvsObject_widget object have this signal - // it is emitted BEFORE the real QPaintDevice is deleted, so we can eventually - // call m_pPainter->end() in time - - QObject::connect(m_pDeviceObject,SIGNAL(aboutToDie()),this,SLOT(detachDevice())); - m_pPainter->begin(p); -} - -void KviKvsObject_painter::detachDevice() -{ - if(!m_pDeviceObject)return; - if(!m_pPainter)return; - disconnect(m_pDeviceObject,SIGNAL(aboutToDie()),this,SLOT(detachDevice())); - m_pPainter->end(); - m_pDeviceObject = 0; -} - -bool KviKvsObject_painter::functionend(KviKvsObjectFunctionCall *c) -{ - detachDevice(); - return true; -} -bool KviKvsObject_painter::functionBeginPdf(KviKvsObjectFunctionCall *c) -{ +//mdm: +// Painter : class_painter.cpp +// Creation date : Fri Mar 18 14:30:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// Lucia Papini (^ashura^) English Translation. +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// + +#include "class_painter.h" +#include "class_pixmap.h" +#include "class_widget.h" + +#include "kvi_debug.h" +#include "kvi_locale.h" +#include "kvi_error.h" +#include "kvi_iconmanager.h" +#include "kvi_malloc.h" + +#include +#include + +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: $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: $drawWinFocusRect(,,,) + Draws a Windows focus rectangle with upper left corner at (x, y) and with width w and height h.[br] + This function draws nothing if the coordinate system has been rotated or sheared. + !fn: $drawRoundRect(,,,,,) + Draws a rectangle with rounded corners at (x, y), with width w and height h.[rb] + The xCor and yCor arguments specify how rounded the corners should be (range is 0->99). + !fn: $drawPie(,,,,,) + Draws a pie defined by the rectangle (x, y, w, h), the start angle a and the arc length alen.[br] + The angles and are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). + !fn: $drawArc(,,,,,) + Draws an arc defined by the rectangle (x, y, w, h), the start angle a and the arc length alen.[br] + The angles and are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). + !fn: $drawPoint(,) + Draws a point at x and y coordinates. + !fn: $drawEllipse(,,,) + Draws an ellipse with center at (x + w/2, y + h/2) and size (w, h). + !fn: $drawChord(,,,,,) + Draws a chord defined by the rectangle (x, y, w, h), the start angle a and the arc length alen.[br] + The angles and are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). + !fn: $drawText(,,,[,]) + Draws the given at position , .[br] + If is -1 (the default) all the text is drawn, otherwise the first characters are drawn. + The text's direction is given by , valid flag are:[br] + [pre] + Auto [br] + RTL (right to left) [br] + LTR (left to right) [br] + [/pre] + !fn: $drawPixmap(,,,,,,) + Draws a pixmap at x,y coordinates[br] + !fn: $setFont(,,)[br] + Set the font's size, family and stile, valid flag for style are:[br] + [pre] + italic [br] + bold [br] + underline [br] + overline [br] + strikeout [br] + fixedpitch [br] + [/pre] + !fn: $setFontSize()[br] + Set the current painter font's size.[br] + !fn: $fontAscent() + Return the distance from the baseline to the highest position characters extend to. + !fn: $fontDescent() + Return the distance from the baseline to the lowest point characters extend to. + !fn: $fontMetricsWidth() + Returns the font metrics width for the painter's current font. + !fn: $fontMetricsHeight() + Returns the font metrics height for the painter's current font. + !fn: $rotate() + Rotates the coordinate system a degrees counterclockwise. + !fn: $translate(,) + Translates the coordinate system by , . + !fn: $shear(,) + Shears the coordinate system by , . + !fn: $scale(,) + Scales the coordinate system by , . + !fn: $setBackgroundMode() + Sets the background mode of the painter to : valid values are:[br] + - Transparent (that is the default value);[br] + - Opaque.[br] + !fn: $setOpacity() [QT4 ONLY] + Sets the painter opacity that affects all painter operations (drawpixmap, drawtext...). Valid values range are from 0 (total transparency) to 1 (total opacity)[br] + You must invoke the [classfnc]$begin[/classfnc] before using it. + !fn: $setTextAntialiasing() [QT4 ONLY] + Enable/disable antialias in text if possible. + You must call the [classfnc]$begin[/classfnc] before using it. + !fn: $setAntialiasing() [QT4 ONLY] + Enable/disable antialias in edges of primitives if possible. + You must call the [classfnc]$begin[/classfnc] before using it. + !fn: $setSmoothPixmapTransform() [QT4 ONLY] + Enable/disable smooth bilinear pixmap transformation algorithm (such as bilinear). + You must call the [classfnc]$begin[/classfnc] before using it. + Example:[br] + [br] + class (hello,widget)[br] + {[br] + constructor()[br] + {[br] + $$->%sintbl[]= $array( 0, 38, 71, 92, 100, 92, 71, 38,0, -38, -71, -92, -100, -92, -71, -38);[br] + $$->%index=0[br] + $$->$starttimer( 30 );[br] + $$->$resize(800,600 );[br] + $$->%string=$0[br] + $$->%waitfor=1;[br] + $$->%nextanim=0[br] + [br] + #zoom and rotation anim[br] + $$->%Zoomindex=11[br] + $$->%degree=0[br] + $$->%Noanim=0[br] + $$->%scrollright=-450[br] + [br] + #anim effect init[br] + $$->%xoffset=4[br] + $$->%yoffset=3[br] + $$->%xstart=270[br] + $$->%ystart=200[br] + $$->%b=0[br] + $$->%yoffs=400[br] + [br] + #parallax parameter[br] + $$->%Off=400[br] + $$->%roll=1[br] + }[br] + timerevent()[br] + {[br] + $$->%b = $(($$->%b + 1) & 15);[br] + if ($$->%nextanim == 1) $$->$repaint(1);[br] + $$->$repaint(0);[br] + }[br] + drawAnim()[br] + {[br] + %P->$setFont(32,"times",bold);[br] + %w=$(%P->$fontMetricsWidth($$->%string[$$->%index]) + 20);[br] + %h=$(%P->$fontMetricsHeight * 2);[br] + %pmx = $(($$->$width/2) -%w/2);[br] + %pmy = $(($$->$height()/2) - %h/2);[br] + %x = 10;[br] + %y= $((%h/2) + $$->$fontDescent());[br] + %i=0[br] + while ( $str.mid("Grifisx/Noldor",%i,1) != "") [br] + {[br] + %i16 = $(($$->%b+%i) & 15);[br] + %char=$str.mid("Grifisx/Noldor",%i,1)[br] + %P->$setPen($((15-%i16)*16),$((15-%i16)*16),$((15-%i16)*16) );[br] + %P->$drawText( $(%x+$$->%xstart),$($$->%ystart+%y-$$->%sintbl[%i16]*%h/800),%char,1,Auto);[br] + %x += %P->$fontMetricsWidth(%char);[br] + %i++;[br] + }[br] + }[br] + matrixeffect()[br] + {[br] + if (($$->%Zoomindex == 99) && ($$->%degree==360)) return %P->$drawPixmap($(400-32),$(300-32),"kvirc.png",0,0,-1,-1)[br] + %P->$scale(0.$$->%Zoomindex,0.$$->%Zoomindex)[br] + if ($$->%Zoomindex != 99) $$->%Zoomindex++;[br] + %P->$rotate($$->%degree)[br] + %P->$translate(400,300)[br] + %P->$drawPixmap(-32,-32,"kvirc.png",0,0,-1,-1)[br] + %P->$setFont(28,"times",bold);[br] + %P->$reset()[br] + if ($$->%scrollright >= 550) return[br] + %P->$scale(0.$$->%Zoomindex,0.$$->%Zoomindex)[br] + %P->$translate(400,350)[br] + %P->$drawText($$->%scrollright,10,"Another cool class brought to you by...",-1,Auto) [br] + $$->%scrollright += 3;[br] + %P->$reset()[br] + }[br] + nextanim()[br] + {[br] + %p=$new(painter)[br] + %p->$setBackgroundMode(Opaque)[br] + %p->$setBrush($rand(255),$rand(255),$rand(255))[br] + %p->$begin($$)[br] + %rand=$rand(5)[br] + %p->$drawrect($rand(800),$rand(400),120,200)[br] + %p->$drawArc($rand(800),$rand(400),120,200,20,$(16*20))[br] + %p->$drawPie($rand(800),$rand(400),120,200,20,$(16*20))[br] + %p->$drawChord($rand(800),$rand(400),120,200,20,$(16*20))[br] + %p->$drawEllipse($rand(800),$rand(400),100,30)[br] + %p->$end()[br] + delete %p[br] + }[br] + paintEvent()[br] + {[br] + if ($$->%nextanim ==1) return $$->$nextanim()[br] + # pixmap creation: every effect will be painted on it then copied on widget[br] + %pixmap=$new(pixmap)[br] + %pixmap->$resize($$->$width(),$$->$height())[br] + [br] + # painter creation [br] + %P=$new(painter);[br] + %P->$begin(%pixmap);[br] + $$->$drawanim[br] + $$->$matrixeffect[br] + %i=0[br] + while (%i != 100)[br] + {[br] + %i16 = $(($$->%b+%i) & 15);[br] + %P->$setPen($((15-%i16)*16),$((15-%i16)*16),$((15-%i16)*16) );[br] + %P->$drawpoint($rand(800),$rand(600))[br] + %i++[br] + }[br] + [br] + # sets the animations order to manage the parallax effect[br] + %P->$end[br] + objects.bitBlt $$ 0 0 %pixmap[br] + delete %pixmap[br] + delete %P[br] + if (%Pauseflag == 1) return[br] + [br] + # manage the animations parameters[br] + if (($$->%Off<=60) && ($$->%roll<182)) $$->%roll += 2;[br] + if ($$->%roll>182) $$->%waitfor=0[br] + if ($$->%Noanim != 1) $$->%degree += 16;[br] + if ($$->%degree >= 360)[br] + {[br] + $$->%degree=0;[br] + if ($$->%Zoomindex == 99) $$->%Noanim=1[br] + } [br] + if ($$->%Noanim != 1) return[br] + [br] + #sinusoid animation[br] + if (($$->%xstart <1) && ($$->%xoffset == -4)) $$->%xoffset=4;[br] + if (($$->%xstart >$($$->$width()-%P->$fontMetricsWidth("Grifisx/Noldor"))) && ($$->%xoffset == 4)) $$->%xoffset=-4;[br] + if (($$->%ystart <1) && ($$->%yoffset == -3)) $$->%yoffset=3;[br] + if (($$->%ystart >$($$->$height()-60)) && ($$->%yoffset == 3)) $$->%yoffset=-3;[br] + $$->%xstart += $$->%xoffset;[br] + $$->%ystart += $$->%yoffset;[br] + }[br] + }[br] + [br] + %Hello=$new(hello)[br] + %Hello->$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(KviKvsObject_painter,"painter","object") + + // Fonts + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setFont",functionSetFont) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setFontSize",functionSetFontSize) + + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setBrush",functionsetBrush) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setPen",functionsetPen) + + + + + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setPenStyle",functionsetPenStyle) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setBrushStyle",functionsetBrushStyle) + + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"fontAscent",functionfontAscent) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"fontDescent",functionfontDescent) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"fontMetricsHeight",functionfontMetricsHeight) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"fontMetricsWidth",functionfontMetricsWidth) + // Draws + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setBackGroundMode",functionsetBackGroundMode) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawRect",functiondrawRect) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawLine",functiondrawLine) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawRoundRect",functiondrawRoundRect) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawWinFocusRect",functiondrawWinFocusRect) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawPoint",functiondrawPoint) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawArc",functiondrawArc) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawEllipse",functiondrawEllipse) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawPie",functiondrawPie) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawChord",functiondrawChord) + + + // Text & Pixmap + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawText",functiondrawText) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawPixmap",functiondrawPixmap) + + + // MAtrix Operation + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"rotate",functionrotateMatrix) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"shear",functionshearMatrix) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"scale",functionscaleMatrix) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"translate",functiontranslateMatrix) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"reset",functionresetMatrix) + + // painter state + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"save",functionsave) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"restore",functionrestore) + + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"beginPdf",functionBeginPdf)// FIXME: needs doc! +//bool KviKvsObject_painter::functionBeginPdf(KviKvsObjectFunctionCall *c) +//QT4 + + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setOpacity",functionsetOpacity) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setTextAntialiasing",functionsetTextAntialiasing) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setAntialiasing",functionsetAntialiasing) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setSmoothPixmapTransform",functionsetSmoothPixmapTransform) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setGradientStart",functionsetGradientStart) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setGradientFinalStop",functionsetGradientStop) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setGradientColor",functionsetGradientColor) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setGradientAsBrush",functionsetGradientAsBrush) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"clearGradient",functionclearGradient) + + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setPenWidth",functionsetPenWidth) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawIcon",functiondrawIcon) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawHtmlText",functiondrawHtmlText) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"htmlTextSize",functionhtmlTextSize) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"fillRect",functionfillRect) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"colorNames",functioncolorNames) + + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"drawPath",functiondrawPath) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"resetPath",functionresetPath) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"pathAddText",functionpathAddText) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"pathMoveTo",functionpathMoveTo) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"pathLineTo",functionpathLineTo) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setPenJoinStyle",functionsetPenJoinStyle) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"setPenCapStyle",functionsetPenCapStyle) + + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"painterDeviceWidth",functionwidth) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"painterDeviceHeight",functionheight) + +// + + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"begin",functionbegin) + KVSO_REGISTER_HANDLER(KviKvsObject_painter,"end",functionend) + + +KVSO_END_REGISTERCLASS(KviKvsObject_painter) + + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_painter,KviKvsObject) + + m_pPainter = new QPainter(); + m_pPrinter = 0 ; + m_pDeviceObject=0; + m_pPainterPath=0; + m_pGradient=0; + +KVSO_END_CONSTRUCTOR(KviKvsObject_painter) + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_painter) + +if (m_pPainterPath) delete m_pPainterPath; + m_pPainterPath=0; +if (m_pGradient) delete m_pGradient; + m_pGradient=0; +if (m_pPainter) delete m_pPainter; + m_pPainter = 0; +if (m_pPrinter) delete m_pPrinter; + m_pPrinter = 0; + +KVSO_END_CONSTRUCTOR(KviKvsObject_painter) + +#define KVSO_PARAMETERS_PAINTER(__pXOrArray,__iY,__iW,__iH)\ +if(__pXOrArray->isArray())\ + {\ + if(__pXOrArray->array()->size() < 4)\ + {\ + c->error(__tr2qs("The array passed as parameter must contain at least 4 elements"));\ + return false;\ + }\ + KviKvsVariant * pX = __pXOrArray->array()->at(0);\ + KviKvsVariant * pY = __pXOrArray->array()->at(1);\ + KviKvsVariant * pW = __pXOrArray->array()->at(2);\ + KviKvsVariant * pH = __pXOrArray->array()->at(3);\ + if(!(pX && pY && pW && pH))\ + {\ + c->error(__tr2qs("One of the geometry array parameters is empty"));\ + return false;\ + }\ + if(!(pX->asInteger(iX) && pY->asInteger(__iY) && pW->asInteger(__iW) && pH->asInteger(__iH)))\ + {\ + c->error(__tr2qs("One of the geometry array parameters didn't evaluate to an integer"));\ + return false;\ + }\ + } else {\ + if(c->params()->count() < 4)\ + {\ + QString error=function+__tr2qs(" requires either an array as first parameter or four integers");\ + c->error(error);\ + return false;\ + }\ + if(!__pXOrArray->asInteger(iX))\ + {\ + c->error(__tr2qs("The first parameter didn't evaluate to an array nor an integer"));\ + return false;\ + }\ + }\ + +#define KVSO_2ARRAYPARAMETERS(__pXOrArray,__iY)\ +if(__pXOrArray->isArray())\ + {\ + if(__pXOrArray->array()->size() < 2)\ + {\ + c->error(__tr2qs("The array passed as parameter must contain at least 2 elements"));\ + return false;\ + }\ + KviKvsVariant * pX = __pXOrArray->array()->at(0);\ + KviKvsVariant * pY = __pXOrArray->array()->at(1);\ + if(!(pX && pY ))\ + {\ + c->error(__tr2qs("One of the array parameters is empty"));\ + return false;\ + }\ + if(!(pX->asInteger(iX) && pY->asInteger(__iY)))\ + {\ + c->error(__tr2qs("One of the array parameters didn't evaluate to an integer"));\ + return false;\ + }\ + } else {\ + if(c->params()->count() < 2)\ + {\ + QString error=function+__tr2qs(" requires either an array as first parameter or two integers");\ + c->error(error);\ + return false;\ + }\ + if(!__pXOrArray->asInteger(iX))\ + {\ + c->error(__tr2qs("The first parameter didn't evaluate to an array nor an integer"));\ + return false;\ + }\ + }\ + +#define KVSO_3OR4ARRAYPARAMETERS(__pCol1OrArray,__iCol2,__iCol3,__iOpacity)\ +if(__pCol1OrArray->isArray())\ + {\ + if(__pCol1OrArray->array()->size() < 3)\ + {\ + c->error(__tr2qs("The array passed as parameter must contain at least 3 elements"));\ + return false;\ + }\ + KviKvsVariant * c1 = __pCol1OrArray->array()->at(0);\ + KviKvsVariant * c2 = __pCol1OrArray->array()->at(1);\ + KviKvsVariant * c3 = __pCol1OrArray->array()->at(2);\ + if(!(c1 && c2 && c3))\ + {\ + c->error(__tr2qs("One of the array parameters is empty"));\ + return false;\ + }\ + if(!(c1->asInteger(iCol1) && c2->asInteger(__iCol2) && c3->asInteger(__iCol3)))\ + {\ + c->error(__tr2qs("One of the array parameters didn't evaluate to an integer"));\ + return false;\ + }\ + if(__pCol1OrArray->array()->size() > 3)\ + {\ + KviKvsVariant * c4 = __pCol1OrArray->array()->at(3);\ + if(!(c4->asInteger(__iOpacity)))\ + {\ + c->error(__tr2qs("The opacity value didn't evaluate to an integer"));\ + return false;\ + }\ + }\ + } else {\ + if(c->params()->count() < 3)\ + {\ + QString error=function+__tr2qs(" requires either an array as first parameter or 3 integers");\ + c->error(error);\ + return false;\ + }\ + if(!__pCol1OrArray->asInteger(iCol1))\ + {\ + c->error(__tr2qs("The first parameter didn't evaluate to an array nor an integer"));\ + return false;\ + }\ + }\ + +bool KviKvsObject_painter::functionSetFont(KviKvsObjectFunctionCall *c) +{ + QString szFamily,szStyle; + kvs_int_t uSize; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("size",KVS_PT_UNSIGNEDINTEGER,0,uSize) + KVSO_PARAMETER("family",KVS_PT_STRING,0,szFamily) + KVSO_PARAMETER("style",KVS_PT_STRING,0,szStyle) + KVSO_PARAMETERS_END(c) + if(!m_pPainter)return true; + QFont font=m_pPainter->font(); + font.setFamily(szFamily); + font.setPointSize(uSize); + if(KviQString::equalCI(szStyle,"italic")) font.setItalic(TRUE); + if(KviQString::equalCI(szStyle,"bold")) font.setBold(TRUE); + if(KviQString::equalCI(szStyle,"underline"))font.setUnderline(TRUE); + if(KviQString::equalCI(szStyle,"overline")) font.setOverline(TRUE); + if(KviQString::equalCI(szStyle,"strikeout"))font.setStrikeOut(TRUE); + if(KviQString::equalCI(szStyle,"fixedpitch")) font.setFixedPitch(TRUE); + m_pPainter->setFont(font); + return true; +} + +bool KviKvsObject_painter::functionSetFontSize(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uSize; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("size",KVS_PT_UNSIGNEDINTEGER,0,uSize) + KVSO_PARAMETERS_END(c) + if(!m_pPainter)return true; + QFont font=m_pPainter->font(); + font.setPointSize(uSize); + m_pPainter->setFont(font); + return true; +} + +bool KviKvsObject_painter::functionsetBackGroundMode(KviKvsObjectFunctionCall *c) +{ + QString szMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("background mode",KVS_PT_STRING,0,szMode) + KVSO_PARAMETERS_END(c) + if(!m_pPainter)return true; + if(KviQString::equalCI(szMode,"Transparent")) m_pPainter->setBackgroundMode(Qt::TransparentMode); + else if(KviQString::equalCI(szMode,"Opaque")) m_pPainter->setBackgroundMode(Qt::OpaqueMode); + else c->warning( __tr2qs("Unknown orientation")); + return true; +} + +bool KviKvsObject_painter::functiondrawLine(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iX,iY,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; +} + +bool KviKvsObject_painter::functiondrawRect(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iX,iY,iW,iH; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) + KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) + KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) + KVSO_PARAMETERS_END(c) + QString function="$drawRect"; + KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) + if(m_pPainter) m_pPainter->drawRect(iX,iY,iW,iH); + return true; +} +//FIXME: REMOVE functiondrawWinFocusRect +bool KviKvsObject_painter::functiondrawWinFocusRect(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iX,iY,iW,iH; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) + KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) + KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) + KVSO_PARAMETERS_END(c) + QString function="$drawWinFocusRect"; + KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) + + return true; +} + +bool KviKvsObject_painter::functiondrawEllipse(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iX,iY,iW,iH; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) + KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) + KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) + KVSO_PARAMETERS_END(c) + QString function="$drawEllipse"; + KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) + if(m_pPainter) m_pPainter->drawEllipse(iX,iY,iW,iH); + return true; +} + +bool KviKvsObject_painter::functiondrawRoundRect(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iXrnd,iYrnd,iX,iY,iW,iH; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x_round",KVS_PT_INT,0,iXrnd) + KVSO_PARAMETER("y_round",KVS_PT_INT,0,iYrnd) + KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) + KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) + KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) + KVSO_PARAMETERS_END(c) + QString function="$drawRoundRect"; + KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) + if(m_pPainter) + m_pPainter->drawRoundRect(iX,iY,iW,iH,iXrnd,iYrnd); + return true; +} + +bool KviKvsObject_painter::functiondrawArc(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iSangle,iLena,iX,iY,iW,iH; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("start_angle",KVS_PT_INT,0,iSangle) + KVSO_PARAMETER("a_lenght",KVS_PT_INT,0,iLena) + KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) + KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) + KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) + KVSO_PARAMETERS_END(c) + QString function="$drawArc"; + KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) + if(m_pPainter) + m_pPainter->drawArc(iX,iY,iW,iH,iSangle,iLena); + return true; +} + +bool KviKvsObject_painter::functiondrawChord(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iSangle,iLena,iX,iY,iW,iH; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("start_angle",KVS_PT_INT,0,iSangle) + KVSO_PARAMETER("a_lenght",KVS_PT_INT,0,iLena) + KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) + KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) + KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) + KVSO_PARAMETERS_END(c) + QString function="$drawChord"; + KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) + if(m_pPainter) + m_pPainter->drawChord(iX,iY,iW,iH,iSangle,iLena); + return true; +} + +bool KviKvsObject_painter::functionsetBrush(KviKvsObjectFunctionCall *c) +{ + 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(!m_pPainter) return true; + + if(var1->isHObject()) + { + kvs_hobject_t hObj; + var1->asHObject(hObj); + KviKvsObject *pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObj); + if (!pObject) + { + c->warning(__tr2qs("Pixmap parameter is not an object!")); + return true; + } + if(pObject->inherits("KviKvsObject_pixmap")) + m_pPainter->setBrush(*((KviKvsObject_pixmap *)pObject)->getPixmap()); + else c->warning(__tr2qs("Object Pixmap required!")); + return true; + } + if (!var1->asInteger(iCol1)) + { + var1->asString(szColor); + if (c->paramCount()<2) iOpacity=255; + else + { + if (!var2->asInteger(iOpacity)) + { + c->warning("The opacity parameter didn't evaluate to integer"); + return true; + } + } + QColor col(szColor); + col.setAlpha(iOpacity); + m_pPainter->setBrush(col); + } + else + { + if(c->paramCount()<3) + { + c->error(__tr2qs("Color name or triplette rgb/hsv value required")); + return true; + } + if (!var2->asInteger(iCol2)||!var3->asInteger(iCol3)) + { + c->error(__tr2qs("One of the triplette parameters didn't evaluate to an integer"));\ + 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; +} + +bool KviKvsObject_painter::functionsetPen(KviKvsObjectFunctionCall *c) +{ + 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(!m_pPainter) return true; + + if (!var1->asInteger(iCol1)) + { + var1->asString(szColor); + if (c->paramCount()<2) iOpacity=255; + else + { + if (!var2->asInteger(iOpacity)) + { + c->warning("The opacity parameter didn't evaluate to integer"); + return true; + } + } + QColor col(szColor); + col.setAlpha(iOpacity); + m_pPainter->setPen(col); + } + else + { + if(c->paramCount()<3) + { + c->error(__tr2qs("Color name or triplette rgb/hsv value required")); + return true; + } + if (!var2->asInteger(iCol2)||!var3->asInteger(iCol3)) + { + c->error(__tr2qs("One of the triplette parameters didn't evaluate to an integer"));\ + 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; +} + +bool KviKvsObject_painter::functiondrawPie(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iSangle,iLena,iX,iY,iW,iH; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("start_angle",KVS_PT_INT,0,iSangle) + KVSO_PARAMETER("a_lenght",KVS_PT_INT,0,iLena) + KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) + KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) + KVSO_PARAMETER("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) + KVSO_PARAMETERS_END(c) + QString function="$drawPie"; + KVSO_PARAMETERS_PAINTER(pXOrArray,iY,iW,iH) + if(m_pPainter) + m_pPainter->drawPie(iX,iY,iW,iH,iSangle,iLena); + return true; +} + +bool KviKvsObject_painter::functiondrawPoint(KviKvsObjectFunctionCall *c) +{ + KviKvsVariant * pXOrArray; + kvs_int_t iX,iY; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("x_or_array",KVS_PT_VARIANT,0,pXOrArray) + KVSO_PARAMETER("y",KVS_PT_INT,KVS_PF_OPTIONAL,iY) + KVSO_PARAMETERS_END(c) + QString function="$drawPoint"; + KVSO_2ARRAYPARAMETERS(pXOrArray,iY) + if(m_pPainter) + m_pPainter->drawPoint(iX,iY); + return true; +} + +bool KviKvsObject_painter::functionfontDescent(KviKvsObjectFunctionCall * c) +{ + if(m_pPainter) + c->returnValue()->setInteger(m_pPainter->fontMetrics().descent()); + return true; +} + +bool KviKvsObject_painter::functionfontAscent(KviKvsObjectFunctionCall * c) +{ + if(m_pPainter) + c->returnValue()->setInteger(m_pPainter->fontMetrics().ascent()); + return true; + +} + +bool KviKvsObject_painter::functionfontMetricsWidth(KviKvsObjectFunctionCall * c) +{ + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if(m_pPainter) + { + if (m_pPainter->isActive()) + c->returnValue()->setInteger(m_pPainter->fontMetrics().width(szText)); + else c->warning("$fontMetricsWidth: the painter is not active!"); + } + return true; +} + +bool KviKvsObject_painter::functionfontMetricsHeight(KviKvsObjectFunctionCall * c) +{ + if(m_pPainter) + { + if (m_pPainter->isActive()) + c->returnValue()->setInteger(m_pPainter->fontMetrics().height()); + else c->warning("$fontMetricsHeight: the painter is not active!"); + } + return true; +} + +bool KviKvsObject_painter::functionbegin(KviKvsObjectFunctionCall *c) +{ + KviKvsObject * pObject; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("paint_device",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if(!m_pPainter)return true; + if (!pObject) + { + c->warning(__tr2qs("Pixmap or Widget parameter is not an object")); + return true; + } + QPaintDevice * pd; + if(pObject->inherits("KviKvsObject_pixmap"))pd=((KviKvsObject_pixmap *)pObject)->getPixmap(); + + else if (pObject->inherits("KviKvsObject_widget")) pd=((KviKvsObject_widget *)pObject)->widget(); + else{ + c->warning(__tr2qs("Widget or Pixmap required ")); + return true; + } + attachDevice(pObject,pd); + if (pObject->inherits("KviKvsObject_pixmap")) ((KviKvsObject_pixmap *)pObject)->pixmapChanged(); + return true; +} + +void KviKvsObject_painter::attachDevice(KviKvsObject * o,QPaintDevice * p) +{ + if(!m_pPainter)return; + if(m_pDeviceObject)detachDevice(); + m_pDeviceObject = o; + // KviKvsObject_pixmap and KviKvsObject_widget object have this signal + // it is emitted BEFORE the real QPaintDevice is deleted, so we can eventually + // call m_pPainter->end() in time + + QObject::connect(m_pDeviceObject,SIGNAL(aboutToDie()),this,SLOT(detachDevice())); + m_pPainter->begin(p); +} + +void KviKvsObject_painter::detachDevice() +{ + if(!m_pDeviceObject)return; + if(!m_pPainter)return; + disconnect(m_pDeviceObject,SIGNAL(aboutToDie()),this,SLOT(detachDevice())); + m_pPainter->end(); + m_pDeviceObject = 0; +} + +bool KviKvsObject_painter::functionend(KviKvsObjectFunctionCall *c) +{ + detachDevice(); + return true; +} +bool KviKvsObject_painter::functionBeginPdf(KviKvsObjectFunctionCall *c) +{ 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; -} -bool KviKvsObject_painter::functiondrawText(KviKvsObjectFunctionCall *c) -{ - QString szText,szMode; - kvs_int_t iX,iY; - 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("mode",KVS_PT_STRING,KVS_PF_OPTIONAL,szMode) - KVSO_PARAMETERS_END(c) - if(!m_pPainter)return true; - if (!szMode.isEmpty()){ - if(KviQString::equalCI(szMode,"RTL"))m_pPainter->setLayoutDirection(Qt::RightToLeft); - else if(KviQString::equalCI(szMode,"LTR"))m_pPainter->setLayoutDirection(Qt::LeftToRight); - else - { - c->warning(__tr2qs("Invalid mode '%Q'"),&szMode); - return true; - } - } - m_pPainter->drawText(iX,iY,szText); - return true; -} - -bool KviKvsObject_painter::functiondrawPixmap(KviKvsObjectFunctionCall *c) -{ - 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(!m_pPainter)return true; - if (!obj) - { - c->warning(__tr2qs("Pixmap parameter is not an object")); - return true; - } - if (!obj->inherits("KviKvsObject_pixmap")) - { - c->warning(__tr2qs("Pixmap object required")); - return true; - } - QPixmap * pm=((KviKvsObject_pixmap *)obj)->getPixmap(); - //if (bTiled) m_pPainter->drawTiledPixmap(iX,iY,iEndx,iEndy,*((KviKvsObject_pixmap *)obj)->getPixmap(),iStartx,iStarty); - //else - m_pPainter->drawPixmap(QPointF(iX,iY),*((KviKvsObject_pixmap *)obj)->getPixmap(),QRect(iStartx,iStarty,iEndx,iEndy)); - return true; -} - -bool KviKvsObject_painter::functionrotateMatrix(KviKvsObjectFunctionCall *c) -{ - kvs_real_t dAngle; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("angle",KVS_PT_DOUBLE,0,dAngle) - KVSO_PARAMETERS_END(c) - if(!m_pPainter)return true; - //m_pMatrix.rotate(dAngle); - //m_pPainter->setWorldMatrix( m_pMatrix,false ); - m_pPainter->rotate(dAngle); - return true; -} - -bool KviKvsObject_painter::functiontranslateMatrix(KviKvsObjectFunctionCall *c) -{ - kvs_real_t dXtrasl,dYtrasl; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("trasl_x",KVS_PT_DOUBLE,0,dXtrasl) - KVSO_PARAMETER("trasl_y",KVS_PT_DOUBLE,0,dYtrasl) - KVSO_PARAMETERS_END(c) - if(!m_pPainter)return true; - //QWMatrix tmpMatrix; - //tmpMatrix.translate(dXtrasl,dYtrasl); - //tmpMatrix = m_pMatrix * tmpMatrix; - //m_pPainter->setWorldMatrix( tmpMatrix ); - //m_pMatrix=tmpMatrix; - m_pPainter->translate(dXtrasl,dYtrasl); - return true; -} - -bool KviKvsObject_painter::functionshearMatrix(KviKvsObjectFunctionCall *c) -{ - kvs_real_t dShearh,dShearv; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("shear_h",KVS_PT_DOUBLE,0,dShearh) - KVSO_PARAMETER("shear_v",KVS_PT_DOUBLE,0,dShearv) - KVSO_PARAMETERS_END(c) - if(!m_pPainter)return true; - //m_pMatrix.shear(dShearh,dShearv); - //m_pPainter->setWorldMatrix(m_pMatrix); - m_pPainter->shear(dShearh,dShearv); - return true; -} - -bool KviKvsObject_painter::functionscaleMatrix(KviKvsObjectFunctionCall *c) -{ - kvs_real_t dScalex,dScaley; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("scale_x",KVS_PT_DOUBLE,0,dScalex) - KVSO_PARAMETER("scale_y",KVS_PT_DOUBLE,0,dScaley) - KVSO_PARAMETERS_END(c) - if(!m_pPainter)return true; - //m_pMatrix.scale(dScalex,dScaley); - //m_pPainter->setWorldMatrix(m_pMatrix); - m_pPainter->scale(dScalex,dScaley); - return true; -} - -bool KviKvsObject_painter::functionresetMatrix(KviKvsObjectFunctionCall *c) -{ - if(!m_pPainter)return true; - //m_pMatrix.reset(); - //m_pPainter->setWorldMatrix( m_pMatrix ); - m_pPainter->resetMatrix(); - return true; -} - -bool KviKvsObject_painter::functiondrawHtmlText(KviKvsObjectFunctionCall *c) -{ - 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) - if(!m_pPainter)return true; - 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; -} - -bool KviKvsObject_painter::functionhtmlTextSize(KviKvsObjectFunctionCall *c) -{ - 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; -} - -bool KviKvsObject_painter::functiondrawIcon(KviKvsObjectFunctionCall *c) -{ - 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("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) - KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) - - KVSO_PARAMETER("state",KVS_PT_STRING,KVS_PF_OPTIONAL,szState) - KVSO_PARAMETERS_END(c) - if (!m_pPainter) return true; - 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; -} - -bool KviKvsObject_painter::functionsetOpacity(KviKvsObjectFunctionCall *c) -{ - if(!m_pPainter)return true; - kvs_real_t dOpacity; - - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("opacity_factor",KVS_PT_DOUBLE,0,dOpacity) - KVSO_PARAMETERS_END(c) - m_pPainter->setOpacity(dOpacity); - return true; -} - -bool KviKvsObject_painter::functionsetTextAntialiasing(KviKvsObjectFunctionCall *c) -{ - if(!m_pPainter)return true; - - bool bEnabled; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) - KVSO_PARAMETERS_END(c) - m_pPainter->setRenderHint(QPainter::TextAntialiasing,bEnabled); - return true; -} - -bool KviKvsObject_painter::functionsetAntialiasing(KviKvsObjectFunctionCall *c) -{ - if(!m_pPainter)return true; - - bool bEnabled; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) - KVSO_PARAMETERS_END(c) - m_pPainter->setRenderHint(QPainter::Antialiasing,bEnabled); - return true; -} - -bool KviKvsObject_painter::functionsetSmoothPixmapTransform(KviKvsObjectFunctionCall *c) -{ - if(!m_pPainter)return true; - - bool bEnabled; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) - KVSO_PARAMETERS_END(c) - m_pPainter->setRenderHint(QPainter::SmoothPixmapTransform,bEnabled); - return true; -} - -bool KviKvsObject_painter::functionsetPenJoinStyle(KviKvsObjectFunctionCall *c) -{ - QString szStyle; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("style",KVS_PT_STRING,0,szStyle) - KVSO_PARAMETERS_END(c) - if (!m_pPainter) return true; - 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; -} - -bool KviKvsObject_painter::functionsetPenCapStyle(KviKvsObjectFunctionCall *c) -{ - QString szStyle; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("style",KVS_PT_STRING,0,szStyle) - KVSO_PARAMETERS_END(c) - if (!m_pPainter) return true; - 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; -} - -bool KviKvsObject_painter::functionsave(KviKvsObjectFunctionCall * c) -{ - if(m_pPainter) - m_pPainter->save(); - return true; -} - -bool KviKvsObject_painter::functionrestore(KviKvsObjectFunctionCall * c) -{ - if(m_pPainter) - m_pPainter->restore(); - return true; -} - -bool KviKvsObject_painter::functionsetPenStyle(KviKvsObjectFunctionCall *c) -{ - QString szStyle; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("style",KVS_PT_STRING,0,szStyle) - KVSO_PARAMETERS_END(c) - if (!m_pPainter) return true; - 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("Unknown pen style %Q"),&szStyle); - return true; -} - -bool KviKvsObject_painter::functionsetBrushStyle(KviKvsObjectFunctionCall *c) -{ - QString szStyle; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("style",KVS_PT_STRING,0,szStyle) - KVSO_PARAMETERS_END(c) - if (!m_pPainter) return true; - 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("Unknown brushn style %Q"),&szStyle); - return true; -} - -bool KviKvsObject_painter::functionsetGradientStart(KviKvsObjectFunctionCall *c) -{ - 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; -} - -bool KviKvsObject_painter::functionsetGradientStop(KviKvsObjectFunctionCall *c) -{ - 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; -} - -bool KviKvsObject_painter::functionsetGradientColor(KviKvsObjectFunctionCall *c) -{ - 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(!m_pPainter) return true; - - if (!var1->asInteger(iCol1)) - { - var1->asString(szColor); - if (c->paramCount()<3) iOpacity=255; - else - { - if (!var2->asInteger(iOpacity)) - { - c->warning("The opacity parameter didn't evaluate to integer"); - 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("Color name or triplette rgb/hsv values required")); - return true; - } - if ( !var2->asInteger(iCol2)||!var3->asInteger(iCol3)) - { - c->error(__tr2qs("One of the triplette parameters didn't evaluate to an integer"));\ - 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; -} - -bool KviKvsObject_painter::functionsetGradientAsBrush(KviKvsObjectFunctionCall *c) -{ - if (!m_pPainter) return true; - if (!m_pGradient) m_pGradient=new(QLinearGradient); - m_pPainter->setBrush(*m_pGradient); - return true; -} - -bool KviKvsObject_painter::functionclearGradient(KviKvsObjectFunctionCall *c) -{ - if (!m_pGradient) delete m_pGradient; - m_pGradient=0; - return true; -} - -bool KviKvsObject_painter::functionsetPenWidth(KviKvsObjectFunctionCall *c) -{ - kvs_real_t iWidth; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("width",KVS_PT_REAL,0,iWidth) - KVSO_PARAMETERS_END(c) - if (!m_pPainter) return true; - QPen pen=m_pPainter->pen(); - pen.setWidthF(iWidth); - m_pPainter->setPen(pen); - return true; -} - -bool KviKvsObject_painter::functionfillRect(KviKvsObjectFunctionCall *c) -{ - 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(!m_pPainter) return true; - 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; -} - -bool KviKvsObject_painter::functioncolorNames(KviKvsObjectFunctionCall *c) -{ - 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; -} -bool KviKvsObject_painter::functionwidth(KviKvsObjectFunctionCall *c) -{ - kvs_int_t width=m_pPainter->device()->width(); - c->returnValue()->setInteger(width); - return true; -} -bool KviKvsObject_painter::functionheight(KviKvsObjectFunctionCall *c) -{ - kvs_int_t height=m_pPainter->device()->height(); - c->returnValue()->setInteger(height); - return true; -} -bool KviKvsObject_painter::functionpathMoveTo(KviKvsObjectFunctionCall *c) -{ - 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; -} - -bool KviKvsObject_painter::functionpathLineTo(KviKvsObjectFunctionCall *c) -{ - 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; -} - -bool KviKvsObject_painter::functionpathAddText(KviKvsObjectFunctionCall *c) -{ - 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; -} - -bool KviKvsObject_painter::functiondrawPath(KviKvsObjectFunctionCall *c) -{ - if (m_pPainter) m_pPainter->drawPath(*m_pPainterPath); - //delete m_pPainterPath; - //m_pPainterPath=0; - return true; -} - -bool KviKvsObject_painter::functionresetPath(KviKvsObjectFunctionCall *c) -{ - if (m_pPainterPath){ - delete m_pPainterPath; - m_pPainterPath=0; - } - return true; -} - - -#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES -#include "m_class_painter.moc" -#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES + 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; +} +bool KviKvsObject_painter::functiondrawText(KviKvsObjectFunctionCall *c) +{ + QString szText,szMode; + kvs_int_t iX,iY; + 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("mode",KVS_PT_STRING,KVS_PF_OPTIONAL,szMode) + KVSO_PARAMETERS_END(c) + if(!m_pPainter)return true; + if (!szMode.isEmpty()){ + if(KviQString::equalCI(szMode,"RTL"))m_pPainter->setLayoutDirection(Qt::RightToLeft); + else if(KviQString::equalCI(szMode,"LTR"))m_pPainter->setLayoutDirection(Qt::LeftToRight); + else + { + c->warning(__tr2qs("Invalid mode '%Q'"),&szMode); + return true; + } + } + m_pPainter->drawText(iX,iY,szText); + return true; +} + +bool KviKvsObject_painter::functiondrawPixmap(KviKvsObjectFunctionCall *c) +{ + 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(!m_pPainter)return true; + if (!obj) + { + c->warning(__tr2qs("Pixmap parameter is not an object")); + return true; + } + if (!obj->inherits("KviKvsObject_pixmap")) + { + c->warning(__tr2qs("Pixmap object required")); + return true; + } + QPixmap * pm=((KviKvsObject_pixmap *)obj)->getPixmap(); + //if (bTiled) m_pPainter->drawTiledPixmap(iX,iY,iEndx,iEndy,*((KviKvsObject_pixmap *)obj)->getPixmap(),iStartx,iStarty); + //else + m_pPainter->drawPixmap(QPointF(iX,iY),*((KviKvsObject_pixmap *)obj)->getPixmap(),QRect(iStartx,iStarty,iEndx,iEndy)); + return true; +} + +bool KviKvsObject_painter::functionrotateMatrix(KviKvsObjectFunctionCall *c) +{ + kvs_real_t dAngle; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("angle",KVS_PT_DOUBLE,0,dAngle) + KVSO_PARAMETERS_END(c) + if(!m_pPainter)return true; + //m_pMatrix.rotate(dAngle); + //m_pPainter->setWorldMatrix( m_pMatrix,false ); + m_pPainter->rotate(dAngle); + return true; +} + +bool KviKvsObject_painter::functiontranslateMatrix(KviKvsObjectFunctionCall *c) +{ + kvs_real_t dXtrasl,dYtrasl; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("trasl_x",KVS_PT_DOUBLE,0,dXtrasl) + KVSO_PARAMETER("trasl_y",KVS_PT_DOUBLE,0,dYtrasl) + KVSO_PARAMETERS_END(c) + if(!m_pPainter)return true; + //QWMatrix tmpMatrix; + //tmpMatrix.translate(dXtrasl,dYtrasl); + //tmpMatrix = m_pMatrix * tmpMatrix; + //m_pPainter->setWorldMatrix( tmpMatrix ); + //m_pMatrix=tmpMatrix; + m_pPainter->translate(dXtrasl,dYtrasl); + return true; +} + +bool KviKvsObject_painter::functionshearMatrix(KviKvsObjectFunctionCall *c) +{ + kvs_real_t dShearh,dShearv; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("shear_h",KVS_PT_DOUBLE,0,dShearh) + KVSO_PARAMETER("shear_v",KVS_PT_DOUBLE,0,dShearv) + KVSO_PARAMETERS_END(c) + if(!m_pPainter)return true; + //m_pMatrix.shear(dShearh,dShearv); + //m_pPainter->setWorldMatrix(m_pMatrix); + m_pPainter->shear(dShearh,dShearv); + return true; +} + +bool KviKvsObject_painter::functionscaleMatrix(KviKvsObjectFunctionCall *c) +{ + kvs_real_t dScalex,dScaley; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("scale_x",KVS_PT_DOUBLE,0,dScalex) + KVSO_PARAMETER("scale_y",KVS_PT_DOUBLE,0,dScaley) + KVSO_PARAMETERS_END(c) + if(!m_pPainter)return true; + //m_pMatrix.scale(dScalex,dScaley); + //m_pPainter->setWorldMatrix(m_pMatrix); + m_pPainter->scale(dScalex,dScaley); + return true; +} + +bool KviKvsObject_painter::functionresetMatrix(KviKvsObjectFunctionCall *c) +{ + if(!m_pPainter)return true; + //m_pMatrix.reset(); + //m_pPainter->setWorldMatrix( m_pMatrix ); + m_pPainter->resetMatrix(); + return true; +} + +bool KviKvsObject_painter::functiondrawHtmlText(KviKvsObjectFunctionCall *c) +{ + 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) + if(!m_pPainter)return true; + 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; +} + +bool KviKvsObject_painter::functionhtmlTextSize(KviKvsObjectFunctionCall *c) +{ + 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; +} + +bool KviKvsObject_painter::functiondrawIcon(KviKvsObjectFunctionCall *c) +{ + 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("w",KVS_PT_INT,KVS_PF_OPTIONAL,iW) + KVSO_PARAMETER("h",KVS_PT_INT,KVS_PF_OPTIONAL,iH) + + KVSO_PARAMETER("state",KVS_PT_STRING,KVS_PF_OPTIONAL,szState) + KVSO_PARAMETERS_END(c) + if (!m_pPainter) return true; + 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; +} + +bool KviKvsObject_painter::functionsetOpacity(KviKvsObjectFunctionCall *c) +{ + if(!m_pPainter)return true; + kvs_real_t dOpacity; + + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("opacity_factor",KVS_PT_DOUBLE,0,dOpacity) + KVSO_PARAMETERS_END(c) + m_pPainter->setOpacity(dOpacity); + return true; +} + +bool KviKvsObject_painter::functionsetTextAntialiasing(KviKvsObjectFunctionCall *c) +{ + if(!m_pPainter)return true; + + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + m_pPainter->setRenderHint(QPainter::TextAntialiasing,bEnabled); + return true; +} + +bool KviKvsObject_painter::functionsetAntialiasing(KviKvsObjectFunctionCall *c) +{ + if(!m_pPainter)return true; + + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + m_pPainter->setRenderHint(QPainter::Antialiasing,bEnabled); + return true; +} + +bool KviKvsObject_painter::functionsetSmoothPixmapTransform(KviKvsObjectFunctionCall *c) +{ + if(!m_pPainter)return true; + + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + m_pPainter->setRenderHint(QPainter::SmoothPixmapTransform,bEnabled); + return true; +} + +bool KviKvsObject_painter::functionsetPenJoinStyle(KviKvsObjectFunctionCall *c) +{ + QString szStyle; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("style",KVS_PT_STRING,0,szStyle) + KVSO_PARAMETERS_END(c) + if (!m_pPainter) return true; + 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; +} + +bool KviKvsObject_painter::functionsetPenCapStyle(KviKvsObjectFunctionCall *c) +{ + QString szStyle; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("style",KVS_PT_STRING,0,szStyle) + KVSO_PARAMETERS_END(c) + if (!m_pPainter) return true; + 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; +} + +bool KviKvsObject_painter::functionsave(KviKvsObjectFunctionCall * c) +{ + if(m_pPainter) + m_pPainter->save(); + return true; +} + +bool KviKvsObject_painter::functionrestore(KviKvsObjectFunctionCall * c) +{ + if(m_pPainter) + m_pPainter->restore(); + return true; +} + +bool KviKvsObject_painter::functionsetPenStyle(KviKvsObjectFunctionCall *c) +{ + QString szStyle; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("style",KVS_PT_STRING,0,szStyle) + KVSO_PARAMETERS_END(c) + if (!m_pPainter) return true; + 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("Unknown pen style %Q"),&szStyle); + return true; +} + +bool KviKvsObject_painter::functionsetBrushStyle(KviKvsObjectFunctionCall *c) +{ + QString szStyle; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("style",KVS_PT_STRING,0,szStyle) + KVSO_PARAMETERS_END(c) + if (!m_pPainter) return true; + 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("Unknown brushn style %Q"),&szStyle); + return true; +} + +bool KviKvsObject_painter::functionsetGradientStart(KviKvsObjectFunctionCall *c) +{ + 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; +} + +bool KviKvsObject_painter::functionsetGradientStop(KviKvsObjectFunctionCall *c) +{ + 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; +} + +bool KviKvsObject_painter::functionsetGradientColor(KviKvsObjectFunctionCall *c) +{ + 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(!m_pPainter) return true; + + if (!var1->asInteger(iCol1)) + { + var1->asString(szColor); + if (c->paramCount()<3) iOpacity=255; + else + { + if (!var2->asInteger(iOpacity)) + { + c->warning("The opacity parameter didn't evaluate to integer"); + 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("Color name or triplette rgb/hsv values required")); + return true; + } + if ( !var2->asInteger(iCol2)||!var3->asInteger(iCol3)) + { + c->error(__tr2qs("One of the triplette parameters didn't evaluate to an integer"));\ + 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; +} + +bool KviKvsObject_painter::functionsetGradientAsBrush(KviKvsObjectFunctionCall *c) +{ + if (!m_pPainter) return true; + if (!m_pGradient) m_pGradient=new(QLinearGradient); + m_pPainter->setBrush(*m_pGradient); + return true; +} + +bool KviKvsObject_painter::functionclearGradient(KviKvsObjectFunctionCall *c) +{ + if (!m_pGradient) delete m_pGradient; + m_pGradient=0; + return true; +} + +bool KviKvsObject_painter::functionsetPenWidth(KviKvsObjectFunctionCall *c) +{ + kvs_real_t iWidth; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("width",KVS_PT_REAL,0,iWidth) + KVSO_PARAMETERS_END(c) + if (!m_pPainter) return true; + QPen pen=m_pPainter->pen(); + pen.setWidthF(iWidth); + m_pPainter->setPen(pen); + return true; +} + +bool KviKvsObject_painter::functionfillRect(KviKvsObjectFunctionCall *c) +{ + 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(!m_pPainter) return true; + 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; +} + +bool KviKvsObject_painter::functioncolorNames(KviKvsObjectFunctionCall *c) +{ + 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; +} +bool KviKvsObject_painter::functionwidth(KviKvsObjectFunctionCall *c) +{ + kvs_int_t width=m_pPainter->device()->width(); + c->returnValue()->setInteger(width); + return true; +} +bool KviKvsObject_painter::functionheight(KviKvsObjectFunctionCall *c) +{ + kvs_int_t height=m_pPainter->device()->height(); + c->returnValue()->setInteger(height); + return true; +} +bool KviKvsObject_painter::functionpathMoveTo(KviKvsObjectFunctionCall *c) +{ + 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; +} + +bool KviKvsObject_painter::functionpathLineTo(KviKvsObjectFunctionCall *c) +{ + 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; +} + +bool KviKvsObject_painter::functionpathAddText(KviKvsObjectFunctionCall *c) +{ + 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; +} + +bool KviKvsObject_painter::functiondrawPath(KviKvsObjectFunctionCall *c) +{ + if (m_pPainter) m_pPainter->drawPath(*m_pPainterPath); + //delete m_pPainterPath; + //m_pPainterPath=0; + return true; +} + +bool KviKvsObject_painter::functionresetPath(KviKvsObjectFunctionCall *c) +{ + if (m_pPainterPath){ + delete m_pPainterPath; + m_pPainterPath=0; + } + return true; +} + + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_class_painter.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/class_painter.h b/src/modules/objects/class_painter.h index 08dbd3b30..5a4049f81 100644 --- a/src/modules/objects/class_painter.h +++ b/src/modules/objects/class_painter.h @@ -1,125 +1,125 @@ -#ifndef _CLASS_PAINTER_H_ -#define _CLASS_PAINTER_H_ -//mdm: -// Painter : class_painter.h -// Creation date : Fri Mar 18 14:30:48 CEST 2005 -// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) -// This file is part of the KVirc irc client distribution -// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net) -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -#include - -#include -#include -#include "kvi_string.h" -#include -#include "object_macros.h" - - -class KviKvsObject_painter : public KviKvsObject -{ - Q_OBJECT -public: - KVSO_DECLARE_OBJECT(KviKvsObject_painter) -protected: - QPrinter * m_pPrinter; - QPainter * m_pPainter; - QMatrix m_pMatrix; - QLinearGradient *m_pGradient; - QPainterPath *m_pPainterPath; -public: - bool functionSetFont(KviKvsObjectFunctionCall *c); - bool functionSetFontSize(KviKvsObjectFunctionCall *c); - - bool functionfontAscent(KviKvsObjectFunctionCall *c); - bool functionfontDescent(KviKvsObjectFunctionCall *c); - bool functionfontMetricsWidth(KviKvsObjectFunctionCall *c); - bool functionfontMetricsHeight(KviKvsObjectFunctionCall *c); - bool functionsetBrush(KviKvsObjectFunctionCall *c); - bool functionsetPen(KviKvsObjectFunctionCall *c); - bool functionsetBackGroundMode(KviKvsObjectFunctionCall *c); - - bool functiondrawRect(KviKvsObjectFunctionCall *c); - bool functiondrawWinFocusRect(KviKvsObjectFunctionCall *c); - bool functiondrawLine(KviKvsObjectFunctionCall *c); - bool functiondrawRoundRect(KviKvsObjectFunctionCall *c); - bool functiondrawPoint(KviKvsObjectFunctionCall *c); - bool functiondrawArc(KviKvsObjectFunctionCall *c); - bool functiondrawChord(KviKvsObjectFunctionCall *c); - bool functiondrawPie(KviKvsObjectFunctionCall *c); - bool functiondrawEllipse(KviKvsObjectFunctionCall *c); - - bool functiondrawText(KviKvsObjectFunctionCall *c); - bool functiondrawPixmap(KviKvsObjectFunctionCall *c); - - - bool functionbegin(KviKvsObjectFunctionCall *c); - bool functionend(KviKvsObjectFunctionCall *c); - bool functionsave(KviKvsObjectFunctionCall *c); - bool functionrestore(KviKvsObjectFunctionCall *c); - - - bool functionscaleMatrix(KviKvsObjectFunctionCall *c); - bool functionshearMatrix(KviKvsObjectFunctionCall *c); - bool functionrotateMatrix(KviKvsObjectFunctionCall *c); - bool functionresetMatrix(KviKvsObjectFunctionCall *c); - bool functiontranslateMatrix(KviKvsObjectFunctionCall *c); - bool functionsetPenStyle(KviKvsObjectFunctionCall *c); - bool functionsetBrushStyle(KviKvsObjectFunctionCall *c); - -// QT4 - bool functionsetOpacity(KviKvsObjectFunctionCall *c); - bool functionsetSmoothPixmapTransform(KviKvsObjectFunctionCall *c); - bool functionsetTextAntialiasing(KviKvsObjectFunctionCall *c); - bool functionsetAntialiasing(KviKvsObjectFunctionCall *c); - bool functionsetGradientStart(KviKvsObjectFunctionCall *c); - bool functionsetGradientStop(KviKvsObjectFunctionCall *c); - bool functionsetGradientColor(KviKvsObjectFunctionCall *c); - bool functionsetGradientAsBrush(KviKvsObjectFunctionCall *c); - bool functionclearGradient(KviKvsObjectFunctionCall *c); - - bool functiondrawIcon(KviKvsObjectFunctionCall *c); - bool functiondrawHtmlText(KviKvsObjectFunctionCall *c); - bool functionhtmlTextSize(KviKvsObjectFunctionCall *c); - bool functionfillRect(KviKvsObjectFunctionCall *c); - bool functionsetPenWidth(KviKvsObjectFunctionCall *c); - bool functioncolorNames(KviKvsObjectFunctionCall *c); - bool functionpathMoveTo(KviKvsObjectFunctionCall *c); - bool functionpathLineTo(KviKvsObjectFunctionCall *c); - bool functiondrawPath(KviKvsObjectFunctionCall *c); - bool functionsetPenJoinStyle(KviKvsObjectFunctionCall *c); - bool functionsetPenCapStyle(KviKvsObjectFunctionCall *c); - bool functionpathAddText(KviKvsObjectFunctionCall *c); - bool functionresetPath(KviKvsObjectFunctionCall *c); - - bool functionBeginPdf(KviKvsObjectFunctionCall *c); - - bool functionwidth(KviKvsObjectFunctionCall *c); - bool functionheight(KviKvsObjectFunctionCall *c); - - -protected: - void attachDevice(KviKvsObject * o,QPaintDevice * p); -protected slots: - void detachDevice(); -private: - KviKvsObject * m_pDeviceObject; -}; -#endif // !_CLASS_PAINTER_H_ - - - +#ifndef _CLASS_PAINTER_H_ +#define _CLASS_PAINTER_H_ +//mdm: +// Painter : class_painter.h +// Creation date : Fri Mar 18 14:30:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include + +#include +#include +#include "kvi_string.h" +#include +#include "object_macros.h" + + +class KviKvsObject_painter : public KviKvsObject +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_painter) +protected: + QPrinter * m_pPrinter; + QPainter * m_pPainter; + QMatrix m_pMatrix; + QLinearGradient *m_pGradient; + QPainterPath *m_pPainterPath; +public: + bool functionSetFont(KviKvsObjectFunctionCall *c); + bool functionSetFontSize(KviKvsObjectFunctionCall *c); + + bool functionfontAscent(KviKvsObjectFunctionCall *c); + bool functionfontDescent(KviKvsObjectFunctionCall *c); + bool functionfontMetricsWidth(KviKvsObjectFunctionCall *c); + bool functionfontMetricsHeight(KviKvsObjectFunctionCall *c); + bool functionsetBrush(KviKvsObjectFunctionCall *c); + bool functionsetPen(KviKvsObjectFunctionCall *c); + bool functionsetBackGroundMode(KviKvsObjectFunctionCall *c); + + bool functiondrawRect(KviKvsObjectFunctionCall *c); + bool functiondrawWinFocusRect(KviKvsObjectFunctionCall *c); + bool functiondrawLine(KviKvsObjectFunctionCall *c); + bool functiondrawRoundRect(KviKvsObjectFunctionCall *c); + bool functiondrawPoint(KviKvsObjectFunctionCall *c); + bool functiondrawArc(KviKvsObjectFunctionCall *c); + bool functiondrawChord(KviKvsObjectFunctionCall *c); + bool functiondrawPie(KviKvsObjectFunctionCall *c); + bool functiondrawEllipse(KviKvsObjectFunctionCall *c); + + bool functiondrawText(KviKvsObjectFunctionCall *c); + bool functiondrawPixmap(KviKvsObjectFunctionCall *c); + + + bool functionbegin(KviKvsObjectFunctionCall *c); + bool functionend(KviKvsObjectFunctionCall *c); + bool functionsave(KviKvsObjectFunctionCall *c); + bool functionrestore(KviKvsObjectFunctionCall *c); + + + bool functionscaleMatrix(KviKvsObjectFunctionCall *c); + bool functionshearMatrix(KviKvsObjectFunctionCall *c); + bool functionrotateMatrix(KviKvsObjectFunctionCall *c); + bool functionresetMatrix(KviKvsObjectFunctionCall *c); + bool functiontranslateMatrix(KviKvsObjectFunctionCall *c); + bool functionsetPenStyle(KviKvsObjectFunctionCall *c); + bool functionsetBrushStyle(KviKvsObjectFunctionCall *c); + +// QT4 + bool functionsetOpacity(KviKvsObjectFunctionCall *c); + bool functionsetSmoothPixmapTransform(KviKvsObjectFunctionCall *c); + bool functionsetTextAntialiasing(KviKvsObjectFunctionCall *c); + bool functionsetAntialiasing(KviKvsObjectFunctionCall *c); + bool functionsetGradientStart(KviKvsObjectFunctionCall *c); + bool functionsetGradientStop(KviKvsObjectFunctionCall *c); + bool functionsetGradientColor(KviKvsObjectFunctionCall *c); + bool functionsetGradientAsBrush(KviKvsObjectFunctionCall *c); + bool functionclearGradient(KviKvsObjectFunctionCall *c); + + bool functiondrawIcon(KviKvsObjectFunctionCall *c); + bool functiondrawHtmlText(KviKvsObjectFunctionCall *c); + bool functionhtmlTextSize(KviKvsObjectFunctionCall *c); + bool functionfillRect(KviKvsObjectFunctionCall *c); + bool functionsetPenWidth(KviKvsObjectFunctionCall *c); + bool functioncolorNames(KviKvsObjectFunctionCall *c); + bool functionpathMoveTo(KviKvsObjectFunctionCall *c); + bool functionpathLineTo(KviKvsObjectFunctionCall *c); + bool functiondrawPath(KviKvsObjectFunctionCall *c); + bool functionsetPenJoinStyle(KviKvsObjectFunctionCall *c); + bool functionsetPenCapStyle(KviKvsObjectFunctionCall *c); + bool functionpathAddText(KviKvsObjectFunctionCall *c); + bool functionresetPath(KviKvsObjectFunctionCall *c); + + bool functionBeginPdf(KviKvsObjectFunctionCall *c); + + bool functionwidth(KviKvsObjectFunctionCall *c); + bool functionheight(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/class_pixmap.cpp b/src/modules/objects/class_pixmap.cpp index 2b41ab2ec..f207e4532 100644 --- a/src/modules/objects/class_pixmap.cpp +++ b/src/modules/objects/class_pixmap.cpp @@ -52,7 +52,7 @@ Scales the pixmap 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. + - 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. Transformation type values: - Fast: fast transformation but less quality. @@ -137,13 +137,13 @@ bool KviKvsObject_pixmap::functionscale(KviKvsObjectFunctionCall *c) KVSO_PARAMETER("aspect_ratio",KVS_PT_STRING,KVS_PF_OPTIONAL,szAspectRatio) KVSO_PARAMETER("tranformation_type",KVS_PT_STRING,KVS_PF_OPTIONAL,szTransformation) KVSO_PARAMETERS_END(c) - Qt::AspectRatioMode ratio=Qt::IgnoreAspectRatio; - 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; + Qt::AspectRatioMode ratio=Qt::IgnoreAspectRatio; + 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 if (!szAspectRatio.isEmpty())c->warning(__tr2qs("Unknown aspect ratio: using default value IgnoreAspectRatio")); Qt::TransformationMode tmode=Qt::FastTransformation; - if (KviQString::equalCI(szTransformation,"Fast")) tmode=Qt::FastTransformation; + if (KviQString::equalCI(szTransformation,"Fast")) tmode=Qt::FastTransformation; else if (KviQString::equalCI(szTransformation,"Smooth")) tmode=Qt::SmoothTransformation; else if (!szAspectRatio.isEmpty())c->warning(__tr2qs("Unknown tranformation mode: using default value Fast")); diff --git a/src/modules/objects/class_popupmenu.cpp b/src/modules/objects/class_popupmenu.cpp index 50b14e9a0..4d1d5247a 100644 --- a/src/modules/objects/class_popupmenu.cpp +++ b/src/modules/objects/class_popupmenu.cpp @@ -1,394 +1,394 @@ -//mdm : -// File : class_popupmenu.cpp -// Creation date : Mon Feb 01 21:30:48 CEST 2005 -// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) -// Lucia Papini (^ashura^) English Translation. -// This file is part of the KVirc irc client distribution -// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net) -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// - - -#include "class_popupmenu.h" - -#include "kvi_error.h" -#include "kvi_debug.h" -#include "kvi_locale.h" -#include "kvi_iconmanager.h" -#include "kvi_tal_popupmenu.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: $insertWidget()[br] - Inserts widget items int a popup menu and return the popup identifier.[br] - The widget is treats as a separator; this means that the item is not selectable and you can, for example, simply insert a label if you need a popup menu with a title. - !fn: $insertHandle(,,[icon]) - Inserts a submenu with optional icon into the popup menu. - !fn: $exec([,,]) - If called without paramaters show the popup menu at the current pointer position.[br] - With the optional parameters show the popup menu at the coordinate x,y widget parameter relative. - !fn: $removeItem() - Removes the menu item that has the identifier id. - !fn: $removeItemAt() - Removes the menu item at position index. - !fn: $insertSeparator() - Inserts a separator at position index.[br] - If the index is negative the separator becomes the last menu item. - !fn: $activatedEvent() - This function is called when a menu item and return the the item id.[br] - The default implementation emits the [classfnc]$activated[/classfnc]() signal. - !fn: $highligthtedEvent() - This function is called when a menu item is highlighted and return the item id.[br] - The default implementation emits the [classfnc]$highlighted[/classfnc]() signal. - @signals: - !sg: $activated() - This signal is emitted by the default implementation of [classfnc]$activatedEvent[/classfnc](). - !sg: $highlighted() - This signal is emitted by the default implementation of [classfnc]$highlightedEvent[/classfnc](). - [br] - |-EXAMPLE POPUP MENU-|[br] - |--Start: - # First of all we create an array wich will be used to create random colors.[br] - %Hex[]=$array(0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)[br] - [br] - class (ws,widget)[br] - {[br] - #In the constructor we create everything that belong to the single widget.[br] - constructor[br] - {[br] - #Geometry of the widget and setting-up of popupmenu [br] - $$->$setGeometry(%X,%Y,100,100)[br] - $$->%lay=$new(layout,$$)[br] - #Here we generate a cicle to create our labels inside the widget.[br] - %i=0[br] - while (%i<10)[br] - {[br] - $$->%label=$new(label,$$)[br] - $$->%label->$settext("Another class by N\&G")[br] - #We set our foreground's coulor using the hex arrey in random way.[br] - %color=%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)][br] - $$->%label->$setforegroundcolor(%color)[br] - $$->%label->$setautoresize(1)[br] - #We add the label to the widget's popupmenu.[br] - $$->%lay->$addwidget($$->%label,%i,0)[br] - %i++;[br] - }[br] - #We make the popupmenu relative to this widget: this is merely demonstrative.[br] - #because it creates 25 identical popups.[br] - $$->%Popupmenu=$new(popupmenu,$$)[br] - #we create the label widget wich will be used as popup's title[br] - $$->%Popuptitle=$new(label)[br] - $$->%Popuptitle->$settext("Windows Options")[br] - $$->%Popuptitle->$setAlignment(Center)[br] - #and we add it.[br] - %A=$$->%Popuptitle[br] - $$->%Popupmenu->$insertwidget(%A)[br] - #Here we keep the various IDs in the arrays[br] - %Tile[%I]=$$->%Popupmenu->$insertItem("Tile",118)[br] - %Cascade[%I]=$$->%Popupmenu->$insertItem("Cascade",115)[br] - $$->%Popupmenu->$insertSeparator(3)[br] - %Closeactw[%I]=$$->%Popupmenu->$insertItem("Close Active Window",08)[br] - %Closeallw[%I]=$$->%Popupmenu->$insertItem("Close All Window",58)[br] - $$->$show()[br] - privateimpl($$->%Popupmenu,activatedEvent)[br] - {[br] - %id=$0[br] - %i = 0[br] - #with this cicle we control wich of the items has been called comparing the id given back by the event with our arrays created before;[br] - while (%i<20)[br] - {[br] - if (%id == %Tile[%i]) return %Workspace->$tile()[br] - if (%id == %Cascade[%i]) return %Workspace->$cascade()[br] - if (%id == %Closeactw[%i]) return %Workspace->$closeactivewindow()[br] - if (%id == %Closeallw[%i]) return %Workspace->$closeallwindows()[br] - %i ++[br] - }[br] - }[br] - }[br] - #we activate the popup pushing the right mouse button on the widget[br] - mousepressevent[br] - {[br] - if ($0 == 1) $$->%Popupmenu->$exec()[br] - }[br] - }[br] - %Workspace=$new(workspace)[br] - %Workspace->$resize(640,480)[br] - %I=0[br] - %Cicle=1[br] - while (%I<20)[br] - {[br] - %X=$rand(500)[br] - %Y=$rand(480)[br] - %Widget=$new(ws,%Workspace)[br] - %I++[br] - }[br] - #Let's show! - %Workspace->$show[br] - |--End.[br][br] -*/ - -KVSO_BEGIN_REGISTERCLASS(KviKvsObject_popupmenu,"popupmenu","widget") - KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"insertItem", functioninsertItem) - //KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"insertWidget", functioninsertWidget) -// KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"setTitle", functionsetTitle) - KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"exec", functionexec) - KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"insertSeparator", functioninsertSeparator) - KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"removeItem", functionremoveItem) - - // events - KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"highlightedEvent", functionhighlightedEvent) - KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"activatedEvent", functionactivatedEvent) - -KVSO_END_REGISTERCLASS(KviKvsObject_popupmenu) - -KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_popupmenu,KviKvsObject_widget) - -KVSO_END_CONSTRUCTOR(KviKvsObject_popupmenu) - - -KVSO_BEGIN_DESTRUCTOR(KviKvsObject_popupmenu) - -KVSO_END_CONSTRUCTOR(KviKvsObject_popupmenu) - -bool KviKvsObject_popupmenu::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) -{ - identifier=0; - SET_OBJECT(QMenu) - connect(widget(),SIGNAL(triggered(QAction *)),this,SLOT(slottriggered(QAction *))); - connect(widget(),SIGNAL(highlighted(int)),this,SLOT(slothighlighted(int))); - return true; -} - -bool KviKvsObject_popupmenu::functioninsertItem(KviKvsObjectFunctionCall *c) -{ - QString szItem,szIcon; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("text",KVS_PT_STRING,0,szItem) - KVSO_PARAMETER("icon_id",KVS_PT_STRING,KVS_PF_OPTIONAL,szIcon) - KVSO_PARAMETERS_END(c) - if(!widget())return true; - QPixmap *pix = 0; - int id=0; - QAction * action; - if(!szIcon.isEmpty()) - { - pix = g_pIconManager->getImage(szIcon); - if (pix) action=((QMenu *)widget())->addAction(*pix,szItem); - else c->warning(__tr2qs("pix '%Q' doesn't exists"),&szIcon); - } - else - action=((QMenu *)widget())->addAction(szItem); - actionsDict[identifier]=action; - c->returnValue()->setInteger(identifier); - identifier++; - return true; -} -/* -bool KviKvsObject_popupmenu::functionsetTitle(KviKvsObjectFunctionCall *c) -{ - QString szTitle; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("title",KVS_PT_STRING,0,szTitle) - KVSO_PARAMETERS_END(c) - if(!widget())return true; - ((QMenu *)widget())->setTitle(szTitle); - - return true; -} -/* -bool KviKvsObject_popupmenu::functioninsertWidget(KviKvsObjectFunctionCall *c) -{ - KviKvsObject *pObject; - kvs_hobject_t hObject; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) - KVSO_PARAMETERS_END(c) - pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); - if (!pObject) - { - c->warning(__tr2qs("Widget parameter is not an object")); - return true; - } - if (!pObject->object()) - { - c->warning(__tr2qs("Widget parameter is not a valid object")); - return true; - } - if(!pObject->object()->isWidgetType()) - { - c->warning(__tr2qs("Can't add a non-widget object")); - return TRUE; - } - if (widget()) ((KviTalPopupMenu *)widget())->insertItem(((KviTalPopupMenu *)(pObject->object()))); - return true; -} - - -bool KviKvsObject_popupmenu::functioninsertHandle(KviKvsObjectFunctionCall *c) -{ - KviKvsObject *ob; - QString szLabel,szIcon; - kvs_hobject_t hObject; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("text_label",KVS_PT_STRING,0,szLabel) - KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) - KVSO_PARAMETER("icon_id",KVS_PT_STRING,KVS_PF_OPTIONAL,szIcon) - KVSO_PARAMETERS_END(c) - ob=KviKvsKernel::instance()->objectController()->lookupObject(hObject); - if(!ob->object()->inherits("KviKvsObject_popupmenu")) - { - c->warning(__tr2qs("Can't add a non - popupmenu object")); - return TRUE; - } - if(!widget())return true; - QPixmap *pix = 0; - int id=0; - if(!szIcon.isEmpty()) - { - pix = g_pIconManager->getImage(szIcon); - if (pix) id=((KviTalPopupMenu *)widget())->insertItem(*pix,szLabel,((KviTalPopupMenu *)(ob->object()))); - else c->warning(__tr2qs("pix '%Q' doesn't exists"),&szIcon); - } - else - id=((KviTalPopupMenu *)widget())->insertItem(szLabel,((KviTalPopupMenu *)(ob->object()))); - c->returnValue()->setInteger(id); - return true; -} -*/ -bool KviKvsObject_popupmenu::functionexec(KviKvsObjectFunctionCall *c) -{ - if(!c->params()->count()) - { - ((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); - if (!pObject) - { - c->warning(__tr2qs("Widget parameter is not an object")); - return true; - } - if (!pObject->object()) - { - c->warning(__tr2qs("Widget parameter is not a valid object")); - return true; - } - if(!pObject->object()->isWidgetType()) - { - c->warning(__tr2qs("Doesn't a widget object")); - return true; - } - - ((QMenu *)widget())->exec(((QWidget *)(pObject->object()))->mapToGlobal(QPoint(iX,iY)) ); - - return true; -} - -bool KviKvsObject_popupmenu::functionremoveItem(KviKvsObjectFunctionCall *c) -{ - kvs_uint_t uItem; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("item_id",KVS_PT_UNSIGNEDINTEGER,0,uItem) - KVSO_PARAMETERS_END(c) - QAction * action=actionsDict.value(uItem); - if(widget() && action){ - ((QMenu *)widget())->removeAction(action); - identifier--; - } - return true; -} - -bool KviKvsObject_popupmenu::functioninsertSeparator(KviKvsObjectFunctionCall *c) -{ - kvs_uint_t iIndex; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,iIndex) - KVSO_PARAMETERS_END(c) - QAction * action=actionsDict.value(iIndex); - if(widget()&& action)((QMenu *)widget())->insertSeparator(action); - return true; -} - -void KviKvsObject_popupmenu::slothighlighted(int i) -{ - KviKvsVariantList params(new KviKvsVariant((kvs_int_t)i)); - callFunction(this,"highlightedEvent",¶ms); -} - -bool KviKvsObject_popupmenu::functionhighlightedEvent(KviKvsObjectFunctionCall *c) -{ - emitSignal("highlighted",c,c->params()); - return true; -} - -void KviKvsObject_popupmenu::slottriggered(QAction *a) -{ - QHashIterator i(actionsDict); - kvs_int_t count=0; - bool found=false; - while (i.hasNext()) - { - i.next(); - if (i.value()!= a) count++; - else break; - } - KviKvsVariantList params(new KviKvsVariant(count)); - callFunction(this,"activatedEvent",¶ms); -} - -bool KviKvsObject_popupmenu::functionactivatedEvent(KviKvsObjectFunctionCall *c) -{ - emitSignal("activated",c,c->params()); - return true; -} - - -#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES -#include "m_class_popupmenu.moc" -#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES +//mdm : +// File : class_popupmenu.cpp +// Creation date : Mon Feb 01 21:30:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// Lucia Papini (^ashura^) English Translation. +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// + + +#include "class_popupmenu.h" + +#include "kvi_error.h" +#include "kvi_debug.h" +#include "kvi_locale.h" +#include "kvi_iconmanager.h" +#include "kvi_tal_popupmenu.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: $insertWidget()[br] + Inserts widget items int a popup menu and return the popup identifier.[br] + The widget is treats as a separator; this means that the item is not selectable and you can, for example, simply insert a label if you need a popup menu with a title. + !fn: $insertHandle(,,[icon]) + Inserts a submenu with optional icon into the popup menu. + !fn: $exec([,,]) + If called without paramaters show the popup menu at the current pointer position.[br] + With the optional parameters show the popup menu at the coordinate x,y widget parameter relative. + !fn: $removeItem() + Removes the menu item that has the identifier id. + !fn: $removeItemAt() + Removes the menu item at position index. + !fn: $insertSeparator() + Inserts a separator at position index.[br] + If the index is negative the separator becomes the last menu item. + !fn: $activatedEvent() + This function is called when a menu item and return the the item id.[br] + The default implementation emits the [classfnc]$activated[/classfnc]() signal. + !fn: $highligthtedEvent() + This function is called when a menu item is highlighted and return the item id.[br] + The default implementation emits the [classfnc]$highlighted[/classfnc]() signal. + @signals: + !sg: $activated() + This signal is emitted by the default implementation of [classfnc]$activatedEvent[/classfnc](). + !sg: $highlighted() + This signal is emitted by the default implementation of [classfnc]$highlightedEvent[/classfnc](). + [br] + |-EXAMPLE POPUP MENU-|[br] + |--Start: + # First of all we create an array wich will be used to create random colors.[br] + %Hex[]=$array(0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)[br] + [br] + class (ws,widget)[br] + {[br] + #In the constructor we create everything that belong to the single widget.[br] + constructor[br] + {[br] + #Geometry of the widget and setting-up of popupmenu [br] + $$->$setGeometry(%X,%Y,100,100)[br] + $$->%lay=$new(layout,$$)[br] + #Here we generate a cicle to create our labels inside the widget.[br] + %i=0[br] + while (%i<10)[br] + {[br] + $$->%label=$new(label,$$)[br] + $$->%label->$settext("Another class by N\&G")[br] + #We set our foreground's coulor using the hex arrey in random way.[br] + %color=%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)][br] + $$->%label->$setforegroundcolor(%color)[br] + $$->%label->$setautoresize(1)[br] + #We add the label to the widget's popupmenu.[br] + $$->%lay->$addwidget($$->%label,%i,0)[br] + %i++;[br] + }[br] + #We make the popupmenu relative to this widget: this is merely demonstrative.[br] + #because it creates 25 identical popups.[br] + $$->%Popupmenu=$new(popupmenu,$$)[br] + #we create the label widget wich will be used as popup's title[br] + $$->%Popuptitle=$new(label)[br] + $$->%Popuptitle->$settext("Windows Options")[br] + $$->%Popuptitle->$setAlignment(Center)[br] + #and we add it.[br] + %A=$$->%Popuptitle[br] + $$->%Popupmenu->$insertwidget(%A)[br] + #Here we keep the various IDs in the arrays[br] + %Tile[%I]=$$->%Popupmenu->$insertItem("Tile",118)[br] + %Cascade[%I]=$$->%Popupmenu->$insertItem("Cascade",115)[br] + $$->%Popupmenu->$insertSeparator(3)[br] + %Closeactw[%I]=$$->%Popupmenu->$insertItem("Close Active Window",08)[br] + %Closeallw[%I]=$$->%Popupmenu->$insertItem("Close All Window",58)[br] + $$->$show()[br] + privateimpl($$->%Popupmenu,activatedEvent)[br] + {[br] + %id=$0[br] + %i = 0[br] + #with this cicle we control wich of the items has been called comparing the id given back by the event with our arrays created before;[br] + while (%i<20)[br] + {[br] + if (%id == %Tile[%i]) return %Workspace->$tile()[br] + if (%id == %Cascade[%i]) return %Workspace->$cascade()[br] + if (%id == %Closeactw[%i]) return %Workspace->$closeactivewindow()[br] + if (%id == %Closeallw[%i]) return %Workspace->$closeallwindows()[br] + %i ++[br] + }[br] + }[br] + }[br] + #we activate the popup pushing the right mouse button on the widget[br] + mousepressevent[br] + {[br] + if ($0 == 1) $$->%Popupmenu->$exec()[br] + }[br] + }[br] + %Workspace=$new(workspace)[br] + %Workspace->$resize(640,480)[br] + %I=0[br] + %Cicle=1[br] + while (%I<20)[br] + {[br] + %X=$rand(500)[br] + %Y=$rand(480)[br] + %Widget=$new(ws,%Workspace)[br] + %I++[br] + }[br] + #Let's show! + %Workspace->$show[br] + |--End.[br][br] +*/ + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_popupmenu,"popupmenu","widget") + KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"insertItem", functioninsertItem) + //KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"insertWidget", functioninsertWidget) +// KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"setTitle", functionsetTitle) + KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"exec", functionexec) + KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"insertSeparator", functioninsertSeparator) + KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"removeItem", functionremoveItem) + + // events + KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"highlightedEvent", functionhighlightedEvent) + KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"activatedEvent", functionactivatedEvent) + +KVSO_END_REGISTERCLASS(KviKvsObject_popupmenu) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_popupmenu,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_popupmenu) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_popupmenu) + +KVSO_END_CONSTRUCTOR(KviKvsObject_popupmenu) + +bool KviKvsObject_popupmenu::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + identifier=0; + SET_OBJECT(QMenu) + connect(widget(),SIGNAL(triggered(QAction *)),this,SLOT(slottriggered(QAction *))); + connect(widget(),SIGNAL(highlighted(int)),this,SLOT(slothighlighted(int))); + return true; +} + +bool KviKvsObject_popupmenu::functioninsertItem(KviKvsObjectFunctionCall *c) +{ + QString szItem,szIcon; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szItem) + KVSO_PARAMETER("icon_id",KVS_PT_STRING,KVS_PF_OPTIONAL,szIcon) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + QPixmap *pix = 0; + int id=0; + QAction * action; + if(!szIcon.isEmpty()) + { + pix = g_pIconManager->getImage(szIcon); + if (pix) action=((QMenu *)widget())->addAction(*pix,szItem); + else c->warning(__tr2qs("pix '%Q' doesn't exists"),&szIcon); + } + else + action=((QMenu *)widget())->addAction(szItem); + actionsDict[identifier]=action; + c->returnValue()->setInteger(identifier); + identifier++; + return true; +} +/* +bool KviKvsObject_popupmenu::functionsetTitle(KviKvsObjectFunctionCall *c) +{ + QString szTitle; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("title",KVS_PT_STRING,0,szTitle) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + ((QMenu *)widget())->setTitle(szTitle); + + return true; +} +/* +bool KviKvsObject_popupmenu::functioninsertWidget(KviKvsObjectFunctionCall *c) +{ + KviKvsObject *pObject; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!pObject) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!pObject->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!pObject->object()->isWidgetType()) + { + c->warning(__tr2qs("Can't add a non-widget object")); + return TRUE; + } + if (widget()) ((KviTalPopupMenu *)widget())->insertItem(((KviTalPopupMenu *)(pObject->object()))); + return true; +} + + +bool KviKvsObject_popupmenu::functioninsertHandle(KviKvsObjectFunctionCall *c) +{ + KviKvsObject *ob; + QString szLabel,szIcon; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text_label",KVS_PT_STRING,0,szLabel) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("icon_id",KVS_PT_STRING,KVS_PF_OPTIONAL,szIcon) + KVSO_PARAMETERS_END(c) + ob=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if(!ob->object()->inherits("KviKvsObject_popupmenu")) + { + c->warning(__tr2qs("Can't add a non - popupmenu object")); + return TRUE; + } + if(!widget())return true; + QPixmap *pix = 0; + int id=0; + if(!szIcon.isEmpty()) + { + pix = g_pIconManager->getImage(szIcon); + if (pix) id=((KviTalPopupMenu *)widget())->insertItem(*pix,szLabel,((KviTalPopupMenu *)(ob->object()))); + else c->warning(__tr2qs("pix '%Q' doesn't exists"),&szIcon); + } + else + id=((KviTalPopupMenu *)widget())->insertItem(szLabel,((KviTalPopupMenu *)(ob->object()))); + c->returnValue()->setInteger(id); + return true; +} +*/ +bool KviKvsObject_popupmenu::functionexec(KviKvsObjectFunctionCall *c) +{ + if(!c->params()->count()) + { + ((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); + if (!pObject) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!pObject->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!pObject->object()->isWidgetType()) + { + c->warning(__tr2qs("Doesn't a widget object")); + return true; + } + + ((QMenu *)widget())->exec(((QWidget *)(pObject->object()))->mapToGlobal(QPoint(iX,iY)) ); + + return true; +} + +bool KviKvsObject_popupmenu::functionremoveItem(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uItem; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("item_id",KVS_PT_UNSIGNEDINTEGER,0,uItem) + KVSO_PARAMETERS_END(c) + QAction * action=actionsDict.value(uItem); + if(widget() && action){ + ((QMenu *)widget())->removeAction(action); + identifier--; + } + return true; +} + +bool KviKvsObject_popupmenu::functioninsertSeparator(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t iIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,iIndex) + KVSO_PARAMETERS_END(c) + QAction * action=actionsDict.value(iIndex); + if(widget()&& action)((QMenu *)widget())->insertSeparator(action); + return true; +} + +void KviKvsObject_popupmenu::slothighlighted(int i) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)i)); + callFunction(this,"highlightedEvent",¶ms); +} + +bool KviKvsObject_popupmenu::functionhighlightedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("highlighted",c,c->params()); + return true; +} + +void KviKvsObject_popupmenu::slottriggered(QAction *a) +{ + QHashIterator i(actionsDict); + kvs_int_t count=0; + bool found=false; + while (i.hasNext()) + { + i.next(); + if (i.value()!= a) count++; + else break; + } + KviKvsVariantList params(new KviKvsVariant(count)); + callFunction(this,"activatedEvent",¶ms); +} + +bool KviKvsObject_popupmenu::functionactivatedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("activated",c,c->params()); + return true; +} + + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_class_popupmenu.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/class_widget.cpp b/src/modules/objects/class_widget.cpp index 322336b47..84c61d022 100644 --- a/src/modules/objects/class_widget.cpp +++ b/src/modules/objects/class_widget.cpp @@ -1,1994 +1,1994 @@ -//============================================================================= -// -// File : class_widget.cpp -// Creation date : Mon Sep 11 16:35:32 CET 2000 by Krzysztof Godlewski -// -// This file is part of the KVirc irc client distribution -// Copyright (C) 1999-2005 Szymon Stefanek (pragma at kvirc dot net) -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -//============================================================================= - -#include "class_widget.h" -#include "class_pixmap.h" - -#include "kvi_malloc.h" -#include "kvi_debug.h" -#include "kvi_error.h" -#include "kvi_locale.h" -#include "kvi_iconmanager.h" -#include "kvi_window.h" -#include "kvi_app.h" -#include "kvi_frame.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef COMPILE_WEBKIT_SUPPORT - #include -#endif - -KviKvsWidget::KviKvsWidget(KviKvsObject_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(); -} - - -// FIXME: WFLAGS -const char * const widgettypes_tbl[] = { - "TopLevel", - "Dialog", - "Popup", - "Desktop", - "Title", - "StaysOnTop", - "SysMenu", - "Minimize", - "Maximize", - "Subwindow", - "FramelessWindow" -}; - -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 -}; - -#define QT_WIDGET_TABFOCUS Qt::TabFocus -#define QT_WIDGET_CLICKFOCUS Qt::ClickFocus -#define QT_WIDGET_STRONGFOCUS Qt::StrongFocus -#define QT_WIDGET_NOFOCUS Qt::NoFocus - -#define widgettypes_num (sizeof(widgettypes_tbl) / sizeof(widgettypes_tbl[0])) - -/* - @doc: widget - @keyterms: - widget object class - @title: - widget class - @type: - class - @short: - Base class for all widgets - @inherits: - [class]object[/class] - @description: - This object class is the rappresentation of a widget. - All the other widget-type classes inherit from this one. - @functions: - !fn: $show() - Shows this widget and the children. - See also [classfnc]$hide[/classfnc]() and [classfnc]$isVisible[/classfnc]. - !fn: $hide() - Hides this widget (and conseguently all the children). - See also [classfnc]$show[/classfnc]() and [classfnc]$isVisible[/classfnc]. - !fn: $repaint() - Repaints the widget directly by calling [classfnc]$paintEvent[/classfnc]() immediately.[br] - !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(