diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-17 00:43:50 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-17 00:43:50 +0000 |
commit | ceea23677c61f20759ae986bd77b0d5c4d673edb (patch) | |
tree | 3fcec1702eaf9c14d1dd736e594f5df08dab4001 /src | |
download | kbfx-ceea23677c61f20759ae986bd77b0d5c4d673edb.tar.gz kbfx-ceea23677c61f20759ae986bd77b0d5c4d673edb.zip |
Added old KDE3 version of kbfx
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kbfx@1091549 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src')
45 files changed, 6767 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..3e76368 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,62 @@ +SET(libkbfxspinxsrc + kbfxbutton.cpp + kbfxplasmacanvasabstractitem.cpp + kbfxplasmacanvasgroup.cpp + kbfxplasmacanvasgroupview.cpp + kbfxplasmacanvasitem.cpp + kbfxplasmacanvasitem_events.cpp + kbfxplasmacanvasitemwrapper.cpp + kbfxplasmacanvasstack.cpp + kbfxplasmacanvasview.cpp + kbfxplasmaindexitem.cpp + kbfxplasmaindexview.cpp + kbfxspinx.cpp + kbfxspinxmenu.cpp + kbfxspinxpopup.cpp + kbfxspinxscrollbar.cpp + kbfxspinxtoolbar.cpp + kbfxspinxtoolbutton.cpp + kbfxspinxtop.cpp + kbfxspinxview.cpp + kbfxtooltip.cpp + ) + +IF (NOT USE_KDE4) + KDE3_ADD_DCOP_SKELS(libkbfxspinxsrc kbfxspinx.h) + KDE3_AUTOMOC(${libkbfxspinxsrc}) + + ADD_LIBRARY(kbfxspinx MODULE ${libkbfxspinxsrc}) + SET_TARGET_PROPERTIES(kbfxspinx + PROPERTIES + COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) + # SET_TARGET_PROPERTIES(kbfxspinx PROPERTIES + # SOVERSION ${LIB_MAJOR} + # VERSION ${APPLICATION_VERSION}) + TARGET_LINK_LIBRARIES(kbfxspinx + kbfxdata + kbfxcommon + ${QT_AND_KDECORE_LIBS} + ${KDE3_UI_LIBRARY} + ) + + KDE3_INSTALL_LIBTOOL_FILE(kbfxspinx ${PLUGIN_INSTALL_DIR}) +ELSE (NOT USE_KDE4) + # TODO: Have to rewrite it for DBUS. + # Rewrite the DCOP interface (in src/) to DBUS for KDE4 support. + # Should be done in a way to preserve KDE3 compatibility! + KDE4_ADD_DCOP_SKELS(libkbfxspinxsrc kbfxspinx.h) + KDE4_AUTOMOC(${libkbfxspinxsrc}) + + KDE4_ADD_LIBRARY(kbfxspinx MODULE ${libkbfxspinxsrc}) + TARGET_LINK_LIBRARIES(kbfxspinx + kbfxdata + kbfxcommon + ${KDE4_KDECORE_LIBS} + ${KDE4_KDEUI_LIBS} + ) + + KDE4_INSTALL_LIBTOOL_FILE(kbfxspinx ${PLUGIN_INSTALL_DIR}) +ENDIF (NOT USE_KDE4) + +INSTALL(TARGETS kbfxspinx DESTINATION ${PLUGIN_INSTALL_DIR}) +INSTALL(FILES kbfxspinx.desktop DESTINATION ${DATA_INSTALL_DIR}/kicker/applets) diff --git a/src/kbfxbutton.cpp b/src/kbfxbutton.cpp new file mode 100644 index 0000000..5d3f8fd --- /dev/null +++ b/src/kbfxbutton.cpp @@ -0,0 +1,417 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include <config.h> + +#include "kbfxbutton.h" + + +bool KbfxButton::m_sizeHeight = TRUE; +int KbfxButton::m_size = 0; + +KbfxButton::KbfxButton ( QWidget * parent, const char *name) : + QLabel ( parent,name,Qt::WStaticContents | Qt::WNoAutoErase |Qt::WPaintDesktop ) +{ + setLineWidth ( 0 ); + setScaledContents ( false ); + setAcceptDrops ( true ); + m_dcopClient = new DCOPClient (); + m_dcopClient->attach (); + m_fadeTime = ConfigInit().m_fadeTime; + + /* Init normal size first */ + m_kicker_auto_adjust = TRUE; + loadSkins(); + m_kicker_auto_adjust = ConfigInit().m_ToolBarResize; + + m_toggle = false; + QTimer * timer = new QTimer ( this,"Update Timer" ); + connect ( timer,SIGNAL ( timeout() ),this,SLOT ( update() ) ); + timer->start ( 25,false ); + + fade_timer = new QTimer ( this,"Fade Timer" ); + connect ( fade_timer,SIGNAL ( timeout() ),this,SLOT ( fade() ) ); +} + +KbfxButton::~KbfxButton() +{ +} + +void KbfxButton::loadSkins() +{ + QImage _tmpHover, _tmpPressed, _tmpNormal; + _tmpHover = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_KbfxHoverButtonPath ) ) ? + QImage ( ConfigInit ().m_KbfxHoverButtonPath ) + : QImage ( ConfigInit ().m_KbfxHoverButtonPathDefault ); + _tmpPressed = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_KbfxPressedButtonPath ) ) ? + QImage ( ConfigInit ().m_KbfxPressedButtonPath ) + : QImage ( ConfigInit ().m_KbfxPressedButtonPathDefault ); + _tmpNormal = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_KbfxNormalButtonPath ) ) ? + QImage ( ConfigInit ().m_KbfxNormalButtonPath ) + : QImage ( ConfigInit ().m_KbfxNormalButtonPathDefault ); + + QSize _sizeNormal = _tmpNormal.size(); + _tmpHover = _tmpHover.smoothScale ( _sizeNormal, QImage::ScaleFree ); + _tmpPressed = _tmpPressed.smoothScale ( _sizeNormal, QImage::ScaleFree ); + + + if ( !m_kicker_auto_adjust ) + { + if ( m_sizeHeight ) + { + _tmpHover = _tmpHover.smoothScale ( _tmpHover.width(), m_size, QImage::ScaleMin ); + _tmpPressed = _tmpPressed.smoothScale ( _tmpPressed.width(), m_size, QImage::ScaleMin ); + _tmpNormal = _tmpNormal.smoothScale ( _tmpNormal.width(), m_size, QImage::ScaleMin ); + } + else + { + _tmpHover = _tmpHover.smoothScale ( m_size, _tmpHover.height(), QImage::ScaleMin ); + _tmpPressed = _tmpPressed.smoothScale ( m_size, _tmpPressed.height(), QImage::ScaleMin ); + _tmpNormal = _tmpNormal.smoothScale ( m_size, _tmpNormal.height(), QImage::ScaleMin ); + } + } + m_over_skin = QPixmap ( _tmpHover ); + m_normal_skin = QPixmap ( _tmpNormal ); + m_pressed_skin = QPixmap ( _tmpPressed ); + m_current_skin = m_normal_skin; + this->resize ( m_current_skin.width(),m_current_skin.height() ); + this->repaint(); +} + +QCString KbfxButton::findPanel() +{ + QCString m_AppletPanel = QCString ("kicker"); + QCStringList objects=m_dcopClient->remoteObjects("kicker"); + + for( QCStringList::ConstIterator it = objects.begin(); + it != objects.end(); + ++it) + { + if ( (*it).contains ( "Panel" ) > 0 ) + { + DCOPRef _dcop_obj ( "kicker", (*it) ); + QStringList _dcop_obj_applets =_dcop_obj.call ( "listApplets()" ); + + for ( QStringList::Iterator _it = _dcop_obj_applets.begin(); + _it != _dcop_obj_applets.end(); + _it++ ) + { + if ( ( *_it ).contains ( "kbfx" ) ) + { + m_AppletPanel = (*it); + break; + } + } + } + } + kdDebug () << "KBFX resides on panel: " << m_AppletPanel << endl; + return m_AppletPanel; +} + +void KbfxButton::readjust( bool _how ) +{ + /* _how = TRUE is for height, _how = FALSE is for width readjust */ + QCString _panel = findPanel(); + int _tmp_size; + if ( _how ) + { + _tmp_size = this->height (); + kdDebug () << "Readjusting " << _panel << " to height: " << _tmp_size << endl; + } + else + { + _tmp_size = this->width (); + kdDebug () << "Readjusting " << _panel << " to width: " << _tmp_size << endl; + } + QByteArray data; + QDataStream arg ( data, IO_WriteOnly ); + arg << _tmp_size ; + if ( !m_dcopClient->send ( "kicker", _panel, "setPanelSize(int)", data ) ) + kdWarning () + << "Could not send DCOP command to:" + << _panel + << endl; +} + +void KbfxButton::enterEvent ( QEvent * e ) +{ + e = e; + if ( m_toggle == true ) + { +// m_current_skin = m_pressed_skin; // no fade code + m_fadePix = m_pressed_skin; + } + else + { +// m_current_skin = m_over_skin; // no fade code + m_fadePix = m_over_skin; + + emit showToolTip (); + } + fade(); +} + +void KbfxButton::fade ( ) +{ + if ( m_fadeTime == 0 ) + { + m_current_skin = m_fadePix; + } + else + { + QImage _final = m_fadePix.convertToImage (); + QImage _current = m_current_skin.convertToImage (); + + if ( !fade_timer->isActive ()) + { + m_opacity = 0; + fade_timer->start( m_fadeTime, false); + } + if ( m_opacity > 0.9 ) + fade_timer->stop(); + m_opacity += 0.1; + + KImageEffect::blend ( _final, _current, m_opacity); + m_current_skin = QPixmap ( _current ); + } + this->resize ( m_current_skin.size() ); + this->update(); +} + +void KbfxButton::leaveEvent ( QEvent * e ) +{ + e = e; + + if ( m_toggle ) + { +// m_current_skin = m_pressed_skin; // no fade code + m_fadePix = m_pressed_skin; + } + else + { +// m_current_skin = m_normal_skin; // no fade code + m_fadePix = m_normal_skin; + } + fade(); + emit leave (); +} + +void KbfxButton::toggle() +{ + if (this->hasMouse() ) { + m_fadePix = m_over_skin; + }else { + + m_fadePix = m_normal_skin; + m_toggle = false; + } + fade(); +} + +void KbfxButton::toggleKMenu() +{ +// m_current_skin = m_normal_skin; + m_fadePix = m_normal_skin; + fade(); + m_toggle = false; +} + +void KbfxButton::mousePressEvent ( QMouseEvent * e ) +{ + e->accept(); + if ( e->button() == QMouseEvent::LeftButton ) + { + if ( m_toggle == false ) + { +// m_current_skin = m_pressed_skin; // no fade code + m_toggle = true; + m_fadePix = m_pressed_skin; + fade(); + emit pressed(); + } + else + { +// m_current_skin = m_normal_skin; // no fade code + m_toggle = false; + if (hasMouse() ) { + m_fadePix = m_over_skin; + }else { + + m_fadePix = m_normal_skin; + } + + fade(); + emit hideMenu(); + } + emit clicked (); + } + + if ( e->button() == QMouseEvent::RightButton ) + { + m_fadePix = m_normal_skin; + fade(); + m_toggle = false; + + QPopupMenu *popup = new QPopupMenu(); + + popup->insertItem ( SmallIcon ( "remove" ), i18n ( "Remove KBFX from Pannel" ), + this, SLOT ( selfDeleter() ) ); + popup->insertItem ( SmallIcon ( "reload" ),i18n ( "Reload KBFX" ), + this, SLOT ( reloadConfig() ) ); + popup->insertSeparator(); + popup->insertItem ( SmallIcon ( "kbfxconfigapp" ), i18n ( "Configure KBFX" ), + this, SLOT ( openConfigDialog() ) ); + popup->insertItem ( SmallIcon ( "kmenuedit" ),i18n ( "Edit Applications Menu" ), + this, SLOT ( openKmenuEdit() ) ); + popup->exec ( e->globalPos() ); + delete popup; + } +} + +void KbfxButton::reloadConfig() +{ +/* + DCOPRef m_kickerkbfxDevelnterface ( "kicker","KBFXInterface" ); + m_kickerkbfxDevelnterface.call ( "notifyConfigChange()" ); + m_kickerkbfxDevelnterface.call ( "notifyConfigChange()" ); +*/ + + DCOPRef m_kickerPanel("kicker", findPanel()); + m_kickerPanel.call("restart()"); +} + +void KbfxButton::selfDeleter() +{ + DCOPRef m_kickerPanel ( "kicker", findPanel() ); + QStringList returnQStringList =m_kickerPanel.call ( "listApplets()" ); + int _myIndex = 0; + + QStringList::Iterator it; + + for ( it = returnQStringList.begin();it != returnQStringList.end();it++ ) + { + if ( ( *it ).contains ( "kbfx" ) ) + { + break; + } + else + _myIndex++; + } + + m_kickerPanel.call ( "removeApplet(int)", _myIndex ); +} + +void KbfxButton::openKmenuEdit() +{ +#ifdef HAVE_MANDRAKE + KRun::runCommand ( "menudrake" ); +#else + KRun::runCommand ( "kmenuedit" ); +#endif +} + +void KbfxButton::openConfigDialog() +{ + KRun::runCommand ( "kbfxconfigapp" ); +} + +void KbfxButton::paintEvent ( QPaintEvent * pe ) +{ + + QPainter p; + if ( !m_current_skin.isNull () ) + { + QRect r = QRect ( pe->rect().x(),pe->rect().y(),m_current_skin.width(),m_current_skin.height() ); + m_buffer = new QPixmap(); + m_buffer->resize ( r.size() ); + m_buffer->fill ( this, r.topLeft() ); + + p.begin ( m_buffer,this ); + p.translate ( -r.x(), -r.y() ); + p.drawPixmap ( r,m_current_skin ); + p.end (); + bitBlt ( this, r.x(), r.y(),m_buffer, 0, 0,m_current_skin.width(), m_current_skin.height() ); + delete m_buffer; + } + +} + +void KbfxButton::dragEnterEvent ( QDragEnterEvent * e ) +{ + e->accept ( QUriDrag::canDecode ( e ) ); + kdDebug() << "Accepting KBFX button drag..." << endl; +} + +void KbfxButton::dropEvent ( QDropEvent * e ) +{ + QStringList filelist; + QString _hover, _normal, _pressed, _tmp; + QImage _hover_pix, _normal_pix, _pressed_pix; + QUriDrag::decodeLocalFiles ( e, filelist ); + + for ( QStringList::Iterator it = filelist.begin(); it != filelist.end(); ++it ) + { + _tmp = ( *it ); + kdDebug() << "KBFX button dropped file: " << _tmp << endl; + if ( _tmp.contains ( "hover", FALSE ) > 0 ) + { + _hover = _tmp; + _hover_pix = QImage ( _tmp ); + } + if ( _tmp.contains ( "normal", FALSE ) > 0 ) + { + _normal = _tmp; + _normal_pix = QImage ( _tmp ); + } + if ( _tmp.contains ( "pressed", FALSE ) > 0 ) + { + _pressed = _tmp; + _pressed_pix = QImage ( _tmp ); + } + } + + kdDebug() << "KBFX button hover: " << _hover << endl + << "KBFX button normal: " << _normal << endl + << "KBFX button pressed: " << _pressed << endl; + + if ( _hover_pix.isNull () || + _normal_pix.isNull () || + _pressed_pix.isNull () ) + { + KMessageBox::error ( 0, + tr2i18n ( "Invalid images were dropped!" + "\nCannot set the KBFX button to use these images!" ), + tr2i18n ( "Error setting KBFX button images" ) ); + return; + } + + ConfigInit ().m_KbfxNormalButtonPath = _normal; + ConfigInit ().m_KbfxHoverButtonPath = _hover; + ConfigInit ().m_KbfxPressedButtonPath = _pressed; + ConfigInit().writeThemerc ( ConfigInit().m_SpinxThemeName ); + + /* Init normal size first */ + m_kicker_auto_adjust = TRUE; + loadSkins(); + m_kicker_auto_adjust = ConfigInit().m_ToolBarResize; +} + +#include "kbfxbutton.moc" diff --git a/src/kbfxbutton.h b/src/kbfxbutton.h new file mode 100644 index 0000000..d4ece12 --- /dev/null +++ b/src/kbfxbutton.h @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_BUTTON_H +#define KBFX_BUTTON_H + +#include <qdragobject.h> +#include <qimage.h> +#include <qlabel.h> +#include <qpainter.h> +#include <qpixmap.h> +#include <qtimer.h> + +#include <dcopclient.h> +#include <dcopref.h> +#include <kdebug.h> +#include <kimageeffect.h> +#include <klocale.h> +#include <kmessagebox.h> +#include <kpopupmenu.h> +#include <krun.h> + +#include <kbfxconfig.h> +#include <kbfxplasmapixmapprovider.h> + + +class QPixmap; +class QLabel; + +class KbfxButton:public QLabel +{ + Q_OBJECT + + public: + KbfxButton ( QWidget * parent, const char * name = 0 ); + ~KbfxButton(); + void kbfx_vista_button_setFx ( bool choice ); + virtual void paintEvent ( QPaintEvent *pe ); + virtual void enterEvent ( QEvent * e ) ; + virtual void leaveEvent ( QEvent * e ); + virtual void mousePressEvent ( QMouseEvent * e ); + virtual void dropEvent ( QDropEvent *e ); + virtual void dragEnterEvent ( QDragEnterEvent *e ); + static bool m_sizeHeight; + static int m_size; + QCString findPanel(); + void readjust( bool ); + + public slots: + void loadSkins(); + void toggle(); + void toggleKMenu(); + void fade(); + void reloadConfig(); + void openKmenuEdit(); + void selfDeleter(); + void openConfigDialog(); + + signals: + void pressed(); + void hideMenu(); + void leave (); + void clicked (); + void showToolTip (); + + protected: + QPixmap m_over_skin; + QPixmap m_pressed_skin; + QPixmap m_release_skin; + QPixmap m_normal_skin; + QPixmap m_current_skin; + +// mng support ??? + QPixmap * m_buffer; + QTimer * m_anime_timer; + QMovie * m_normal_anime; + QMovie * m_pressed_anime; + QMovie * m_hover_anime; + QMovie * m_current_anime; + QString m_normal_path; + QString m_over_path; + QString m_pressed_path; + bool m_anime_on; + bool m_kicker_auto_adjust; + DCOPClient * m_dcopClient; + + /* state of the button */ + bool m_toggle; + QTimer * fade_timer; + float m_opacity; + QPixmap m_fadePix; + int m_fadeTime; +}; + +#endif diff --git a/src/kbfxplasmacanvasabstractitem.cpp b/src/kbfxplasmacanvasabstractitem.cpp new file mode 100644 index 0000000..4655765 --- /dev/null +++ b/src/kbfxplasmacanvasabstractitem.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +// +// C++ Implementation: kbfxplasmacanvasabstractitem +// +// Description: +// +// +// Author: Siraj Razick <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// + + +#include "kbfxplasmacanvasabstractitem.h" + + +KbfxPlasmaCanvasAbstractItem::KbfxPlasmaCanvasAbstractItem ( QCanvasPixmapArray * a, QCanvas * canvas ) + : QCanvasSprite ( a,canvas ) +{ + + m_source=0; +} + + +KbfxPlasmaCanvasAbstractItem::~KbfxPlasmaCanvasAbstractItem() +{} + +// void +// KbfxPlasmaCanvasAbstractItem::setSelected() +// { +// +// } + +void KbfxPlasmaCanvasAbstractItem::setCurrent ( bool state ) +{ + m_current = state; +} + + +bool +KbfxPlasmaCanvasAbstractItem::isCurrent() +{ + return m_current; +} + +void +KbfxPlasmaCanvasAbstractItem::mousePressEvent ( QMouseEvent * e ) +{ + e = e; +} +void +KbfxPlasmaCanvasAbstractItem::mouseMoveEvent ( QMouseEvent * e ) +{ + e = e; +} + +void +KbfxPlasmaCanvasAbstractItem::enterEvent ( QEvent * e ) +{ + e =e ; +} + + +void KbfxPlasmaCanvasAbstractItem::mouseReleaseEvent ( QMouseEvent * e ) +{ + e =e ; + emit clicked(); +} + +void KbfxPlasmaCanvasAbstractItem::exec() +{ + if ( m_source == 0 ) + return; + + + m_source->exec(); +} + + +void KbfxPlasmaCanvasAbstractItem::hideit() +{ + this->hide(); +} + +void +KbfxPlasmaCanvasAbstractItem::draw ( QPainter& pe ) +{ + this->drawContent ( &pe ); +} + + +void KbfxPlasmaCanvasAbstractItem::setLabelText ( QString s ) +{ + s = s; +} + +QPixmap +KbfxPlasmaCanvasAbstractItem::dragPixmap() +{ + return QPixmap(); +} + +void +KbfxPlasmaCanvasAbstractItem::drawContent ( QPainter * p ) +{ + p = p ; +} + +#include "kbfxplasmacanvasabstractitem.moc" diff --git a/src/kbfxplasmacanvasabstractitem.h b/src/kbfxplasmacanvasabstractitem.h new file mode 100644 index 0000000..7110486 --- /dev/null +++ b/src/kbfxplasmacanvasabstractitem.h @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_PLASMA_CANVAS_ABSTRACT_ITEM_H +#define KBFX_PLASMA_CANVAS_ABSTRACT_ITEM_H + +#include <qcanvas.h> +#include <qpainter.h> +#include "kbfxplasmacanvasrtti.h" +#include <qtimer.h> +#include <kdesktopfile.h> +#include <kstandarddirs.h> +#include <kiconloader.h> +#include "kbfxdatasource.h" +#include <krun.h> + +class KbfxPlasmaCanvasAbstractItem:public QObject,public QCanvasSprite +{ + + Q_OBJECT + + public: + typedef enum {EXECUTABLE=0,SEPARATOR,INDEX,OTHER} Type; +// typedef enum {RASTER=0,VECTOR,NATIVE} SkinMode; + + KbfxPlasmaCanvasAbstractItem ( QCanvasPixmapArray * a, QCanvas * canvas ); + virtual ~KbfxPlasmaCanvasAbstractItem (); + + void setCurrent ( bool ); + virtual Type type() { return m_type; } + virtual void setType ( Type t ) { m_type = t;} + + QString name() { if ( m_source != 0 ) return m_source->name(); else return QString ( "Not Set" );}; + + void setSource ( KbfxDataSource src ); + bool isCurrent(); + virtual int height() { return m_height;} + + virtual int width() { return m_width;} + + virtual bool lookup ( QString str ) {str = str ; return false;} + + virtual int rtti() const { return CANVASITEM;} + + virtual void draw ( QPainter & pe ); + + virtual void drawContent ( QPainter * pe ); + + virtual QPixmap dragPixmap(); + + +//Event Handling + virtual void mousePressEvent ( QMouseEvent * e ); + virtual void mouseMoveEvent ( QMouseEvent * e ); + virtual void enterEvent ( QEvent * e ); + virtual void mouseReleaseEvent ( QMouseEvent * e ); + + + virtual void setLabelText ( QString s ); + + public slots: + virtual void hideit(); + virtual void exec(); + signals: + void clicked(); + void leave(); + void selected ( KbfxPlasmaCanvasAbstractItem* ); + + private: + +// KbfxPlasmaCanvasAbstractItem (const KbfxPlasmaCanvasItem &t); + KbfxDataSource * m_source; + Type m_type; + int m_height; + int m_width; + bool m_current; + + + + +} +;//C.G + +#endif //M.I.G + diff --git a/src/kbfxplasmacanvasgroup.cpp b/src/kbfxplasmacanvasgroup.cpp new file mode 100644 index 0000000..044fc18 --- /dev/null +++ b/src/kbfxplasmacanvasgroup.cpp @@ -0,0 +1,330 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxplasmacanvasgroup.h" + +KbfxPlasmaCanvasGroup::KbfxPlasmaCanvasGroup () +{ + + m_height = 0; + m_id = 0; +// m_count = 0; + m_name = QString ( "Unknown" ); +// bool m_visible = true; + m_shaded = false; +} + +KbfxPlasmaCanvasGroup::~KbfxPlasmaCanvasGroup () +{ + for ( ItemListIter it ( m_itemList ); *it; ++it ) + { +//qDebug("Trying to delete Item from Rgoup================"); +// if(*it) +// delete (*it); +// itemListMap ().remove (*it); + if ( ( *it ) != 0 ) + if ( deleteItem ( ( *it ) ) == false ) + { + qDebug ( "Deleting failed" ); + } + } + + +} + +KbfxPlasmaCanvasGroup::ItemListMap & KbfxPlasmaCanvasGroup::itemListMap () +{ + static ItemListMap * + map = 0; + if ( !map ) + map = new ItemListMap (); + return *map; +} + +bool +KbfxPlasmaCanvasGroup::deleteItem ( KbfxPlasmaCanvasAbstractItem * it ) +{ +//qDebug("Removing Item from Group"); +// itemListMap ().remove (it); + //delete it; +//return true; + for ( ItemListIter iti ( m_itemList ); *iti; ++iti ) + { + if ( iti == it ) + { + itemListMap ().remove ( *iti ); + if ( m_itemList.removeRef ( it ) ) + { + if ( m_itemList.isEmpty () ) + delete this; + return true; + } + else + { + qDebug ( "deleting Item failed" ); + return false; + } + } + } + return false; +} + +bool +KbfxPlasmaCanvasGroup::addItem ( KbfxPlasmaCanvasAbstractItem * it ) +{ + + if ( it->name().isEmpty() ) + { + qDebug ( "Adding Failed bcos Name Missing" ); + return false; + } + ItemListMap::ConstIterator itn = itemListMap ().find ( it ); + if ( itn != itemListMap ().end () ) + { + qDebug ( "Adding Failed Due to Item not end" ); + return false; + } + for ( ItemListIter itr ( m_itemList ); *itr; ++itr ) + { + if ( ( *itr )->lookup ( it->name() ) == true ) + { + qDebug ( "Adding Failed Due to Item already exisits" ); + return false; + } + } + + + int _x = 0; + int _y = this->boundingRect ().height (); + KbfxPlasmaCanvasGroup *&group = itemListMap () [it]; + if ( group ) + { + if ( group == this ) + return true; + group->m_itemList.removeRef ( it ); + if ( group->m_itemList.isEmpty () ) + delete group; + } + m_itemList.prepend ( it ); + m_height += it->height(); + m_width = it->width(); + it->move ( _x, _y ); + group = this; + + if ( it->type() == KbfxPlasmaCanvasAbstractItem::SEPARATOR ) + m_sepheight = it->height(); + m_count++; + return true; +} + + +void +KbfxPlasmaCanvasGroup::move ( int x, int y ) +{ + + for ( ItemListIter it ( m_itemList ); *it; ++it ) + { + ( *it )->move ( ( *it )->x () + x, ( *it )->y () + y ); + } + + +} + +void +KbfxPlasmaCanvasGroup::moveBy ( int x, int y ) +{ + + for ( ItemListIter it ( m_itemList ); *it; ++it ) + { + ( *it )->move ( x, y ); + } +} + +void +KbfxPlasmaCanvasGroup::hide() +{ + + for ( ItemListIter it ( m_itemList ); *it; ++it ) + { +// if(*it) + ( *it )->hide(); + } + m_visible = false; + + +} + +void +KbfxPlasmaCanvasGroup::setGroupName ( QString name ) +{ + m_name = name; + delete [] name; +} + +QString +KbfxPlasmaCanvasGroup::name() +{ + return m_name; +} + +void +KbfxPlasmaCanvasGroup::showAll() +{ + for ( ItemListIter it ( m_itemList ); *it; ++it ) + { + if ( ( *it )->type() == KbfxPlasmaCanvasAbstractItem::SEPARATOR || m_shaded == false ) + ( *it )->show(); + } + +} + +void +KbfxPlasmaCanvasGroup::show() +{ + for ( ItemListIter it ( m_itemList ); *it; ++it ) + { + if ( ( *it )->type() == KbfxPlasmaCanvasAbstractItem::SEPARATOR || m_shaded == false ) + ( *it )->show(); + } + m_visible = true; +} + +void +KbfxPlasmaCanvasGroup::shade () +{ + if ( m_shaded == false ) + { + emit this->groupShade ( this->groupID() ); + + for ( ItemListIter it ( m_itemList ); *it; ++it ) + { + // (*it)->move ((*it)->x (), 0); + if ( ( *it )->type() != KbfxPlasmaCanvasAbstractItem::SEPARATOR ) + ( *it )->hide(); + } + m_shaded = true; + return; + } + else if ( m_shaded == true ) + { + int _shadeby = 0; + int _firstItemHeight=0; + + emit this->groupUnShade ( this->groupID() ); + + for ( ItemListIter it ( m_itemList ); *it; ++it ) + { + if ( ( *it )->type() != KbfxPlasmaCanvasAbstractItem::SEPARATOR ) + { +// (*it)->move ((*it)->x (), _shadeby); + ( *it )->show(); + _shadeby += ( *it )->height (); + } + else + { + _shadeby = ( *it )->height (); + _firstItemHeight = _shadeby; + + } + } + m_shaded = false; + } +} + +void +KbfxPlasmaCanvasGroup::moveUp ( int y ) +{ + + for ( ItemListIter it ( m_itemList ); *it; ++it ) + { + ( *it )->move ( ( *it )->x (), ( ( *it )->y () +m_sepheight ) - y ); + } + + +} + +void +KbfxPlasmaCanvasGroup::moveDown ( int y ) +{ + + for ( ItemListIter it ( m_itemList ); *it; ++it ) + { + ( *it )->move ( ( *it )->x (), ( ( *it )->y () - m_sepheight ) + y ); + } +} + +QRect +KbfxPlasmaCanvasGroup::boundingRect () +{ + if ( this->count () == 0 ) + return QRect ( 0, 0, 0, 0 ); + + QRect r; + for ( ItemListIter it ( m_itemList ); *it; ++it ) + r |= ( *it )->boundingRect (); + return r; +} + +int +KbfxPlasmaCanvasGroup::count () +{ + + return m_itemList.count(); +} + +int +KbfxPlasmaCanvasGroup::height () +{ + + return m_height ; +} + +int +KbfxPlasmaCanvasGroup::width () +{ + + return m_width; +} + + +KbfxPlasmaCanvasGroup * +KbfxPlasmaCanvasGroup::groupContaining ( KbfxPlasmaCanvasAbstractItem * item ) +{ + ItemListMap::ConstIterator it = itemListMap ().find ( item ); + if ( it == itemListMap ().end () ) + return 0; + else + return *it; +} + +uint +KbfxPlasmaCanvasGroup::groupID() +{ + return m_id; +} + + +void KbfxPlasmaCanvasGroup::setGroupID ( uint e_id ) +{ + m_id = e_id; +} + +#include "kbfxplasmacanvasgroup.moc" diff --git a/src/kbfxplasmacanvasgroup.h b/src/kbfxplasmacanvasgroup.h new file mode 100644 index 0000000..1d6e2da --- /dev/null +++ b/src/kbfxplasmacanvasgroup.h @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_PLASMA_CANVAS_GROUP_H +#define KBFX_PLASMA_CANVAS_GROUP_H + +#include <qmap.h> +#include <qptrlist.h> +#include "kbfxplasmacanvasabstractitem.h" +#include <qobject.h> +class QCanvasItem; +class QRect; + +class KbfxPlasmaCanvasGroup:public QObject +{ + + Q_OBJECT + public: + typedef QPtrList<KbfxPlasmaCanvasAbstractItem> ItemList; + typedef QPtrListIterator<KbfxPlasmaCanvasAbstractItem> ItemListIter; + //a Global mapof Groups + typedef QMap<KbfxPlasmaCanvasAbstractItem*,KbfxPlasmaCanvasGroup*> ItemListMap; + + KbfxPlasmaCanvasGroup(); + virtual ~KbfxPlasmaCanvasGroup(); + + bool addItem ( KbfxPlasmaCanvasAbstractItem * ); + bool deleteItem ( KbfxPlasmaCanvasAbstractItem * ); + void move ( int x,int y ); + void moveBy ( int x,int y ); + QString name(); + QRect boundingRect(); + int count(); + int height(); + int width(); + static KbfxPlasmaCanvasGroup * groupContaining ( KbfxPlasmaCanvasAbstractItem * ); + QString groupName(); + uint groupID(); + void setGroupName ( QString name ); + void setGroupID ( uint ); + bool isShaded() {return m_shaded;}; + virtual int rtti() { return 1005;} + void showAll(); + + public slots: + void moveUp ( int ); + void moveDown ( int ); + void shade();//folding action + void hide(); + void show(); + signals: + void groupShade ( uint id ); + void groupUnShade ( uint id ); + + + + private : + ItemList m_itemList; + static ItemListMap& itemListMap(); + int m_x; + int m_y; + int m_height; + int m_width; +//state variables + bool m_shaded; + bool m_visible; + QString m_name; + uint m_id; + int m_sepheight; + int m_count; + + +}; + + + +#endif diff --git a/src/kbfxplasmacanvasgroupview.cpp b/src/kbfxplasmacanvasgroupview.cpp new file mode 100644 index 0000000..04c7f8e --- /dev/null +++ b/src/kbfxplasmacanvasgroupview.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxplasmacanvasgroupview.h" + +KbfxPlasmaCanvasGroupView::KbfxPlasmaCanvasGroupView () +{ + m_groupChain.setAutoDelete ( true ); + m_count = 0; + m_height = 0; + m_width = 0; + m_name = QString ( "Unkown" ); + m_fullExpand = false; + +} + +KbfxPlasmaCanvasGroupView::~KbfxPlasmaCanvasGroupView () +{ +// delete [] m_name; + for ( uint i = 0; i < m_groupChain.count (); ++i ) + { + m_groupChain.at ( i )->~KbfxPlasmaCanvasGroup(); + m_groupChain.remove ( m_groupChain.at ( i ) ); + } + +} + +void +KbfxPlasmaCanvasGroupView::addGroup ( KbfxPlasmaCanvasGroup * gPtr ) +{ + if ( gPtr == NULL ) + { + qDebug + ( "KbfxPlasmaCanvasGroupView.cpp:39:Null Pointer Passed to addGroup()" ); + return; + } + else + { + gPtr->setGroupID ( ( uint ) m_count ); + m_height+= gPtr->height(); + m_width = gPtr->width(); + gPtr->move ( 0,m_height-gPtr->height() ); + m_groupChain.append ( gPtr ); +// gPtr->show(); +// qDebug("adding Groupy"); + m_count++; + connect ( gPtr, SIGNAL ( groupShade ( uint ) ), this, + SLOT ( foldGroup ( uint ) ) ); + connect ( gPtr, SIGNAL ( groupUnShade ( uint ) ), this, + SLOT ( unFoldGroup ( uint ) ) ); + + + } + + +} + +KbfxPlasmaCanvasGroupView * +KbfxPlasmaCanvasGroupView::contains ( KbfxPlasmaCanvasGroup * ) +{ +//maybe I don't need this + return 0; + +} + +void +KbfxPlasmaCanvasGroupView::setName ( QString name ) +{ + m_name = name; + //delete [] name; +} + +QString +KbfxPlasmaCanvasGroupView::name() +{ + return m_name; +} + + +void +KbfxPlasmaCanvasGroupView::foldGroupAll () +{ +///not too many groups and needs fast shading so ...this + + for ( uint i = 0; i < m_groupChain.count (); ++i ) + { + if ( m_groupChain.at ( i ) ) + if ( !m_groupChain.at ( i )->isShaded() ) + m_groupChain.at ( i )->shade (); + } + + m_fullExpand = true; +} + +void +KbfxPlasmaCanvasGroupView::unfoldGroupAll () +{ +///not too many groups and needs fast shading so ...this + + for ( uint i = 0; i < m_groupChain.count (); ++i ) + { + if ( m_groupChain.at ( i ) ) + if ( m_groupChain.at ( i )->isShaded() ) + m_groupChain.at ( i )->shade (); + } + + m_fullExpand = true; +} + +void +KbfxPlasmaCanvasGroupView::hide () +{ + + for ( uint i = 0; i < m_groupChain.count (); ++i ) + { + if ( m_groupChain.at ( i ) ) +// if( m_groupChain.at (i)->isShaded()) + m_groupChain.at ( i )->hide(); + } + +} + + +void +KbfxPlasmaCanvasGroupView::show() +{ + + for ( uint i = 0; i < m_groupChain.count (); ++i ) + { +// if (m_groupChain.at (i)) +// if( m_groupChain.at (i)->isShaded()) +/// unFoldGroup(i); + + m_groupChain.at ( i )->show(); + ///qDebug("Showing group %d",i); + } + +} + + +void +KbfxPlasmaCanvasGroupView::foldGroup ( uint e_id ) +{ + + KbfxPlasmaCanvasGroup *_it; + KbfxPlasmaCanvasGroup *_et = m_groupChain.at ( e_id ); + if ( _et == NULL ) + return; + + int _height = _et->height (); + //int _shadestate = _et->isShaded (); + + for ( _it = m_groupChain.first (); _it; _it = m_groupChain.next () ) + { + if ( e_id != _it->groupID () ) + { + if ( _it->groupID () > e_id ) + { + _it->moveUp ( _height ); + + } + + } + } + +} + +void +KbfxPlasmaCanvasGroupView::unFoldGroup ( uint e_id ) +{ + KbfxPlasmaCanvasGroup *_it; + KbfxPlasmaCanvasGroup *_et = m_groupChain.at ( e_id ); + if ( _et == NULL ) + { + qDebug ( "OOps no such groups can't unfold" ); + return; + } + + int _height = _et->height (); + //int _shadestate = _et->isShaded (); + + for ( _it = m_groupChain.first (); _it; _it = m_groupChain.next () ) + { + if ( e_id != _it->groupID () ) + { + if ( _it->groupID () > e_id ) + { + _it->moveDown ( _height ); + } + + } + } +} + +#include "kbfxplasmacanvasgroupview.moc" diff --git a/src/kbfxplasmacanvasgroupview.h b/src/kbfxplasmacanvasgroupview.h new file mode 100644 index 0000000..2f79e2c --- /dev/null +++ b/src/kbfxplasmacanvasgroupview.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_PLASMA_CANVAS_GROUP_VIEW_H +#define KBFX_PLASMA_CANVAS_GROUP_VIEW_H + +#include <qobject.h> +#include <qptrlist.h> +#include "kbfxplasmacanvasgroup.h" + +/** +This class will manager a list of Groups. +**/ + + +class KbfxPlasmaCanvasGroupView:public QObject +{ + + Q_OBJECT + + public: + typedef QPtrList<KbfxPlasmaCanvasGroup> groupPtrList; + + KbfxPlasmaCanvasGroupView(); + virtual ~KbfxPlasmaCanvasGroupView(); + + void addGroup ( KbfxPlasmaCanvasGroup* ); + void deleteGroup ( KbfxPlasmaCanvasGroup* ); + KbfxPlasmaCanvasGroupView* contains ( KbfxPlasmaCanvasGroup* ); + virtual int rtti() {return 1006;} + void predend ( KbfxPlasmaCanvasGroup* ); + void append ( KbfxPlasmaCanvasGroup * ); + int height() + { + return m_height; + } + int width() + { + return m_width; + } + void setName ( QString name ); + QString name(); + bool expanded() { return m_fullExpand;} + public slots: + void foldGroupAll(); + void unfoldGroupAll(); + void hide(); + void show(); + void foldGroup ( uint id ); + void unFoldGroup ( uint id ); + + private: + int m_x; + int m_y; + int m_z; //depth index : not Z axis + int m_count; + int m_height; + int m_width; + bool m_fullExpand; + QString m_name; + QString m_iconPath; + KbfxPlasmaCanvasGroup * m_current; + groupPtrList m_groupChain; + //state variables + +}; + +#endif diff --git a/src/kbfxplasmacanvasitem.cpp b/src/kbfxplasmacanvasitem.cpp new file mode 100644 index 0000000..4a5824f --- /dev/null +++ b/src/kbfxplasmacanvasitem.cpp @@ -0,0 +1,401 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxplasmacanvasitem.h" + +KbfxPlasmaCanvasItem::KbfxPlasmaCanvasItem ( QCanvasPixmapArray * a , QCanvas * canvas ) :KbfxPlasmaCanvasAbstractItem ( a, canvas ) +{ + this->setItemMode ( 1 ); + setAnimated ( false ); + m_desktopFile = 0L; + m_isCurrent = false; +// m_pixmapArray = a; + QPixmap * _img = this->image ( 0 ); + m_commentText ="No Comment Set By Plugin"; + m_height =_img->height(); + m_width =_img->width(); + connect ( this,SIGNAL ( clicked() ),this,SLOT ( exec() ) ); + m_type = OTHER; +// ConfigInit().read(); + m_noComments = ConfigInit().m_noComments; + m_source = 0; + m_margin = ConfigInit().m_commentMargine; + m_lineColor = ConfigInit().m_lineColor; + m_iconSize = ConfigInit().m_iconSize; + m_commentColor = ConfigInit().m_fontAppCommentColor; + m_commentFont = ConfigInit().m_fontAppCommentFont; + m_fontAppNameColor = ConfigInit().m_fontAppNameColor; + m_fontAppNameFont = ConfigInit().m_fontAppNameFont; + m_sepNameFont = ConfigInit().m_sepNameFont; + m_boldFonts = ConfigInit().m_fontHoverBold; + +} + +KbfxPlasmaCanvasItem::~KbfxPlasmaCanvasItem() +{ + setCanvas ( 0L ); +} +/* +QCanvasPixmapArray * KbfxPlasmaCanvasItem::getPixmapArray() +{ + return m_pixmapArray; + +} +*/ +void +KbfxPlasmaCanvasItem::setLabelText ( QString str ) +{ + + QFont * _font = new QFont ( m_fontAppNameFont ); + + QFontMetrics fm ( *_font ); + + int _commentWidth = fm.width ( str+"..." ); + int _strLen = str.length(); + if ( _commentWidth > ( this->width() - m_margin ) ) + { + + for ( int i = 0; i < _strLen /*&& ( fm.width(str+"...") < width()-40 )*/ ;i++ ) + { + str.truncate ( str.length()-2 ); + if ( fm.width ( str+"..." ) < width() - m_margin ) + break; + + } + str+="..."; + } + + m_labelText = str ; +} + + +bool +KbfxPlasmaCanvasItem::lookup ( QString str ) +{ + + if ( str.isNull() ) + return false; + + if ( m_type == SEPARATOR || m_type == INDEX ) + return false; + + if ( m_labelText.contains ( str,false ) > 0 ) + return true; + if ( m_commentText.contains ( str,false ) > 0 ) + return true; + if ( m_exec.contains ( str,false ) >0 ) + return true; + + + return false; +} + +void +KbfxPlasmaCanvasItem::setExec ( QString desktopfile ) +{ + m_desktopFile = new KDesktopFile ( desktopfile ); + m_desktopFilePath = desktopfile; + bool check = m_desktopFile->isAuthorizedDesktopFile ( desktopfile ); + + setLabelText ( m_desktopFile->readName() ); + setComment ( m_desktopFile->readComment() ); + setIconPath ( m_desktopFile->readIcon() ); + + if ( check == 0 ) + { + m_restricted = true; + m_error = "Adiministrator Blocked"; + delete m_desktopFile; + return ; + } + delete m_desktopFile; +} + +void +KbfxPlasmaCanvasItem::setIconPath ( QString str ) +{ + KIconLoader *iconload = KGlobal::iconLoader (); + m_iconPath = iconload->iconPath ( str, KIcon::Desktop, false ); +// m_icon.load(m_iconPath); + QImage _img ( m_iconPath ); + + if ( _img.height() > 128 ) + { + _img = _img.smoothScale ( 32,32 ); + + } + + m_icon.convertFromImage ( _img ); + +} + +void +KbfxPlasmaCanvasItem::setIcon ( QPixmap pixmap ) +{ + m_icon = pixmap; + +} + + +void +KbfxPlasmaCanvasItem::setSource ( KbfxDataSource src ) +{ + + + m_source = new KbfxDataSource(); + *m_source = src; + if ( src.type() == KbfxDataSource::DESKTOP ) + { + this->setExec ( src.desktopFile () ); + } + else + { + setLabelText ( src.name() ); + setName ( src.name() ); + setComment ( src.comment() ); + setIconPath ( src.icon() ); + + } + +} + +void +KbfxPlasmaCanvasItem::hideit () +{ + + m_hidden = 0; + this->hide (); +} + + +void +KbfxPlasmaCanvasItem::setType ( Type t ) +{ + m_type = t; +} + +bool KbfxPlasmaCanvasItem::itemMode () +{ + return m_skined; +} + +void +KbfxPlasmaCanvasItem::setItemMode ( bool mode ) +{ + m_skined = mode; +} + + + +void +KbfxPlasmaCanvasItem::drawBackDrop ( QPainter * pe,QRect & r ) +{ + r = r ; + if ( pe == NULL ) + return ; +} + + + + +/* +void +KbfxPlasmaCanvasItem::drawText(QPainter * pe,QString str) +{ + + +} +*/ + +void +KbfxPlasmaCanvasItem::draw ( QPainter & pe ) +{ + drawContent ( &pe ); +} + +QPixmap +KbfxPlasmaCanvasItem::dragPixmap() +{ + double _x = x(); + double _y = y(); + setX ( 0.0 ); + setY ( 0.0 ); + QPixmap dragpixmap ( this->width(),this->height() ); + dragpixmap.fill ( QColor ( 255,255,255 ) ); + QPainter p; + p.begin ( &dragpixmap ); + this->drawContent ( &p ); + p.end(); + setX ( _x ); + setY ( _y ); + return dragpixmap; + +} + +void +KbfxPlasmaCanvasItem::drawContent ( QPainter * pe ) +{ + if ( m_isCurrent ) + { + this->setFrame ( 1 ); + } + else + { + this->setFrame ( 0 ); + } +//int _currentFrame = + QCanvasPixmap *cp = this->image ( this->frame () ); + m_height = cp->height(); + m_width = cp->width(); +//Draw the Background + if ( m_skined == true ) + { + + pe->drawPixmap ( this->boundingRect (), *cp ); + + } + else + { + pe->setPen ( QColor ( 91,178,62 ) ); + pe->drawRect ( this->boundingRect() ); + pe->setPen ( QColor ( 0,10,0 ) ); + } + + + /** + We will split the Item box into two + **/ + + QRect tmp ( 0,0,0,0 ); +//TODO: Should be read from kbfxconfig.cpp + + + +// + + QRect * rectTop = new QRect ( m_margin, ( int ) y(), cp->width() - m_margin, cp->height() /2 ); + QRect * rectBot = new QRect ( m_margin, ( int ) y() + rectTop->height(), cp->width() - m_margin, cp->height() /2 ); + + +///Draw Icon + +//TODO::remover hard coded icon size : read from config + + if ( !m_isCurrent ) + pe->drawPixmap ( QRect ( ( m_margin-m_iconSize ) /2, ( int ) y() + ( cp->height()-m_iconSize ) /2,m_iconSize,m_iconSize ),m_icon ); + else + pe->drawPixmap ( QRect ( ( m_margin-m_iconSize ) /2, ( int ) y() + ( cp->height()-m_iconSize ) /2,m_iconSize+2,m_iconSize+2 ),m_icon ); +//End of DrawIcon + + + QFont * _font = new QFont ( m_fontAppNameFont ); + QFont * _font_comment = new QFont ( m_commentFont ); + QFont * _font_separator = new QFont ( m_sepNameFont ); + pe->setFont ( *_font ); + + if ( this->type() == EXECUTABLE ) + { + pe->setPen ( m_fontAppNameColor ); + if ( m_noComments == false ) + { + if ( m_isCurrent && m_boldFonts == true ) { _font->setBold ( true );pe->setFont ( *_font ); } + pe->drawText ( *rectTop, Qt::AlignLeft| Qt::AlignBottom ,QString ( m_labelText ), -1, &tmp,0 ); + pe->setPen ( m_lineColor ); + pe->drawLine ( m_margin, ( int ) y() + rectTop->height(), ( int ) cp->width() - 2, ( int ) y() + rectTop->height() ); + pe->setFont ( *_font_comment ); + pe->setPen ( m_commentColor ); + pe->drawText ( *rectBot, Qt::AlignLeft| Qt::AlignTop ,QString ( m_commentText ), -1, &tmp,0 ); + } + else + { + pe->drawText ( QRect ( m_margin+1, ( int ) y()+1,cp->width(),cp->height() ), Qt::AlignLeft | Qt::AlignVCenter ,QString ( m_labelText ), -1, &tmp,0 ); +// pe->drawText ( QRect ( m_margin, ( int ) y(),cp->width(),cp->height() ), Qt::AlignLeft | Qt::AlignVCenter ,QString ( m_labelText ), -1, &tmp,0 ); + } + } + else + { + if ( this->type() == SEPARATOR ) + { + pe->setFont ( *_font_separator ); + pe->setPen ( ConfigInit().m_sepNameColor ); + } + else + { + pe->setPen ( m_fontAppNameColor ); + } + pe->drawText ( QRect ( ( int ) x(), ( int ) y(),cp->width(),cp->height() ), Qt::AlignCenter ,QString ( m_labelText ), -1, &tmp,0 ); + + } + +///Draw the line + + + delete rectTop; + delete rectBot; + delete _font; + delete _font_comment; + delete _font_separator; +} + + +void::KbfxPlasmaCanvasItem::setComment ( QString str ) +{ + + + QFont * _font = new QFont ( m_commentFont ); + + QFontMetrics fm ( *_font ); + + int _commentWidth = fm.width ( str+"..." ); + int _strLen = str.length(); + if ( _commentWidth > ( this->width()-m_margin ) ) + { + + for ( int i = 0; i < _strLen /*&& ( fm.width(str+"...") < width()-40 )*/ ;i++ ) + { + str.truncate ( str.length()-2 ); + if ( fm.width ( str+"..." ) < width()-m_margin ) + break; + + } + str+="..."; + } + + m_commentText = str; +} + + +void +KbfxPlasmaCanvasItem::advance ( int phase ) +{ + if ( phase == 0 ) + { + setXVelocity ( 0 ); + setYVelocity ( yVelocity () * 1 - 0.001 ); + } + else + { + move ( x () + xVelocity (), y () + yVelocity () ); + } +} + +#include "kbfxplasmacanvasitem.moc" + diff --git a/src/kbfxplasmacanvasitem.h b/src/kbfxplasmacanvasitem.h new file mode 100644 index 0000000..92f1047 --- /dev/null +++ b/src/kbfxplasmacanvasitem.h @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_PLASMA_CANVAS_ITEM_H +#define KBFX_PLASMA_CANVAS_ITEM_H + +#include <qcanvas.h> +#include <qfont.h> +#include <qfontinfo.h> +#include <qimage.h> + +#include <kapplication.h> +#include <kdebug.h> +#include <kdesktopfile.h> + +#include <kbfxconfig.h> +#include <kbfxplasmapixmapprovider.h> + +#include "kbfxplasmacanvasabstractitem.h" + + +class KbfxPlasmaCanvasItem:public KbfxPlasmaCanvasAbstractItem +{ + + Q_OBJECT + + public: + +// typedef enum {EXECUTABLE=0,SEPARATOR,INDEX,OTHER} Type; + typedef enum {RASTER=0,VECTOR,NATIVE} SkinMode; + + + KbfxPlasmaCanvasItem ( QCanvasPixmapArray * a, QCanvas * canvas ); + KbfxPlasmaCanvasItem ( const KbfxPlasmaCanvasItem &t ); + KbfxPlasmaCanvasItem &operator = ( const KbfxPlasmaCanvasItem &t ); + virtual ~KbfxPlasmaCanvasItem (); + + bool itemMode(); + void setItemMode ( bool mode=true ); + void setType ( Type ); + void setCurrent ( bool ); + void setExec ( QString desktopfile ); + QString name() {return m_labelText;}; + QString desktopFile() { return m_desktopFilePath;} + + + KbfxDataSource * source() { return m_source;} + void setSource ( KbfxDataSource src ); + void setCommand ( QString cmd ); + void setComment ( QString comment ); + void setIcon ( QPixmap pixmap ); + void setIconPath ( QString path ); + bool isCurrent(); + int height() { return m_height;} + int width() { return m_width;} + Type type() { return m_type;} + bool lookup ( QString str ); + virtual void advance ( int phase ); + virtual int rtti() const { return CANVASITEM;} + virtual void draw ( QPainter & pe ); + virtual void drawContent ( QPainter * pe ); + virtual QPixmap dragPixmap(); + +// virtual void drawText(QPainter *pe,QString str); + virtual void drawBackDrop ( QPainter * pe,QRect & rect ); + + /* Event Handling */ + virtual void mousePressEvent ( QMouseEvent * e ); + virtual void mouseMoveEvent ( QMouseEvent * e ); + virtual void enterEvent ( QEvent * e ); + virtual void mouseReleaseEvent ( QMouseEvent * e ); + + + void setLabelText ( QString s ); + + public slots: + void updateAngle() {} + void hideit(); + void exec(); + signals: + void leave(); + void selected ( KbfxPlasmaCanvasItem* ); + + private: + + + void drawStar ( QPainter * pe ); + + int m_frameCount; + int m_textWidth; + QString m_exec; + QString m_desktopFilePath; + QString m_labelText; + QString m_commentText; + QPixmap m_icon; + QString m_iconPath; + KDesktopFile * m_desktopFile; + KbfxDataSource * m_source; + + /* Theming stuff */ + QColor m_fontAppNameColor; + QFont m_fontAppNameFont; + QColor m_commentColor; + QFont m_commentFont; + QColor m_lineColor; + QFont m_sepNameFont; + bool m_boldFonts; + bool m_skined; + bool m_restricted ; //KDE kiosk + Type m_type; + bool m_hidden; + QString m_error; + bool m_isCurrent; + bool m_noComments; + int m_margin; + int m_height; + int m_width; + int m_iconSize; +} +;//C.G + +#endif //M.I.G + diff --git a/src/kbfxplasmacanvasitem_events.cpp b/src/kbfxplasmacanvasitem_events.cpp new file mode 100644 index 0000000..d268a9e --- /dev/null +++ b/src/kbfxplasmacanvasitem_events.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxplasmacanvasitem.h" +#include <kapplication.h> +#include <kdesktopfile.h> +#include <kiconeffect.h> + +void KbfxPlasmaCanvasItem::mousePressEvent ( QMouseEvent * e ) +{ + e = e; +//TODO: +//implement this class + //emit clicked(); +//qDebug("Recive Mouse Press Event"); +} + +void +KbfxPlasmaCanvasItem::mouseReleaseEvent ( QMouseEvent * e ) +{ + e = e; + // QPixmap pix = labelIcon(); + emit clicked(); +} + +void KbfxPlasmaCanvasItem::mouseMoveEvent ( QMouseEvent * e ) +{ + e=e; +//qDebug("Item revices Mouse Event"); + +} + +void KbfxPlasmaCanvasItem::enterEvent ( QEvent * e ) +{ + e=e; +//qDebug("Mouse Enters"); +} + +void +KbfxPlasmaCanvasItem::exec() +{ + + if ( m_source == 0 ) + return; + + +// KIconEffect::visualActivate(new QWidget(), this->boundingRect()); + m_source->exec(); + +} + +bool +KbfxPlasmaCanvasItem::isCurrent() +{ + return m_isCurrent; +} + +void +KbfxPlasmaCanvasItem::setCurrent ( bool state ) +{ + m_isCurrent = state; +} + diff --git a/src/kbfxplasmacanvasitem_events.h b/src/kbfxplasmacanvasitem_events.h new file mode 100644 index 0000000..7f3dfaf --- /dev/null +++ b/src/kbfxplasmacanvasitem_events.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxplasmacanvasitem.h" + diff --git a/src/kbfxplasmacanvasitemwrapper.cpp b/src/kbfxplasmacanvasitemwrapper.cpp new file mode 100644 index 0000000..1c244f4 --- /dev/null +++ b/src/kbfxplasmacanvasitemwrapper.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxplasmacanvasitemwrapper.h" +#include <qptrlist.h> +#include <kbfxplasmapixmapprovider.h> + +KbfxPlasmaCanvasItemWrapper::KbfxPlasmaCanvasItemWrapper ( QCanvas * canvas ) +{ + m_canvas = canvas; +} + +KbfxPlasmaCanvasItemWrapper::~KbfxPlasmaCanvasItemWrapper () +{} + +QCanvasItem * +KbfxPlasmaCanvasItemWrapper::item ( KbfxPlasmaCanvasItem::Type __type ) +{ + QPixmap _img_sep = ( *KbfxPlasmaPixmapProvider::pixmap ( "separator" ) ); + QImage _tmp_img = _img_sep.convertToImage(); + _tmp_img = _tmp_img.smoothScale ( ConfigInit().m_itemView_w, _img_sep.height (),QImage::ScaleFree ); + _img_sep = QPixmap ( _tmp_img ); + + QPixmap _img_tnorm = ( *KbfxPlasmaPixmapProvider::pixmap ( "tilenormal" ) ); + _tmp_img = _img_tnorm.convertToImage(); + _tmp_img = _tmp_img.smoothScale ( ConfigInit().m_itemView_w, _img_tnorm.height (),QImage::ScaleFree ); + _img_tnorm = QPixmap ( _tmp_img ); + + QPixmap _img_thov = ( *KbfxPlasmaPixmapProvider::pixmap ( "tilehover" ) ); + _tmp_img = _img_thov.convertToImage(); + _tmp_img = _tmp_img.smoothScale ( ConfigInit().m_itemView_w, _img_thov.height (),QImage::ScaleFree ); + _img_thov = QPixmap ( _tmp_img ); + + if ( __type == KbfxPlasmaCanvasItem::SEPARATOR ) + { + QValueList<QPixmap> list; + list.append ( _img_sep ); + KbfxPlasmaCanvasItem *_ret = + new KbfxPlasmaCanvasItem ( new QCanvasPixmapArray ( list ),m_canvas ); + _ret->setType ( __type ); + return ( QCanvasItem * ) _ret; + } + + if ( __type == KbfxPlasmaCanvasItem::EXECUTABLE ) + { + + QValueList<QPixmap> list; + list.append ( _img_tnorm ); + list.append ( _img_thov ); + + QCanvasPixmapArray * _pArray = new QCanvasPixmapArray ( list ); + + KbfxPlasmaCanvasItem *_ret = new KbfxPlasmaCanvasItem ( _pArray, + m_canvas ); + + _ret->setType ( __type ); + return ( QCanvasItem * ) _ret; + } + + + return 0; +} + + +QCanvasItem * +KbfxPlasmaCanvasItemWrapper::itemIndex ( KbfxPlasmaCanvasItem::Type __type ) +{ + QPixmap _img_isep = ( *KbfxPlasmaPixmapProvider::pixmap ( "indexseparator" ) ); + QImage _tmp_img = _img_isep.convertToImage(); + _tmp_img = _tmp_img.smoothScale ( ConfigInit().m_listBox_w, _img_isep.height (),QImage::ScaleFree ); + _img_isep = QPixmap ( _tmp_img ); + + QPixmap _img_r = ( *KbfxPlasmaPixmapProvider::pixmap ( "rhstile" ) ); + _tmp_img = _img_r.convertToImage(); + _tmp_img = _tmp_img.smoothScale ( ConfigInit().m_listBox_w, _img_r.height (),QImage::ScaleFree ); + _img_r = QPixmap ( _tmp_img ); + + QPixmap _img_rhov = ( *KbfxPlasmaPixmapProvider::pixmap ( "rhshovertile" ) ); + _tmp_img = _img_rhov.convertToImage(); + _tmp_img = _tmp_img.smoothScale ( ConfigInit().m_listBox_w, _img_rhov.height (),QImage::ScaleFree ); + _img_rhov = QPixmap ( _tmp_img ); + + if ( __type == KbfxPlasmaCanvasItem::SEPARATOR ) + { + QValueList<QPixmap> list; + list.append ( _img_isep ); + KbfxPlasmaIndexItem *_ret = + new KbfxPlasmaIndexItem ( new QCanvasPixmapArray ( list ),m_canvas ); + _ret->setType ( __type ); + return ( QCanvasItem * ) _ret; + } + if ( __type == KbfxPlasmaCanvasItem::INDEX ) + { + QValueList<QPixmap> list2; + list2.append ( _img_r ); + list2.append ( _img_rhov ); + KbfxPlasmaIndexItem *_ret = new KbfxPlasmaIndexItem ( new QCanvasPixmapArray ( list2 ), + m_canvas ); + + _ret->setType ( __type ); + return ( QCanvasItem * ) _ret; + + } + return 0; +} + +#include "kbfxplasmacanvasitemwrapper.moc" diff --git a/src/kbfxplasmacanvasitemwrapper.h b/src/kbfxplasmacanvasitemwrapper.h new file mode 100644 index 0000000..54e70b2 --- /dev/null +++ b/src/kbfxplasmacanvasitemwrapper.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_PLASMA_CANVAS_ITEM_WRAPPER_H +#define KBFX_PLASMA_CANVAS_ITEM_WRAPPER_H + +#include "kbfxplasmacanvasitem.h" +#include "kbfxplasmaindexitem.h" +#include <qcanvas.h> + + +class KbfxPlasmaCanvasItemWrapper:public QObject +{ + + Q_OBJECT + public: + + KbfxPlasmaCanvasItemWrapper ( QCanvas * canvas ); + ~KbfxPlasmaCanvasItemWrapper(); + QCanvasItem* item ( KbfxPlasmaCanvasItem::Type __type ); + QCanvasItem* itemIndex ( KbfxPlasmaCanvasItem::Type __type ); + + private: + + QCanvas * m_canvas; + +//none + +}; + +#endif diff --git a/src/kbfxplasmacanvasrtti.h b/src/kbfxplasmacanvasrtti.h new file mode 100644 index 0000000..9f2d9be --- /dev/null +++ b/src/kbfxplasmacanvasrtti.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +enum {CANVASITEM=1003,CANVASBUTTON}; diff --git a/src/kbfxplasmacanvasstack.cpp b/src/kbfxplasmacanvasstack.cpp new file mode 100644 index 0000000..bfe5b36 --- /dev/null +++ b/src/kbfxplasmacanvasstack.cpp @@ -0,0 +1,179 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxplasmacanvasstack.h" + +KbfxPlasmaCanvasStack::KbfxPlasmaCanvasStack() +{ + + m_current= 0;//set to NULL + m_count = 0; + m_height = 0; + m_width = 0; + m_groupChain.setAutoDelete ( TRUE ); + m_name = "Unset:Faulty plugin"; +} + +KbfxPlasmaCanvasStack::~KbfxPlasmaCanvasStack() +{ +//TODO: needs to manage memory here + + + for ( uint i = 0; i < ( uint ) m_count; ++i ) + { + + m_groupChain.at ( i )->~KbfxPlasmaCanvasGroupView(); + m_groupChain.remove ( m_groupChain.at ( i ) ); + + } + + Dict::Iterator it; + + for ( it = m_dict.begin();it != m_dict.end();++it ) + { + m_dict.remove ( it ); + } + + delete m_current; + +} + + +void +KbfxPlasmaCanvasStack::raise ( uint id ) +{ + + KbfxPlasmaCanvasGroupView * _gvPtr = m_groupChain.at ( id ); + + if ( !_gvPtr ) + qDebug ( "Error item not in Stack" ); + else + { + for ( uint i = 0; i < m_groupChain.count (); ++i ) + { + m_groupChain.at ( i )->hide(); + } + m_height = _gvPtr->height(); + _gvPtr->show(); + } + + +} + + + +bool +KbfxPlasmaCanvasStack::contains ( QString name ) +{ +//FIXME:Depricated Data Structure Needs fixing + if ( m_dict.contains ( name ) == true ) + return true; + else + return false; + +} + + +void +KbfxPlasmaCanvasStack::addGroup ( KbfxPlasmaCanvasGroupView * gPtr ) +{ + if ( gPtr == NULL ) + { + qDebug + ( "KbfxPlasmaCanvasStack.cpp:34:Null Pointer Passed to addGroup()" ); + return; + } + else + { + m_groupChain.append ( gPtr ); + m_height = gPtr->height(); + m_width = gPtr->width(); + // KbfxPlasmaDataStack stackinfo; +/// stackinfo + m_dict[gPtr->name() ] = m_count; + + m_count++; + } +} + +KbfxPlasmaCanvasStack::Dict +KbfxPlasmaCanvasStack::getDict() +{ + return m_dict; +} + +void +KbfxPlasmaCanvasStack::hide() +{ + for ( uint i = 0; i < m_groupChain.count (); ++i ) + { + m_groupChain.at ( i )->hide(); + } +} + + +void +KbfxPlasmaCanvasStack::raiseByName ( QString name ) +{ + for ( uint i = 0; i < m_groupChain.count (); ++i ) + { + m_groupChain.at ( i )->hide(); + } + + + for ( uint i = 0; i < m_groupChain.count (); ++i ) + { + if ( m_groupChain.at ( i )->name() == name ) + { + m_groupChain.at ( i )->show(); + m_height = m_groupChain.at ( i )->height(); + } + } + +} + + + + +KbfxPlasmaCanvasGroupView * +KbfxPlasmaCanvasStack::activeViewByName ( QString name ) +{ + + + for ( uint i = 0; i < m_groupChain.count (); ++i ) + { + if ( m_groupChain.at ( i )->name() == name ) + { + return m_groupChain.at ( i ); + } + } + + return new KbfxPlasmaCanvasGroupView(); +} + + +QString +KbfxPlasmaCanvasStack::getItemName ( int id ) +{ + return m_groupChain.at ( id )->name(); +} + +#include "kbfxplasmacanvasstack.moc" diff --git a/src/kbfxplasmacanvasstack.h b/src/kbfxplasmacanvasstack.h new file mode 100644 index 0000000..91ad67c --- /dev/null +++ b/src/kbfxplasmacanvasstack.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_PLASMA_CANVAS_STACK_H +#define KBFX_PLASMA_CANVAS_STACK_H + +#include <qobject.h> +#include <qptrlist.h> +#include <kbfxplasmacanvasstackdata.h> +//#include "kbfxplasmacanvasgroup.h" +#include "kbfxplasmacanvasgroupview.h" + +/** +This class will manager a list of Grouplists. +**/ + + +class KbfxPlasmaCanvasStack:public QObject +{ + + Q_OBJECT + + public: + typedef QPtrList<KbfxPlasmaCanvasGroupView> groupPtrList; + typedef QMap<QString,uint> Dict;//DEPRECATED + typedef QMap<KbfxPlasmaCanvasStackData,uint> DataDict; + + KbfxPlasmaCanvasStack(); + virtual ~KbfxPlasmaCanvasStack(); + void addGroup ( KbfxPlasmaCanvasGroupView* ); + void deleteGroup ( KbfxPlasmaCanvasGroupView* ); + KbfxPlasmaCanvasStack* contains ( KbfxPlasmaCanvasGroupView* ); + QString getItemName ( int ); + virtual int rtti() {return 1006;} + void predend ( KbfxPlasmaCanvasGroupView* ); + void append ( KbfxPlasmaCanvasGroupView* ); + Dict getDict(); + void hide(); + int count() { return m_count;} + int height() + { + return m_height; + } + int width() + { + return m_width; + } + QString name() {return m_name;} + void setName ( QString name ) { m_name = name;} + bool contains ( QString ); + KbfxPlasmaCanvasGroupView * activeViewByName ( QString name ); + public slots: + void raise ( uint id ); + void raiseByName ( QString name ); + private: + int m_x; + int m_y; + int m_z; //depth index : not Z axis + int m_count; + int m_height; + int m_width; + KbfxPlasmaCanvasGroupView * m_current; + groupPtrList m_groupChain; + Dict m_dict; + DataDict m_dataDict; + QString m_name; +//state variables + +}; + +#endif diff --git a/src/kbfxplasmacanvasstackdata.h b/src/kbfxplasmacanvasstackdata.h new file mode 100644 index 0000000..1783b77 --- /dev/null +++ b/src/kbfxplasmacanvasstackdata.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_PLASMA_CANVAS_STACK_DATA_H +#define KBFX_PLASMA_CANVAS_STACK_DATA_H + + +class KbfxPlasmaCanvasStackData +{ + + public: + KbfxPlasmaCanvasStackData() {} + ~KbfxPlasmaCanvasStackData() {} + QString name; + QString icon; + int id; + +}; +#endif + diff --git a/src/kbfxplasmacanvasview.cpp b/src/kbfxplasmacanvasview.cpp new file mode 100644 index 0000000..013458e --- /dev/null +++ b/src/kbfxplasmacanvasview.cpp @@ -0,0 +1,665 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxplasmacanvasview.h" + +KbfxPlasmaCanvasView::KbfxPlasmaCanvasView ( QWidget * parent, + const char *name, WFlags fl ) : + QCanvasView ( parent, name,fl ) +{ + + viewport ()->setMouseTracking ( TRUE ); + viewport ()->setAcceptDrops ( true ); + this->setVScrollBarMode ( QScrollView::AlwaysOff ); + this->setHScrollBarMode ( QScrollView::AlwaysOff ); + setFrameShape ( QFrame::NoFrame ); + m_currentItem = 0L; + m_stack = 0; + m_currentView = new KbfxPlasmaCanvasGroupView (); + m_lastSignalData = ""; + gstack = 0; + m_exeCandidate = 0; + m_findDone = true; + m_selectedItem = 0L; + m_search = new QCanvas ( this->width (), this->height () ); + + m_scrollbar_top = new KbfxSpinxScrollBar ( this ); + m_scrollbar_bot = new KbfxSpinxScrollBar ( this,"bottom",1); + m_scrollbar_top->setType ( KbfxSpinxScrollBar::UP ); + m_scrollbar_bot->setType ( KbfxSpinxScrollBar::DOWN ); + + connect ( m_scrollbar_top, SIGNAL ( scroll ( int, int ) ), this, + SLOT ( scrollBy ( int, int ) ) ); + connect ( m_scrollbar_bot, SIGNAL ( scroll ( int, int ) ), this, + SLOT ( scrollBy ( int, int ) ) ); + + placeScrollBars (); +} + +void +KbfxPlasmaCanvasView::placeScrollBars () +{ + m_scrollbar_top->move ( 0, 0 ); + m_scrollbar_bot->move ( 0, ( this->height () + 1 ) - m_scrollbar_bot->height () ); +} + +KbfxPlasmaCanvasView::~KbfxPlasmaCanvasView () +{ +} + +void +KbfxPlasmaCanvasView::keyPressEvent ( QKeyEvent * ke ) +{ + qDebug ( "QCanvasView got Key events" ); + ke->ignore(); +} + +void +KbfxPlasmaCanvasView::execFirst () +{ + //if ( m_search->allItems ().count () < 1 ) +// { +// return; +// } +qDebug("_____----------------------------------------"); + if ( m_exeCandidate != 0 ) + m_exeCandidate->exec (); +} + +void +KbfxPlasmaCanvasView::clearAllButOne ( KbfxPlasmaCanvasItem * i ) +{ + i = i; + + QCanvasItemList list = canvas ()->allItems (); + + QCanvasItemList::Iterator it = list.begin (); + for ( ; it != list.end (); ++it ) + { + if ( *it ) + { + if ( *it != m_selectedItem ) + { + KbfxPlasmaIndexItem *t = ( KbfxPlasmaIndexItem * ) ( *it ); + t->setCurrent ( false ); + } + } + } + canvas ()->update (); +} + +void +KbfxPlasmaCanvasView::execAt ( int i ) +{ + int e = i - 48; + int e_count = m_search->allItems ().count (); + + if ( e_count < 2 ) + { + return; + } + if ( e >= e_count - 1 ) + return; + + KbfxPlasmaCanvasItem *tmp = m_searchMap[e]; + if ( tmp == 0 ) + return; + else + tmp->exec (); +} + +void +KbfxPlasmaCanvasView::leaveEvent ( QEvent * e ) +{ + e = e; + clearAllButOne ( m_currentItem ); +} + +void +KbfxPlasmaCanvasView::enterEvent ( QEvent * e ) +{ + e = e; + clearAllButOne ( m_currentItem ); +} + +void +KbfxPlasmaCanvasView::mouseMoveEvent ( QMouseEvent * me ) +{ + QPoint p = inverseWorldMatrix ().map ( viewportToContents ( me->pos () ) ); + if ( canvas () == NULL ) + return; + +// KbfxPlasmaCanvasGroup *tmp = 0; + QCanvasItemList l = canvas ()->collisions ( p ); + for ( QCanvasItemList::Iterator it = l.begin (); it != l.end (); ++it ) + { + if ( *it == 0 ) + return; + if ( ( *it )->rtti () == CANVASITEM ) + { + KbfxPlasmaCanvasItem *t = ( KbfxPlasmaCanvasItem * ) ( *it ); + t->mouseMoveEvent ( me ); + if ( m_currentItem != NULL ) + { + m_currentItem->setCurrent ( false ); + } + m_currentItem = t; + t->setCurrent ( true ); + } + } + canvas ()->update (); +} + +void +KbfxPlasmaCanvasView::contentsMouseMoveEvent ( QMouseEvent * me ) +{ + if ( canvas () == NULL ) + return; + + if ( me->state () & LeftButton ) + { + int distance = ( me->pos () - m_dragPos ).manhattanLength (); + if ( distance > QApplication::startDragDistance () ) + this->startDrag (); + } + QScrollView::contentsMouseMoveEvent ( me ); + + QCanvasItemList l = canvas ()->collisions ( me->pos () ); + + if ( l.count () <= 0 ) + return; + + for ( QCanvasItemList::Iterator it = l.begin (); it != l.end (); ++it ) + { + if ( *it == 0 ) + return; + if ( ( *it )->rtti () == CANVASITEM ) + { + KbfxPlasmaCanvasItem *t = ( KbfxPlasmaCanvasItem * ) ( *it ); + t->mouseMoveEvent ( me ); + if ( m_currentItem != NULL ) + { + m_currentItem->setCurrent ( false ); + } + m_currentItem = t; + t->setCurrent ( true ); + this->setCursor ( QCursor ( Qt::PointingHandCursor ) ); + } + } + canvas ()->update (); +} + + +void +KbfxPlasmaCanvasView::contentsMousePressEvent ( QMouseEvent * me ) +{ + KbfxPlasmaCanvasGroup *tmp = 0; + QCanvasItemList l = canvas ()->collisions ( me->pos () ); + for ( QCanvasItemList::Iterator it = l.begin (); it != l.end (); ++it ) + { + if ( ( *it )->rtti () == CANVASITEM ) + { + KbfxPlasmaCanvasItem *t = ( KbfxPlasmaCanvasItem * ) ( *it ); + t->mousePressEvent ( me ); + if ( t->type () == KbfxPlasmaCanvasItem::SEPARATOR ) + tmp = KbfxPlasmaCanvasGroup::groupContaining ( t ); + } + } + if ( tmp != 0 ) + tmp->shade (); + m_clickPos = me->pos (); + + if ( me->button () == LeftButton ) + m_dragPos = me->pos (); + QScrollView::contentsMousePressEvent ( me ); + canvas ()->update (); +} + +void +KbfxPlasmaCanvasView::startDrag () +{ + if ( m_currentItem != 0 ) + { + KbfxDataSource *src = new KbfxDataSource (); + src = m_currentItem->source (); + if ( src == 0 ) + { + qDebug ( "null source" ); + return; + } + QUriDrag *drag = + new QUriDrag ( QStrList ( src->contentPath () ), this, + src->name ().ascii () ); + drag->setFileNames ( QStringList ( src->contentPath () ) ); + drag->setPixmap ( m_currentItem->dragPixmap () ); + drag->drag (); + emit clicked (); + } +} + +void +KbfxPlasmaCanvasView::resizeEvent ( QResizeEvent * ) +{ + placeScrollBars (); +} + +/* +void +KbfxPlasmaCanvasView::enterEvent ( QEvent * e ) +{ + e = e; + if ( canvas () == 0 ) + return; + +// KbfxPlasmaCanvasGroup *tmp = 0; + QPoint _mPos = QCursor::pos (); + QCanvasItemList l = canvas ()->collisions ( this->mapFromGlobal ( _mPos ) ); + + for ( QCanvasItemList::Iterator it = l.begin (); it != l.end (); ++it ) + { + if ( *it == 0 ) + break; + if ( ( *it )->rtti () == CANVASITEM ) + { + KbfxPlasmaCanvasItem *t = ( KbfxPlasmaCanvasItem * ) ( *it ); +// t->enterEvent ( e); + m_currentItem = t; + } + } +} +*/ + +void +KbfxPlasmaCanvasView::reload() +{ + clearAll(); + clearSearch(); + m_appletMap.clear(); +} + +void +KbfxPlasmaCanvasView::clearAll () +{ + if ( canvas() != m_search ) + return ; + + QCanvasItemList list = canvas ()->allItems (); + + QCanvasItemList::Iterator it = list.begin (); + for ( ; it != list.end (); ++it ) + { + if ( *it ) + { +// KbfxPlasmaCanvasItem *t = (KbfxPlasmaCanvasItem *) (*it); + m_search->removeItem ( ( *it ) ); + ( *it )->setCanvas ( 0L ); +// delete (*it); + } + } + canvas()->update(); +} + +void +KbfxPlasmaCanvasView::setKbfxCanvas ( QCanvas * cnv ) +{ + m_default = cnv; + setCanvas ( m_default ); + // canvas ()->setBackgroundPixmap ( ( *KbfxPlasmaPixmapProvider::pixmap ( "appviewbg" )) ); + QPixmap * pixmap = KbfxPlasmaPixmapProvider::pixmap ( "middleboxbg" ); + if ( pixmap != NULL ) + { + QImage img = pixmap->convertToImage(); + img = img.smoothScale ( this->width(),pixmap->height(),QImage::ScaleFree ); + pixmap->convertFromImage ( img ); + this->canvas ()->setBackgroundPixmap ( *pixmap ); + } +} + +void +KbfxPlasmaCanvasView::expandAll () +{ + if ( m_currentView != 0 ) + { + if ( ConfigInit ().m_startHidden == false ) + m_currentView->unfoldGroupAll (); + scroll ( 0, 0 ); + } +} + +void +KbfxPlasmaCanvasView::handleLoadRequest ( KbfxSignal signal ) +{ + QString tm = signal.name (); + + KbfxDataStack *_stack = m_dataStack[signal.name () ]; + if ( _stack == 0 ) + { + qDebug ( "Empty Stack" ); + return; + } + + QString _activateGroup = _stack->getSubGroupName ( signal.id () ); + + KbfxDataGroupList *_dataList = _stack->getStack ( _activateGroup ); + KbfxPlasmaCanvasGroupView *gview = new KbfxPlasmaCanvasGroupView (); + KbfxPlasmaCanvasStack *v_stack = m_appletMap[signal.name () ]; + + if ( m_currentView->name () == _activateGroup && canvas() != m_search) + { + return; + } + setCanvas ( m_default ); + + scrollBy ( 0, - ( canvas ()->height () ) ); + + stackMap::Iterator it; + for ( it = m_appletMap.begin (); it != m_appletMap.end (); ++it ) + { + ( *it )->hide (); + } + + if ( m_appletMap[signal.name () ]->contains ( _activateGroup ) != true ) + { + loadGroup ( _dataList, gview ); + m_currentView = gview; + m_appletMap[signal.name () ]->setName ( signal.name () ); + m_appletMap[signal.name () ]->addGroup ( gview ); + m_appletMap[signal.name () ]->raiseByName ( _activateGroup ); + int _height = + v_stack->height () + m_scrollbar_top->height () + + m_scrollbar_bot->height (); + if ( _height > this->visibleHeight () ) + canvas ()->resize ( v_stack->width (), _height ); + else + canvas ()->resize ( v_stack->width (), this->visibleHeight () ); + canvas()->update(); + repaint(); + // return; + } + else + { + m_appletMap[signal.name () ]->raiseByName ( _activateGroup ); + m_currentView = + m_appletMap[signal.name () ]->activeViewByName ( _activateGroup ); + int _height = + m_appletMap[signal.name () ]->height () + m_scrollbar_top->height () + + m_scrollbar_bot->height (); + if ( _height > this->visibleHeight () ) + canvas ()->resize ( m_appletMap[signal.name () ]->width (), _height ); + else + canvas ()->resize ( m_appletMap[signal.name () ]->width (), + this->visibleHeight () ); + canvas()->update(); + repaint(); + } + +} + + +void +KbfxPlasmaCanvasView::contentsMouseReleaseEvent ( QMouseEvent * me ) +{ +// KbfxPlasmaCanvasGroup *tmp = 0; + QCanvasItemList l = canvas ()->collisions ( me->pos () ); + for ( QCanvasItemList::Iterator it = l.begin (); it != l.end (); ++it ) + { + if ( ( *it )->rtti () == CANVASITEM ) + { + KbfxPlasmaCanvasItem *t = ( KbfxPlasmaCanvasItem * ) ( *it ); + t->mouseReleaseEvent ( me ); + if ( t->type () != KbfxPlasmaCanvasItem::SEPARATOR ) + emit clicked (); + } + } +} + + +void +KbfxPlasmaCanvasView::clearSearch () +{ + searchMap::Iterator it; + for ( it = m_searchMap.begin (); it != m_searchMap.end (); ++it ) + { + if ( it != 0 ) + m_searchMap.remove ( it ); + } +} + + +void +KbfxPlasmaCanvasView::search_R ( const QString name ) +{ + gstack = new KbfxPlasmaCanvasStack (); + KbfxPlasmaCanvasGroup *visualGroup = new KbfxPlasmaCanvasGroup (); + KbfxPlasmaCanvasGroupView *glist = new KbfxPlasmaCanvasGroupView (); + KbfxPlasmaCanvasItem *box = 0; + KbfxPlasmaCanvasItemWrapper *boxwrapper = 0; + + glist->setName ( "Search Result" ); + + this->setCanvas ( m_search ); + + QPixmap * pixmap = KbfxPlasmaPixmapProvider::pixmap ( "middleboxbg" ); + if ( pixmap != NULL ) + { + QImage img = pixmap->convertToImage(); + img = img.smoothScale ( this->width(),pixmap->height(),QImage::ScaleFree ); + pixmap->convertFromImage ( img ); + this->canvas ()->setBackgroundPixmap ( *pixmap ); + } + + this->setCursor ( QCursor ( Qt::BusyCursor ) ); + + clearAll (); + dataStack::Iterator sit; + + for ( sit = m_dataStack.begin (); sit != m_dataStack.end (); ++sit ) + { + if ( sit == NULL ) + continue; + + visualGroup = new KbfxPlasmaCanvasGroup (); + KbfxDataGroup *appGroup = + KbfxPlasmaPluginLoader::search ( sit.key (), name ); + + boxwrapper = new KbfxPlasmaCanvasItemWrapper ( m_search ); + box = + ( KbfxPlasmaCanvasItem * ) boxwrapper-> + item ( KbfxPlasmaCanvasItem::SEPARATOR ); + + if ( appGroup != NULL ) + box->setLabelText ( "Hits for " + sit.key () ); + + if ( appGroup == NULL ) + { + qDebug ( "Null Search Group" ); + continue; + } + + + if ( appGroup->count () <= 0 ) + continue; + + if ( visualGroup->addItem ( box ) == false ) + {} + + + KbfxDataGroup::Data dat = appGroup->getData (); + KbfxDataGroup::Data::Iterator it; + + KbfxDataSource * firstItem = appGroup->itemAt(0); + + boxwrapper = new KbfxPlasmaCanvasItemWrapper ( m_search ); + m_exeCandidate = + ( KbfxPlasmaCanvasItem * ) boxwrapper-> + item ( KbfxPlasmaCanvasItem::EXECUTABLE ); + + m_exeCandidate->setSource ( *firstItem ); + + for ( it = dat.begin(); it != dat.end (); it++ ) + { + qApp->processEvents (); + boxwrapper = new KbfxPlasmaCanvasItemWrapper ( m_search ); + box = + ( KbfxPlasmaCanvasItem * ) boxwrapper-> + item ( KbfxPlasmaCanvasItem::EXECUTABLE ); + box->setSource ( * ( it.data () ) ); + if ( visualGroup->addItem ( box ) == true ) + { + } + } + visualGroup->move ( 0, m_scrollbar_top->height () ); + + glist->addGroup ( visualGroup ); + } + + gstack->addGroup ( glist ); + gstack->raise ( 0 ); + if ( gstack->height() < this->visibleHeight() ) + m_search->resize ( gstack->width(),this->visibleHeight() ); + else + m_search->resize ( gstack->width (), + gstack->height () + m_scrollbar_top->height () + + m_scrollbar_bot->height () ); + m_search->update (); + + this->setCursor ( QCursor ( Qt::ArrowCursor ) ); +} + + +void +KbfxPlasmaCanvasView::search ( const QString & str ) +{ + if ( str.isEmpty () ) + return; + + if ( str == "" ) + return; + + search_R ( str ); +} + + + +void +KbfxPlasmaCanvasView::addStack ( KbfxPlasmaCanvasStack * stak, QString name ) +{ + if ( m_appletMap.contains ( name ) ) + { + return; + } + m_appletMap[name] = stak; +} + +void +KbfxPlasmaCanvasView::addStack ( KbfxDataStack * stak, QString name ) +{ + if ( m_dataStack.contains ( name ) ) + { + return; + } + m_dataStack[name] = stak; + addStack ( new KbfxPlasmaCanvasStack (), name ); +} + +void +KbfxPlasmaCanvasView::loadGroup ( KbfxDataGroupList * src, + KbfxPlasmaCanvasGroupView * dest ) +{ + if ( src == 0 ) + return ; + + KbfxDataGroupList::GroupList list = src->getGroup (); + dest->setName ( src->name () ); + KbfxPlasmaCanvasItem *box = 0; + KbfxPlasmaCanvasItemWrapper *boxwrapper = 0; + KbfxPlasmaCanvasGroup *appGroup = 0; //new KbfxPlasmaCanvasGroup (); + QString l_lastAdd = ""; + for ( int i = 0; i < src->count (); i++ ) + { + if ( list.at ( i ) != 0 ) + { + if ( list.at ( i )->count () <= 0 ) + continue; + + appGroup = new KbfxPlasmaCanvasGroup (); + + boxwrapper = new KbfxPlasmaCanvasItemWrapper ( m_default ); + box = + ( KbfxPlasmaCanvasItem * ) boxwrapper-> + item ( KbfxPlasmaCanvasItem::SEPARATOR ); + + if ( list.at ( i )->name ().compare ( l_lastAdd ) == 0 ) + { + box->setLabelText ( src->name () ); + } + else + { + l_lastAdd = list.at ( i )->name () ; + box->setLabelText ( list.at ( i )->name () ); + } + + appGroup->addItem ( box ); + + KbfxDataGroup::Data::Iterator git; + KbfxDataGroup::Data data; + data = list.at ( i )->getData (); + + for ( git = data.begin (); git != data.end (); git++ ) + { + boxwrapper = new KbfxPlasmaCanvasItemWrapper ( m_default ); + box = + ( KbfxPlasmaCanvasItem * ) boxwrapper-> + item ( KbfxPlasmaCanvasItem::EXECUTABLE ); + box->setSource ( * ( git.data () ) ); + appGroup->addItem ( box ); + } + if ( appGroup->count () > 0 ) + { + dest->addGroup ( appGroup ); + appGroup->move ( 0, m_scrollbar_top->height () ); + } + } + } + if ( ConfigInit ().m_startHidden ) + { + dest->foldGroupAll (); + } + else + { + dest->unfoldGroupAll (); + } +} + + +void +KbfxPlasmaCanvasView::contentsDragLeaveEvent ( QDragEnterEvent * event ) +{ + event->accept ( true ); +} + +void +KbfxPlasmaCanvasView::contentsDragEnterEvent ( QDragEnterEvent * event ) +{ + event->accept ( true ); +} + +#include "kbfxplasmacanvasview.moc" diff --git a/src/kbfxplasmacanvasview.h b/src/kbfxplasmacanvasview.h new file mode 100644 index 0000000..80c8a99 --- /dev/null +++ b/src/kbfxplasmacanvasview.h @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_PLASMA_CANVAS_VIEW_H +#define KBFX_PLASMA_CANVAS_VIEW_H + +#include <qcanvas.h> +#include <qcursor.h> +#include <qdragobject.h> +#include <qpainter.h> + +#include <kimageeffect.h> + +#include <kbfxconfig.h> +#include <kbfxdatastack.h> +#include <kbfxplasmapixmapprovider.h> +#include <kbfxplasmapluginloader.h> + +//#include "kbfxplasmacanvasrtti.h" +#include "kbfxplasmacanvasgroup.h" +#include "kbfxplasmacanvasgroupview.h" +#include "kbfxplasmacanvasitem.h" +#include "kbfxplasmacanvasitemwrapper.h" + +#include "kbfxplasmacanvasstack.h" +#include "kbfxplasmacanvasview.h" +#include "kbfxsignal.h" +#include "kbfxspinxscrollbar.h" + + +class QCanvasView; + + +class KbfxPlasmaCanvasView : public QCanvasView +{ + Q_OBJECT + + public: + typedef QMap<QString,KbfxPlasmaCanvasStack*> stackMap; + typedef QMap<QString,KbfxDataStack*> dataStack; + typedef QMap<int,KbfxPlasmaCanvasItem*> searchMap; + + KbfxPlasmaCanvasView ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ); + virtual ~KbfxPlasmaCanvasView(); + void addStack ( KbfxPlasmaCanvasStack*stk,QString name ); + void addStack ( KbfxDataStack*stk,QString name ); + + void setKbfxCanvas ( QCanvas*cnv ); + void loadGroup ( KbfxDataGroupList * src,KbfxPlasmaCanvasGroupView * dest ); + void contentsDragLeaveEvent ( QDragEnterEvent *event ); + void contentsDragEnterEvent ( QDragEnterEvent *event ); + + + public slots: + + void clearAll(); + virtual void contentsMousePressEvent ( QMouseEvent * me ); + virtual void contentsMouseMoveEvent ( QMouseEvent * e ); + virtual void contentsMouseReleaseEvent ( QMouseEvent * e ); + virtual void mouseMoveEvent ( QMouseEvent * me ); + virtual void enterEvent ( QEvent * e ); + virtual void keyPressEvent ( QKeyEvent * ke ); + virtual void emulatedKeyPress ( QKeyEvent * k ) {keyPressEvent ( k );} + virtual void resizeEvent ( QResizeEvent * ) ; + virtual void leaveEvent ( QEvent * e ); +// virtual void leaveEvent(QEvent e ); + void handleLoadRequest ( KbfxSignal ); + void search ( const QString & ); + void search_R ( const QString key ); + void execFirst(); + void execAt ( int i ); + void expandAll(); + void reload(); + signals: + void clicked(); + protected: + void clearAllButOne ( KbfxPlasmaCanvasItem * i ); + + private: + void clearSearch(); + void startDrag(); + void placeScrollBars(); + + QPoint m_clickPos; + KbfxPlasmaCanvasItem * m_currentItem; + KbfxPlasmaCanvasStack * m_currentStack; + KbfxPlasmaCanvasStack * m_stack; + QString m_lastSignalData; + stackMap m_appletMap; + dataStack m_dataStack; + searchMap m_searchMap; + KbfxPlasmaCanvasStack * gstack ; + KbfxPlasmaCanvasItem * m_exeCandidate; + QCanvas * m_default; + QCanvas * m_search; + bool m_findDone; + KbfxSpinxScrollBar * m_scrollbar_top; + KbfxSpinxScrollBar * m_scrollbar_bot; + QPoint m_dragPos; + KbfxPlasmaCanvasGroupView * m_currentView; + QString m_currentViewName; + KbfxPlasmaCanvasItem * m_selectedItem; +}; + +#endif + diff --git a/src/kbfxplasmaindexitem.cpp b/src/kbfxplasmaindexitem.cpp new file mode 100644 index 0000000..cbbfe91 --- /dev/null +++ b/src/kbfxplasmaindexitem.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxplasmaindexitem.h" +#include <kdesktopfile.h> +#include <kapplication.h> +#include <kbfxconfig.h> + +KbfxPlasmaIndexItem::KbfxPlasmaIndexItem ( QCanvasPixmapArray * a, QCanvas * canvas ) :KbfxPlasmaCanvasAbstractItem ( a,canvas ) +{ +//this->setItemMode (1); + setAnimated ( false ); + setCurrent ( false ); + m_isSelected = false; + QPixmap * _img = this->image ( 0 ); + m_height =_img->height(); + m_width= _img->width(); + +} + + + +KbfxPlasmaIndexItem::~KbfxPlasmaIndexItem() +{} + +void +KbfxPlasmaIndexItem::setIcon ( QString str ) +{ + KIconLoader *iconload = KGlobal::iconLoader (); + m_iconPath = iconload->iconPath ( str, KIcon::Desktop, false ); + + m_icon.load ( m_iconPath ); +} + +void +KbfxPlasmaIndexItem::setText ( QString text ) +{ + m_text = text; +} + +void +KbfxPlasmaIndexItem::setSelected ( bool stat ) +{ + m_isSelected = stat; + +} + +bool +KbfxPlasmaIndexItem::selected() +{ + return m_isSelected; +} + + +void +KbfxPlasmaIndexItem::drawContent ( QPainter * pe ) +{ + + if ( this->isCurrent() || m_isSelected ) + { + this->setFrame ( 1 ); + } + else + { + this->setFrame ( 0 ); + } + + QCanvasPixmap *cp = this->image ( this->frame () ); + m_height = cp->height(); + m_width = cp->width(); + + pe->drawPixmap ( this->boundingRect (), *cp ); + + QRect r ( ( int ) x(), ( int ) y(), m_width, m_height ); + QRect textRect ( m_height+1, ( int ) y(), m_width,m_height ); + + QFont * _font_plugin = new QFont ( ConfigInit().m_pluginNameFont ); + QFont * _font_index = new QFont ( ConfigInit().m_fontIndexFont ); + + if ( this->type() != KbfxPlasmaIndexItem::SEPARATOR ) + { + pe->setFont ( *_font_index ); + pe->setPen ( ConfigInit().m_fontIndexColor ); + } + else + { + pe->setFont ( *_font_plugin ); + pe->setPen ( ConfigInit().m_pluginNameColor); + } + + pe->drawText ( textRect, Qt::AlignVCenter | Qt::AlignLeft ,QString ( m_text ), -1, &r,0 ); + pe->drawPixmap ( QRect ( ( int ) x() +5 , ( int ) y() +6,m_height-12,m_height-12 ),m_icon ); + + delete _font_plugin; + delete _font_index; + +} + +int +KbfxPlasmaIndexItem::height() +{ + return m_height; +} + +void +KbfxPlasmaIndexItem::setId ( int id ) +{ + m_id = id; +} + + +void +KbfxPlasmaIndexItem::draw ( QPainter & p ) +{ + drawContent ( &p ); +} + +void +KbfxPlasmaIndexItem::setLabelText ( QString str ) +{ + QFont * _font = new QFont(ConfigInit().m_fontIndexFont); + + QFontMetrics fm ( *_font ); + + int _commentWidth = fm.width ( str+"..." ); + int _strLen = str.length(); + int _margin = height();; + if ( _commentWidth > ( m_width -_margin ) ) + { + + for ( int i = 0; i < _strLen /*&& ( fm.width(str+"...") < width()-40 )*/ ;i++ ) + { + str.truncate ( str.length()-2 ); + if ( fm.width ( str+"..." ) < m_width-_margin ) + break; + + } + str+="..."; + } + + setText ( str ); +} + + +QString +KbfxPlasmaIndexItem::belongsTo() +{ + + return m_parent; +} + +void +KbfxPlasmaIndexItem::setBelongsTo ( QString parent ) +{ + m_parent = parent; +} + + +void KbfxPlasmaIndexItem::mousePressEvent ( QMouseEvent * e ) +{ + e = e; +} + +#include "kbfxplasmaindexitem.moc" diff --git a/src/kbfxplasmaindexitem.h b/src/kbfxplasmaindexitem.h new file mode 100644 index 0000000..9b68da8 --- /dev/null +++ b/src/kbfxplasmaindexitem.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_PLASMA_INDEX_ITEM_H +#define KBFX_PLASMA_INDEX_ITEM_H + +#include "kbfxplasmacanvasabstractitem.h" + +class KbfxPlasmaIndexItem : public KbfxPlasmaCanvasAbstractItem +{ + Q_OBJECT + + public: + + KbfxPlasmaIndexItem ( QCanvasPixmapArray * a, QCanvas * canvas ); + virtual ~KbfxPlasmaIndexItem(); + + void setIcon ( QString path ); + void setText ( QString text ); + void setId ( int id ); + //void setName(QString name); + void setLabelText ( QString text ); + void setBelongsTo ( QString parent ); + QString belongsTo(); + int height(); + void setSelected ( bool select ); + bool selected(); + int Id() { return m_id;} + + virtual void drawContent ( QPainter * pe ); + virtual void draw ( QPainter & pe ); + virtual void mousePressEvent ( QMouseEvent * e ); + + private: + int m_id; + QString m_name; + QString m_text; + QString m_iconPath; + QPixmap m_icon; + QString m_parent; + bool m_isCurrent; + int m_height; + int m_width; + bool m_isSelected; + + +}; + + +#endif diff --git a/src/kbfxplasmaindexview.cpp b/src/kbfxplasmaindexview.cpp new file mode 100644 index 0000000..ee50c9e --- /dev/null +++ b/src/kbfxplasmaindexview.cpp @@ -0,0 +1,436 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxplasmaindexview.h" + +KbfxPlasmaIndexView::KbfxPlasmaIndexView ( QWidget * parent, const char *name, + WFlags l ) : + QCanvasView ( parent, name, l ) +{ + m_itemGroup = new KbfxPlasmaCanvasGroup (); + m_itemGroupList = new KbfxPlasmaCanvasGroupView (); + m_itemStack = new KbfxPlasmaCanvasStack (); + m_pluginLoaded = ""; + m_itemStack->addGroup ( m_itemGroupList ); + viewport ()->setMouseTracking ( TRUE ); + + m_currentPos = QPoint ( 0, 0 ); + m_mousePollTimer = new QTimer ( this ); + + m_pluginList = KbfxPlasmaPluginLoader::scanPlugins (); + viewport ()->setAcceptDrops ( true ); + this->setVScrollBarMode ( QScrollView::AlwaysOff ); + this->setHScrollBarMode ( QScrollView::AlwaysOff ); + setFrameShape ( QFrame::NoFrame ); + m_currentItem = 0L; + m_selectedItem = 0L; +// m_pluginList = ""; + connect ( this, SIGNAL ( clicked ( KbfxPlasmaIndexItem * ) ), this, + SLOT ( slotClicked ( KbfxPlasmaIndexItem * ) ) ); + m_currentView = 0; + setDragAutoScroll ( true ); +} + + +KbfxPlasmaIndexView::~KbfxPlasmaIndexView () +{ +} + +void +KbfxPlasmaIndexView::checkMousePos () +{ + KbfxPlasmaCanvasGroup *tmp = 0; + if ( QCursor::pos () == mapToGlobal ( contentsToViewport ( m_currentPos ) ) ) + { + QMouseEvent me ( QEvent::MouseButtonPress, + this->mapToGlobal ( m_currentPos ), Qt::LeftButton, + Qt::LeftButton ); + + clearAll (); + + QCanvasItemList l = canvas ()->collisions ( m_currentPos ); + for ( QCanvasItemList::Iterator it = l.begin (); it != l.end (); ++it ) + { + if ( ( *it )->rtti () == CANVASITEM ) + { + KbfxPlasmaIndexItem *t = ( KbfxPlasmaIndexItem * ) ( *it ); + + if ( t->type () != KbfxPlasmaCanvasItem::SEPARATOR ) + { + emit clearSelected(); + t->mousePressEvent ( &me ); + m_selectedItem = t; + t->setSelected ( true ); + emit clicked ( t ); + } + + if ( t->type () == KbfxPlasmaCanvasItem::SEPARATOR ) + tmp = KbfxPlasmaCanvasGroup::groupContaining ( t ); +// groupContaining ((KbfxPlasmaCanvasItem *) l.first ()); + } + } + + } +// if (tmp != 0) +// tmp->shade(); +} + + +void +KbfxPlasmaIndexView::setView ( KbfxPlasmaCanvasView * view ) +{ + if ( view == NULL ) + return; + m_currentView = view; +} + +void +KbfxPlasmaIndexView::clearAllButOne ( KbfxPlasmaIndexItem * i ) +{ + i = i; + + QCanvasItemList list = canvas ()->allItems (); + + QCanvasItemList::Iterator it = list.begin (); + for ( ; it != list.end (); ++it ) + { + if ( *it ) + { + if ( *it != m_selectedItem ) + { + KbfxPlasmaIndexItem *t = ( KbfxPlasmaIndexItem * ) ( *it ); + t->setCurrent ( false ); + } + } + } + canvas ()->update (); +} + +void +KbfxPlasmaIndexView::clearSelection () +{ + QCanvasItemList list = canvas ()->allItems (); + + QCanvasItemList::Iterator it = list.begin (); + for ( ; it != list.end (); ++it ) + { + if ( *it ) + { + KbfxPlasmaIndexItem *t = ( KbfxPlasmaIndexItem * ) ( *it ); + t->setCurrent ( false ); + t->setSelected ( false ); + } + } + canvas ()->update (); +} + +void +KbfxPlasmaIndexView::leaveEvent ( QEvent * e ) +{ + e = e; + clearAllButOne ( m_currentItem ); + emit expand (); +} + +void +KbfxPlasmaIndexView::contextMenuSlot ( int id ) +{ + id = id; +/* + m_pluginList.remove ( m_pluginList.at ( id - 1 ) ); + if ( m_currentView != 0 ) + emit pluginRequest ( m_pluginMenu->text ( id ), m_currentView ); +*/ +} + +void +KbfxPlasmaIndexView::contentsContextMenuEvent ( QContextMenuEvent * event ) +{ + event = event; +/* + m_pluginMenu = new KPopupMenu ( this );; + connect ( m_pluginMenu, SIGNAL ( activated ( int ) ), this, + SLOT ( contextMenuSlot ( int ) ) ); + + m_pluginMenu->insertTitle ( "Insert Plugin", 0, 0 ); + int _index = 1; + + for ( QStringList::Iterator it = m_pluginList.begin (); + it != m_pluginList.end (); ++it ) + { + + m_pluginMenu->insertItem ( *it, _index, _index ); + _index++; + } + + m_pluginMenu->exec ( event->globalPos () ); +*/ +} + +void +KbfxPlasmaIndexView::loadList ( KbfxDataStack * stkPtr ) +{ + if ( stkPtr == NULL ) + { + kdDebug() << "Loading Stack Failed:KbfxListBox->loadList()" << endl; + return; + } + + int _height = 0; + + KbfxPlasmaCanvasItem *box = 0; + KbfxPlasmaCanvasItemWrapper *boxwrapper = 0; + + KbfxPlasmaCanvasItemWrapper *indexitemwrap = + new KbfxPlasmaCanvasItemWrapper ( canvas () ); + + m_itemGroup = new KbfxPlasmaCanvasGroup (); + + boxwrapper = new KbfxPlasmaCanvasItemWrapper ( canvas () ); + + box = + ( KbfxPlasmaCanvasItem * ) boxwrapper-> + itemIndex ( KbfxPlasmaCanvasItem::SEPARATOR ); + + box->setLabelText ( stkPtr->name () ); + m_itemGroup->addItem ( box ); + + _height += box->height (); + + KbfxDataStack::DataDict _dict = stkPtr->getDataDict (); + KbfxDataStack::DataDict::Iterator it; + for ( it = _dict.begin (); it != _dict.end (); ++it ) + { + KbfxPlasmaIndexItem *item = + ( KbfxPlasmaIndexItem * ) indexitemwrap-> + itemIndex ( KbfxPlasmaCanvasItem::INDEX ); + + if ( item == 0 ) + return; + + item->setType ( KbfxPlasmaCanvasItem::INDEX ); + item->setText ( it.data ().name ); + item->setName ( it.data ().name ); + item->setLabelText ( it.data ().name ); + item->setIcon ( it.data ().icon ); + item->setId ( it.key () ); + + m_itemGroup->addItem ( item ); + + item->setBelongsTo ( stkPtr->name () ); + } + + m_itemGroupList->addGroup ( m_itemGroup ); + + if ( m_itemGroupList->height () > this->height () ) + canvas ()->resize ( this->width (), m_itemGroupList->height () ); + canvas ()->update (); + + m_itemStack->raise ( 0 ); + + for ( QStringList::Iterator it = m_pluginList.begin (); + it != m_pluginList.end (); ++it ) + { + if ( *it == stkPtr->name() ) + { + m_pluginList.remove ( it ); + break; + } + } +} + +void +KbfxPlasmaIndexView::setKbfxCanvas ( QCanvas * cnv ) +{ + setCanvas ( cnv ); + + canvas ()->setBackgroundPixmap ( ( *KbfxPlasmaPixmapProvider::pixmap ( "listboxbg" )) ); + + canvas ()->update (); +} + + +void +KbfxPlasmaIndexView::loadPlugin ( QString name, KbfxPlasmaCanvasView * view ) +{ + if ( m_pluginList.contains ( name ) <= 0 ) + { + KbfxPlasmaPluginLoader *m_loader = new KbfxPlasmaPluginLoader (); + KbfxDataStack *m_stack_R = m_loader->getView ( name ); + + if ( m_stack_R == NULL ) + return; + + if ( m_currentView != 0 ) + view->addStack ( m_stack_R, name ); + + this->loadList ( m_stack_R ); + canvas ()->update (); + m_pluginLoaded += name; + + delete m_loader; + return; + } + else + { + kdDebug() << "Plugin already loaded" << endl; + return; + } +} + + +void +KbfxPlasmaIndexView::mouseMoveEvent ( QMouseEvent * me ) +{ + me = me; +} + + + +void +KbfxPlasmaIndexView::contentsMouseMoveEvent ( QMouseEvent * me ) +{ + if ( canvas () == NULL ) + return; + + m_currentPos = me->pos (); + +// TODO: Get wait time from config + + this->setCursor ( QCursor ( Qt::PointingHandCursor ) ); + + QTimer::singleShot ( 800, this, SLOT ( checkMousePos () ) ); + + if ( contentsToViewport ( me->pos () ).y () < this->height () / 5 ) + { + scrollBy ( -10, -10 ); + } + else if ( contentsToViewport ( me->pos () ).y () > ( ( this->height () * 2 ) / 3 ) ) + { + scrollBy ( 10, 10 ); + } + + QScrollView::contentsMouseMoveEvent ( me ); + + +// KbfxPlasmaCanvasGroup *tmp = 0; + QCanvasItemList l = canvas ()->collisions ( me->pos () ); + + if ( l.count () <= 0 ) + return; + + for ( QCanvasItemList::Iterator it = l.begin (); it != l.end (); ++it ) + { + if ( *it == 0 ) + return; + if ( ( *it )->rtti () == CANVASITEM ) + { + KbfxPlasmaIndexItem *t = ( KbfxPlasmaIndexItem * ) ( *it ); + t->mouseMoveEvent ( me ); + if ( m_currentItem != NULL ) + { + if ( !m_currentItem->isSelected () ) + m_currentItem->setCurrent ( false ); + } + m_currentItem = t; + t->setCurrent ( true ); + } + } + canvas ()->update (); +} + +void +KbfxPlasmaIndexView::contentsMousePressEvent ( QMouseEvent * me ) +{ + if ( me->button () == RightButton ) + return; + + clearAll (); + + this->setCursor ( QCursor ( Qt::WaitCursor ) ); + + KbfxPlasmaCanvasGroup *tmp = 0; + QCanvasItemList l = canvas ()->collisions ( me->pos () ); + for ( QCanvasItemList::Iterator it = l.begin (); it != l.end (); ++it ) + { + if ( ( *it )->rtti () == CANVASITEM ) + { + KbfxPlasmaIndexItem *t = ( KbfxPlasmaIndexItem * ) ( *it ); + + if ( t->type () != KbfxPlasmaCanvasItem::SEPARATOR ) + { + t->mousePressEvent ( me ); + m_selectedItem = t; + t->setSelected ( true ); + emit clicked ( t ); + } + + if ( t->type () == KbfxPlasmaCanvasItem::SEPARATOR ) + tmp = KbfxPlasmaCanvasGroup::groupContaining ( t ); +// groupContaining ((KbfxPlasmaCanvasItem *) l.first ()); + } + } + if ( tmp != 0 ) + tmp->shade (); + +// m_clickPos = me->pos (); + + QScrollView::contentsMousePressEvent ( me ); + + canvas ()->update (); + this->setCursor ( QCursor ( Qt::PointingHandCursor ) ); +} + +void +KbfxPlasmaIndexView::slotClicked ( KbfxPlasmaIndexItem * it ) +{ + if ( it == NULL ) + return; + + KbfxPlasmaIndexItem *_it = ( KbfxPlasmaIndexItem * ) it; + + KbfxSignal signal ( _it->belongsTo (), _it->Id () ); + + this->setCursor ( QCursor ( Qt::WaitCursor ) ); + emit loadRequest ( signal ); + this->setCursor ( QCursor ( Qt::PointingHandCursor ) ); +} + +void +KbfxPlasmaIndexView::clearAll () +{ + QCanvasItemList list = canvas ()->allItems (); + + QCanvasItemList::Iterator it = list.begin (); + for ( ; it != list.end (); ++it ) + { + if ( *it ) + { + KbfxPlasmaIndexItem *t = ( KbfxPlasmaIndexItem * ) ( *it ); + t->setSelected ( false ); + } + } + + canvas ()->update (); +} + + +#include "kbfxplasmaindexview.moc" diff --git a/src/kbfxplasmaindexview.h b/src/kbfxplasmaindexview.h new file mode 100644 index 0000000..ebda368 --- /dev/null +++ b/src/kbfxplasmaindexview.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_PLASMA_INDEX_VIEW_H +#define KBFX_PLASMA_INDEX_VIEW_H + +#include <qcanvas.h> + +#include <kdebug.h> +#include <kpopupmenu.h> + +#include <kbfxdatastack.h> +#include <kbfxplasmapixmapprovider.h> +#include <kbfxplasmapluginloader.h> + +#include "kbfxplasmacanvasitemwrapper.h" +#include "kbfxplasmacanvasstack.h" +#include "kbfxplasmacanvasview.h" +#include "kbfxplasmaindexitem.h" +#include "kbfxsignal.h" + + + +class KbfxPlasmaIndexView : public QCanvasView +{ + + Q_OBJECT + + public: + + KbfxPlasmaIndexView ( QWidget * parent = 0, const char * name = 0, WFlags l = 0 ); + virtual ~KbfxPlasmaIndexView(); + void loadList ( KbfxDataStack * stkPtr ); + int count() { return m_itemGroup->count() ; } + void setView ( KbfxPlasmaCanvasView * view ); + virtual void contentsMouseMoveEvent ( QMouseEvent * e ); + virtual void contentsMousePressEvent ( QMouseEvent * me ); + virtual void contentsContextMenuEvent ( QContextMenuEvent * e ) ; + virtual void mouseMoveEvent ( QMouseEvent * e ); + virtual void leaveEvent ( QEvent * e ); + void setKbfxCanvas ( QCanvas * cnv ); + void clearAll(); + + public slots: + void slotClicked ( KbfxPlasmaIndexItem * ); + void contextMenuSlot ( int id ); + void loadPlugin ( QString name,KbfxPlasmaCanvasView * ); + void checkMousePos(); + void clearSelection(); + + signals: + void loadRequest ( KbfxSignal signal ); + void pluginRequest ( QString pluginName,KbfxPlasmaCanvasView * ); + void clicked ( KbfxPlasmaIndexItem * item ); + void expand(); + void clearSelected(); + + protected: + void clearAllButOne ( KbfxPlasmaIndexItem * i ); + + private: + + KbfxPlasmaCanvasGroup * m_itemGroup; + KbfxPlasmaCanvasGroupView * m_itemGroupList; + KbfxPlasmaCanvasStack * m_itemStack; + KbfxPlasmaIndexItem * m_currentItem; + KbfxPlasmaIndexItem * m_selectedItem; + QStringList m_pluginList; + QStringList m_pluginLoaded; + KPopupMenu * m_pluginMenu; + KbfxPlasmaCanvasView * m_currentView; + QPoint m_currentPos; + QTimer * m_mousePollTimer; +}; + +#endif diff --git a/src/kbfxsignal.h b/src/kbfxsignal.h new file mode 100644 index 0000000..6f2dfd0 --- /dev/null +++ b/src/kbfxsignal.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_SIGNAL_H +#define KBFX_SIGNAL_H + +class KbfxSignal +{ + public: + KbfxSignal() {m_name="";} + KbfxSignal ( QString name,uint id ) { m_name = name;m_id = id;} + ~KbfxSignal() {} + QString name() {return m_name;} + uint id() {return m_id;} + private: + QString m_name; + uint m_id; +}; + +#endif diff --git a/src/kbfxspinx.cpp b/src/kbfxspinx.cpp new file mode 100644 index 0000000..4208b21 --- /dev/null +++ b/src/kbfxspinx.cpp @@ -0,0 +1,327 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include <config.h> + +#include "kbfxspinx.h" + +bool KbfxSpinx::m_horizontal_position = TRUE; + +KbfxSpinx::KbfxSpinx ( const QString& configFile, Type type, int actions, QWidget *parent, const char *name ) + : KPanelApplet ( configFile, type, actions, parent, name ),DCOPObject ( "KBFXInterface" ) +{ + m_parent = parent; + createKbfx(); +} + +KbfxSpinx::~KbfxSpinx() +{ +} + +void KbfxSpinx::dirtyReaload(const QString & dir) +{ + QString _dir=dir; + notifyConfigChange(); +} + +void KbfxSpinx::createKbfx() +{ + m_menu = 0; // Set to NULL + m_tooltip = ConfigInit().m_ToolTip; + m_kicker_auto_adjust = ConfigInit().m_ToolBarResize; + m_KbfxWatcher = ConfigInit().m_KbfxWatcher; + m_dcopClient = new DCOPClient (); + m_dcopClient->attach (); + + kbfxBtn = new KbfxButton ( this,"Kbfx Button" ); + if ( ConfigInit ().m_KbfxMenuType == "kmenu" ) + { + kbfxBtn->show(); + kbfxBtn->repaint(); + } + else + { + createRMenu(); + connect ( m_menu,SIGNAL ( aboutToHide () ),kbfxBtn,SLOT ( toggle() ) ); + } + + kmenu_timer = new QTimer ( this,"Fade Timer" ); + connect ( kmenu_timer, SIGNAL ( timeout() ), kbfxBtn, SLOT ( toggleKMenu () ) ); + + connect ( kbfxBtn , SIGNAL ( pressed() ),this,SLOT ( showKbfxMenu() ) ); + connect ( kbfxBtn , SIGNAL ( showToolTip() ),this,SLOT ( ToolTip() ) ); + + if ( m_kicker_auto_adjust ) + m_parent->resize ( m_parent->width(),kbfxBtn->height() ); + resizeRequest(); + + if (m_KbfxWatcher) + { + l_watch = new KDirWatch(this,"SyscocaWatch"); + KUser * l_user = new KUser(); + QString l_path("/var/tmp/kdecache-"); + l_path.append(l_user->loginName()); + l_path.append("/"); + l_watch->addDir(l_path); + l_watch->startScan( TRUE, FALSE); + connect ( l_watch, SIGNAL ( dirty(const QString&) ), + this, SLOT ( dirtyReaload(const QString&) ) ); + delete l_user; + } +} + +void KbfxSpinx::notifyConfigChange() +{ + kdDebug() << "Got DCOP Call notifyConfigChange" + << endl; +/* + FIXME + The delete here does not reload everything. + Only the button and the parent menu. + Carefull memory de-allocation is needed before deleteing further :-( + Else be ready for a nice backtrace. + Memleak is obvious. +*/ + +/* + bool _KbfxButton_m_sizeHeight = KbfxButton::m_sizeHeight; + int _KbfxButton_m_size = KbfxButton::m_size; + + zap ( l_watch ); + zap ( kmenu_timer ); + zap ( kbfxBtn ); + zap ( m_menu ); + zap ( m_dcopClient ); + ConfigInit().read(); + KbfxPlasmaPixmapProvider::rebuildCache(); + createKbfx(); + + KbfxButton::m_sizeHeight = _KbfxButton_m_sizeHeight; + KbfxButton::m_size = _KbfxButton_m_size; + kbfxBtn->loadSkins(); +*/ + + kbfxBtn -> reloadConfig(); +} + +void KbfxSpinx::createRMenu() +{ + m_menu = new KbfxSpinxPopUp ( this,"KbfxOpop" ); + m_menuWidget = new KbfxSpinxMenuWidget ( m_menu,"KbfxSpinxMenu" ); + m_menu->addItem ( m_menuWidget,0 ); + kbfxBtn->show(); + kbfxBtn->repaint(); + menuPosition(); +} + +void KbfxSpinx::showKbfxMenu() +{ + if ( ConfigInit ().m_KbfxMenuType == "kmenu" ) + { + showKmenu (); + } + else + { + m_menu->popup ( menuPosition() ); + } +} + +void KbfxSpinx::ToolTip () +{ + if ( !m_tooltip ) + return; + + KbfxToolTip *tooltip = new KbfxToolTip (); + + QPoint xpoint = ( this->mapToGlobal ( QPoint ( 0, 0 ) ) ); + int popx = xpoint.x (); + int popy = xpoint.y (); + + if ( position () == pTop ) + { + popy += this->height(); + } + if ( position () == pBottom ) + { + popy -= tooltip->height(); + } + if ( position () == pLeft ) + { + popx += this->width(); + } + if ( position () == pRight ) + { + popx -= tooltip->width(); + } + + connect ( kbfxBtn, SIGNAL ( leave () ), tooltip, SLOT ( hideToolTip () ) ); + connect ( kbfxBtn, SIGNAL ( clicked () ), tooltip, SLOT ( hideToolTip () ) ); + tooltip->setStartPos ( popx, popy ); + tooltip->show (); +} + +void KbfxSpinx::showKmenu() +{ + /* Import of old KBFX code */ + /** + Note that there is no real way to know the + height of the K-menu + **/ + + this->setCursor ( Qt::BlankCursor ); + + QByteArray data, rdata; + QDataStream arg ( data, IO_WriteOnly ); + QCString replytype; + QPoint _tmp ( QCursor::pos () ); + + if ( position () == pTop || position () == pBottom ) + { + if ( _tmp.y () > 128 ) + { + QCursor::setPos ( this->mapToGlobal ( QPoint ( 0, 0 ) ) ); + } + else + { + QCursor::setPos ( this->mapToGlobal ( this->geometry ().bottomLeft () ) ); + } + } + else + { + if ( _tmp.x () > 128 ) + { + QCursor::setPos ( this->mapToGlobal ( QPoint ( 0, 0 ) ) ); + } + else + { + QCursor::setPos ( this->mapToGlobal ( this->geometry ().topRight () ) ); + } + } + + arg << QPoint ( QCursor::pos () ); + + if ( !m_dcopClient-> + call ( "kicker", "kicker", "popupKMenu(QPoint)", data, replytype, rdata, + FALSE, -1 ) ) + { + kdWarning () + << "**KBFX-APPLET-FATAL_ERROR:Could not send DCOP command" + << endl; + } + + this->setCursor ( Qt::ArrowCursor ); + QCursor::setPos ( _tmp ); + if ( !kmenu_timer->isActive ()) + kmenu_timer->start(5000,true); + kdDebug () << "Kmenu Called" << endl; +} + +void KbfxSpinx::showMenu() +{ + showKbfxMenu(); +} + +void KbfxSpinx::about() +{ +// KMessageBox::information ( 0, i18n ( "This is an about box" ) ); + KRun::runCommand ( "kbfxconfigapp --about" ); +} + +void KbfxSpinx::help() +{ + kapp->invokeHelp ( "", "kbfxconfigapp" ); +} + +void KbfxSpinx::preferences() +{ + KRun::runCommand ( "kbfxconfigapp" ); +} + +int KbfxSpinx::widthForHeight ( int height ) const +{ + static int width_for_height = 0; + if ( width_for_height != height || !m_horizontal_position ) + { + if ( m_kicker_auto_adjust ) + kbfxBtn->readjust( TRUE ); // Readjust for height + KbfxButton::m_sizeHeight = TRUE; + KbfxButton::m_size = height; + kbfxBtn->loadSkins(); + width_for_height = height; + } + m_horizontal_position = TRUE; + return kbfxBtn->width(); +} + +int KbfxSpinx::heightForWidth ( int width ) const +{ + static int height_for_width = 0; + if ( height_for_width != width || m_horizontal_position) + { + if ( m_kicker_auto_adjust ) + kbfxBtn->readjust( FALSE ); // Readjust for width + KbfxButton::m_sizeHeight = FALSE; + KbfxButton::m_size = width; + kbfxBtn->loadSkins(); + height_for_width = width; + } + m_horizontal_position = FALSE; + return kbfxBtn->height(); +} + +QPoint KbfxSpinx::menuPosition() +{ + QPoint xpoint = ( this->mapToGlobal ( QPoint ( 0, 0 ) ) ); + int popx = xpoint.x (); + int popy = xpoint.y (); + + if ( position () == pTop ) + { + return QPoint ( popx, ( popy + this->height() ) ); + } + if ( position () == pBottom ) + { + return QPoint ( popx, ( popy - m_menuWidget->height() ) ); + } + if ( position () == pLeft ) + { + return QPoint ( ( popx + this->width() ), popy ); + } + if ( position () == pRight ) + { + return QPoint ( ( popx - m_menuWidget->width() ), popy ); + } + + return xpoint; // Should never be reached? +} + +extern "C" +{ + KPanelApplet* init ( QWidget *parent, const QString& configFile ) + { + KGlobal::locale()->insertCatalogue ( "KbfxSpinx" ); + return new KbfxSpinx ( configFile, KPanelApplet::Normal, + KPanelApplet::About | KPanelApplet::Help | KPanelApplet::Preferences, + parent, "KbfxSpinx" ); + } +} + +#include "kbfxspinx.moc" diff --git a/src/kbfxspinx.desktop b/src/kbfxspinx.desktop new file mode 100644 index 0000000..01153d6 --- /dev/null +++ b/src/kbfxspinx.desktop @@ -0,0 +1,17 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=KBFX Spinx +Comment=K-Menu Replacement +Comment[de]=K-Menü- Nachfolger +Comment[el]=Αντικαταστάτης του K-Μενού +Comment[et]=K-menüü asendus +Comment[fr]=Remplacement du menu K +Comment[nl]=K-Menu-vervanging +Comment[pt]=Substituto do Menu K +Comment[pt_BR]=Substituto do Menu K +Comment[sv]=Ersättning av K-menyn +Icon=kbfx +X-KDE-Library=libkbfxspinx +X-KDE-UniqueApplet=true + + diff --git a/src/kbfxspinx.h b/src/kbfxspinx.h new file mode 100644 index 0000000..3111cb2 --- /dev/null +++ b/src/kbfxspinx.h @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_SPINX_H +#define KBFX_SPINX_H + +#define zap(x) if(x){delete(x); x=0;} + +#include <config.h> + +#include <qbitmap.h> +#include <qlabel.h> +#include <qlcdnumber.h> +#include <qpoint.h> +#include <qpopupmenu.h> +#include <qstring.h> +#include <qtimer.h> + +#include <dcopclient.h> +#include <dcopobject.h> +#include <dcopref.h> +#include <kapplication.h> +#include <kconfig.h> +#include <kdebug.h> +#include <kdirwatch.h> +#include <kglobal.h> +#include <klocale.h> +#include <kmessagebox.h> +#include <kpanelapplet.h> +#include <kpopupmenu.h> +#include <krun.h> +#include <kuser.h> + +#include <kbfxconfig.h> +#include <kbfxplasmapixmapprovider.h> + +#include "kbfxbutton.h" +#include "kbfxspinxmenu.h" +#include "kbfxspinxpopup.h" +#include "kbfxspinxview.h" +#include "kbfxtooltip.h" + + +class KbfxSpinx : public KPanelApplet,public DCOPObject +{ + K_DCOP + Q_OBJECT + + public: + KbfxSpinx ( const QString& configFile, Type t = Normal, int actions = 0, + QWidget *parent = 0, const char *name = 0 ); + + ~KbfxSpinx(); + virtual int widthForHeight ( int height ) const; + virtual int heightForWidth ( int width ) const; + virtual void about(); + virtual void help(); + virtual void preferences(); + QPoint menuPosition(); + void resizeRequest() { emit(updateLayout()); } + k_dcop: + ASYNC showMenu(); + ASYNC notifyConfigChange(); + + public slots: + void showKbfxMenu(); + void showKmenu(); + void ToolTip(); + void dirtyReaload(const QString&); + + protected: + void createRMenu(); + void createKbfx(); + bool m_tooltip; + + private: + KConfig *ksConfig; + KbfxButton * kbfxBtn; + KbfxSpinxMenuWidget * m_menuWidget; + KbfxSpinxPopUp * m_menu; + QWidget * m_parent; + bool m_kicker_auto_adjust; + bool m_KbfxWatcher; + static bool m_horizontal_position; + DCOPClient * m_dcopClient; + QTimer * kmenu_timer; + KDirWatch * l_watch; +}; + +#endif diff --git a/src/kbfxspinxmenu.cpp b/src/kbfxspinxmenu.cpp new file mode 100644 index 0000000..0d016ac --- /dev/null +++ b/src/kbfxspinxmenu.cpp @@ -0,0 +1,513 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxspinxmenu.h" + +KbfxSpinxMenuWidget::KbfxSpinxMenuWidget ( QWidget * parent, const char *name, + WFlags fl ) : + QWidget ( parent, "MenuWidget", + fl | Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_StaysOnTop ) +{ + m_parent = parent; + QString _name=name; + init(); + +} + +void +KbfxSpinxMenuWidget::reinit() +{ + emit refresh(); + init(); + +} + +void +KbfxSpinxMenuWidget::init() +{ + createMask (); + + QWidget *main = new QWidget ( this ); + + m_kbfxSpinxTop = new KbfxSpinxTop ( main ); + m_toolBarBot = new KbfxSpinxToolBar ( main ); + m_toolBarBot->setMinimumHeight ( ConfigInit ().m_botBar_h ); + m_toolBarBot->setMaximumHeight ( ConfigInit ().m_botBar_h ); + m_kbfxSpinxTop->setMaximumHeight ( ConfigInit ().m_topBar_h ); + m_kbfxSpinxTop->setMinimumHeight ( ConfigInit ().m_topBar_h ); + + QWidget *middle = new QWidget ( main ); + + middle->setPalette ( QPalette ( QColor ( 24, 233, 233 ) ) ); + +// m_middleFrame = new QHBoxLayout(middle); + + m_canvasView = new KbfxPlasmaCanvasView ( this ); + m_indexView = new KbfxPlasmaIndexView ( this ); + m_indexLeftView = new KbfxPlasmaIndexView ( this ); + + /* Search Box */ + m_searchTag = new KbfxPixmapLabel ( this, "Search:" ); + QToolTip::add( m_searchTag, tr2i18n( "Double click to clear..." ) ); + m_searchTag->normalize (); + m_searchTag->move ( ConfigInit ().m_searchBox_x, + ConfigInit ().m_searchBox_y ); + + QPixmap m_searchPixmap = ( *KbfxPlasmaPixmapProvider::pixmap ( "find" ) ); + + m_searchTag->setPixmap ( m_searchPixmap ); + + m_searchTag->resize ( m_searchPixmap.width (), ConfigInit ().m_searchBox_h ); + + m_search = new QLineEdit ( this, "Search BOX" ); + QToolTip::add( m_search, tr2i18n( "Type here to search..." ) ); + m_search->setFrameShape ( QFrame::NoFrame ); + m_search->setFocusPolicy ( QWidget::StrongFocus ); + m_search->move ( ConfigInit ().m_searchBox_x + m_searchTag->width (), + ConfigInit ().m_searchBox_y ); + m_search->resize ( ConfigInit ().m_searchBox_w - m_searchTag->width (), + ConfigInit ().m_searchBox_h ); + + connect (m_searchTag, SIGNAL (mouseDoubleClicked ( const ButtonState & )), this, + SLOT (search_clear ( const ButtonState & ))); + + int frameHeight = ConfigInit().m_listBox_h; + + if (frameHeight <= (this->height () - ( m_kbfxSpinxTop->height () + m_toolBarBot->height ()) ) ) { + frameHeight = (this->height () - ( m_kbfxSpinxTop->height () + + m_toolBarBot->height ()) ); + } + +// m_middleFrame->addWidget(middleleft); + m_canvasView->setMaximumHeight ( ConfigInit().m_itemView_h ); + m_canvasView->setMinimumHeight ( ConfigInit().m_itemView_h ); + m_canvasView->setMaximumWidth ( ConfigInit ().m_itemView_w ); + m_canvasView->setMinimumWidth ( ConfigInit ().m_itemView_w ); + m_appCanvas = new QCanvas ( m_canvasView->width (), m_canvasView->height () ); + m_canvasView->setKbfxCanvas ( m_appCanvas ); + m_appCanvas->setDoubleBuffering ( true ); + + m_indexView->setMaximumHeight ( frameHeight ); + m_indexView->setMinimumHeight ( frameHeight ); + m_indexView->setMaximumWidth ( ConfigInit ().m_listBox_w ); + m_indexView->setMinimumWidth ( ConfigInit ().m_listBox_w ); + m_indexCanvas = new QCanvas ( m_indexView->width (), m_indexView->height () ); + m_indexView->setKbfxCanvas ( m_indexCanvas ); + m_indexCanvas->setDoubleBuffering ( true ); + m_indexView->setView ( m_canvasView ); + + m_indexLeftView->setMaximumHeight ( frameHeight ); + m_indexLeftView->setMinimumHeight ( frameHeight ); + m_indexLeftView->setMaximumWidth ( ConfigInit ().m_listBox_w ); + m_indexLeftView->setMinimumWidth ( ConfigInit ().m_listBox_w ); + m_indexLeftCanvas = + new QCanvas ( m_indexLeftView->width (), m_indexLeftView->height () ); + m_indexLeftView->setKbfxCanvas ( m_indexLeftCanvas ); + m_indexLeftCanvas->setDoubleBuffering ( true ); + m_indexLeftView->setView ( m_canvasView ); + + + m_canvasView->move ( ConfigInit ().m_itemView_x, ConfigInit ().m_itemView_y ); + m_indexView->move ( ConfigInit ().m_listBox_x, ConfigInit ().m_listBox_y ); + m_indexLeftView->move ( ConfigInit ().m_listBox_w + ConfigInit ().m_itemView_w, + ConfigInit ().m_listBox_y ); + + m_fixedFrame = new QVBoxLayout ( main ); + m_fixedFrame->setResizeMode ( QLayout::Minimum ); + m_fixedFrame->addWidget ( m_kbfxSpinxTop ); + m_fixedFrame->addWidget ( middle ); + m_fixedFrame->addWidget ( m_toolBarBot ); + + m_loadedListLeft = " "; + m_loadedListRight = " "; + + main->resize ( this->size () ); + + loadHistory (); + + connect ( m_indexView, SIGNAL ( loadRequest ( KbfxSignal ) ), m_canvasView, + SLOT ( handleLoadRequest ( KbfxSignal ) ) ); + + connect ( m_indexLeftView, SIGNAL ( loadRequest ( KbfxSignal ) ), m_canvasView, + SLOT ( handleLoadRequest ( KbfxSignal ) ) ); + + connect ( m_canvasView, SIGNAL ( clicked () ), this, SLOT ( hideMenu () ) ); + + connect ( m_search, SIGNAL ( textChanged ( const QString & ) ), m_canvasView, + SLOT ( search ( const QString & ) ) ); + + connect ( m_indexView, + SIGNAL ( pluginRequest ( QString, KbfxPlasmaCanvasView * ) ), + m_indexView, SLOT ( loadPlugin ( QString, KbfxPlasmaCanvasView * ) ) ); + + connect ( m_indexLeftView, + SIGNAL ( pluginRequest ( QString, KbfxPlasmaCanvasView * ) ), + m_indexLeftView, + SLOT ( loadPlugin ( QString, KbfxPlasmaCanvasView * ) ) ); + + connect ( m_indexView, + SIGNAL ( clearSelected() ), + m_indexLeftView, SLOT ( clearSelection() ) ); + + connect ( m_indexLeftView, + SIGNAL ( clearSelected() ), + m_indexView, + SLOT ( clearSelection() ) ); + + connect (this,SIGNAL(refresh()),m_canvasView,SLOT(reload())); + connect (this,SIGNAL(runItem()),m_canvasView,SLOT(execFirst())); + + KbfxSpinxToolButton *logout = new KbfxSpinxToolButton ( m_toolBarBot ); + KbfxSpinxToolButton *lock = new KbfxSpinxToolButton ( m_toolBarBot ); + + lock ->setPixmaps ( ( *KbfxPlasmaPixmapProvider::pixmap ( "lock" ) ), + ( *KbfxPlasmaPixmapProvider::pixmap ( "lockhover" ) ) ); + + logout ->setPixmaps ( ( *KbfxPlasmaPixmapProvider::pixmap ( "logout" ) ), + ( *KbfxPlasmaPixmapProvider::pixmap ( "logouthover" ) ) ); + + KbfxDataSource *logoutSrc = new KbfxDataSource (); + logoutSrc->setCommand ( "dcop kdesktop KDesktopIface logout" ); + logoutSrc->setName ( "Logout" ); + + KbfxDataSource *lockSrc = new KbfxDataSource (); + lockSrc->setCommand ( "dcop kdesktop KScreensaverIface lock" ); + lockSrc->setName ( "logout" ); + + logout->setDataSource ( logoutSrc ); + lock ->setDataSource ( lockSrc ); + + delete logoutSrc; + delete lockSrc; + m_toolBarBot->addButton ( logout ); + m_toolBarBot->addButton ( lock ); + + connect ( logout,SIGNAL ( clicked() ),this , SLOT ( hideMenu() ) ); + connect ( lock ,SIGNAL ( clicked() ),this , SLOT ( hideMenu() ) ); +} + + +KbfxSpinxMenuWidget::~KbfxSpinxMenuWidget () +{ +} + +void +KbfxSpinxMenuWidget::search_clear ( const ButtonState & _btn ) +{ + if ( _btn == Qt::LeftButton ) + { + /* Clear the search box */ + m_search->clear(); + /* Clear the search canvas */ + m_canvasView->clearAll (); + } +} + +/* +void +KbfxSpinxMenuWidget::changeHeight (int het) +{ + +} +*/ + +void +KbfxSpinxMenuWidget::createMask () +{ + QPixmap maskpng = ( *KbfxPlasmaPixmapProvider::pixmap ( "mask" ) ); + QImage rawimg = maskpng.convertToImage (); + + rawimg = + rawimg.smoothScale ( ConfigInit ().m_userMenuWidth, + ConfigInit ().m_userMenuHeight, + QImage::ScaleFree ); + + maskpng.convertFromImage ( rawimg ); + + setMinimumWidth ( maskpng.width () ); + setMinimumHeight ( maskpng.height () ); +// setMaximumWidth ( maskpng.width () ); +// setMaximumHeight ( maskpng.height () ); + if ( !maskpng.mask () ) + if ( rawimg.hasAlphaBuffer () ) + { + QBitmap bm; + bm = rawimg.createAlphaMask (); + maskpng.setMask ( bm ); + } + else + { + QBitmap bm; + bm = rawimg.createHeuristicMask (); + // maskpng.setMask ( bm ); + } + + if ( maskpng.mask () && m_parent ) + m_parent->setMask ( *maskpng.mask () ); +} + +void +KbfxSpinxMenuWidget::resizeContent () +{} + +void +KbfxSpinxMenuWidget::loadHistory () +{ + QStringList::Iterator it; + for ( it = ConfigInit ().m_pluginsLeft.begin (); + it != ConfigInit ().m_pluginsLeft.end (); ++it ) + { + if ( (*it) != NULL) + this->loadPluginLeft ( ( *it ) ); + } + for ( it = ConfigInit ().m_pluginsRight.begin (); + it != ConfigInit ().m_pluginsRight.end (); ++it ) + { + if ( (*it) != NULL) + this->loadPluginRight ( ( *it ) ); + } +} + +void +KbfxSpinxMenuWidget::enterPressed () +{ + kdDebug() << "TODO: Implement Enter Presed" << endl; +} + +/* +void +KbfxSpinxMenuWidget::propergateMove (QMouseEvent * me) +{ +} +*/ + +void +KbfxSpinxMenuWidget::hideMenu () +{ + emit nowHidden (); + m_parent->hide (); +} + +/* +void +KbfxSpinxMenuWidget::mouseMoveEvent (QMouseEvent * me) +{ +// m_listBox->setFocus(); +} +*/ + +void +KbfxSpinxMenuWidget::loadPluginLeft ( QString name ) +{ + if (name == NULL) { + return; + } + if ( m_loadedListLeft.contains ( name ) <= 0 ) + { + m_loader = new KbfxPlasmaPluginLoader (); + m_stack_R = m_loader->getView ( name ); + + if ( m_stack_R == NULL ) + return; + + m_canvasView->addStack ( m_stack_R, name ); + m_indexView->loadList ( m_stack_R ); + delete m_loader; + m_loadedListLeft += name; + return; + } + else + { + kdDebug() << "Plugin already loaded" << endl; + return; + } +} + +void +KbfxSpinxMenuWidget::loadPluginRight ( QString name ) +{ +if ( m_loadedListRight.contains ( name ) <= 0 ) + { + m_loader = new KbfxPlasmaPluginLoader (); + m_stack_R = m_loader->getView ( name ); + + if ( m_stack_R == NULL ) + return; + + m_canvasView->addStack ( m_stack_R, name ); + m_indexLeftView->loadList ( m_stack_R ); + delete m_loader; + m_loadedListRight += name; + return; + } + else + { + kdDebug() << "Plugin already loaded" << endl; + return; + } +} + +/* +void +KbfxSpinxMenuWidget::focusInEvent (QFocusEvent * te) +{ + kdDebug() << "TODO: Handle Focus Event" << endl; +} +*/ + +void +KbfxSpinxMenuWidget::keyPressEvent ( QKeyEvent * e ) +{ + if ( e->key () == Qt::Key_Backspace ) + { + m_search->backspace (); + return; + } + + else if ( e->key () == Qt::Key_Escape ) + { + hideMenu (); + return; + } + + else if ( e->key() == Qt::Key_Return ) + { + hideMenu (); + m_canvasView->setFocus (); + KRun::runCommand ( m_search->text ()); + return; + } + + else if ( e->key () == Qt::Key_Up ) + { + m_search->setFocus (); + return; + } + + else if ( e->key () == Qt::Key_Down ) + { + m_canvasView->setFocus (); + return; + } + + else if ( e->key () == Qt::Key_Control + || e->key () == Qt::Key_Alt + || e->key () == Qt::Key_Pause + || e->key () == Qt::Key_Print + || e->key () == Qt::Key_SysReq + || e->key () == Qt::Key_Meta + || e->key () == Qt::Key_CapsLock + || e->key () == Qt::Key_NumLock + || e->key () == Qt::Key_ScrollLock + || e->key () == Qt::Key_F1 + || e->key () == Qt::Key_F2 + || e->key () == Qt::Key_F3 + || e->key () == Qt::Key_F4 + || e->key () == Qt::Key_F5 + || e->key () == Qt::Key_F6 + || e->key () == Qt::Key_F7 + || e->key () == Qt::Key_F8 + || e->key () == Qt::Key_F9 + || e->key () == Qt::Key_F10 + || e->key () == Qt::Key_F11 + || e->key () == Qt::Key_F12 + || e->key () == Qt::Key_F13 + || e->key () == Qt::Key_F14 + || e->key () == Qt::Key_F15 + || e->key () == Qt::Key_F16 + || e->key () == Qt::Key_F17 + || e->key () == Qt::Key_F18 + || e->key () == Qt::Key_F19 + || e->key () == Qt::Key_F20 + || e->key () == Qt::Key_Super_L + || e->key () == Qt::Key_Super_R + || e->key () == Qt::Key_Menu + || e->key () == Qt::Key_Hyper_L + || e->key () == Qt::Key_Hyper_R + || e->key () == Qt::Key_Help + || e->key () == Qt::Key_Back + || e->key () == Qt::Key_Forward + || e->key () == Qt::Key_Stop + || e->key () == Qt::Key_Refresh + || e->key () == Qt::Key_VolumeDown + || e->key () == Qt::Key_VolumeMute + || e->key () == Qt::Key_VolumeUp + || e->key () == Qt::Key_BassBoost + || e->key () == Qt::Key_BassUp + || e->key () == Qt::Key_BassDown + || e->key () == Qt::Key_TrebleUp + || e->key () == Qt::Key_TrebleDown + || e->key () == Qt::Key_MediaPlay + || e->key () == Qt::Key_MediaStop + || e->key () == Qt::Key_MediaPrev + || e->key () == Qt::Key_MediaNext + || e->key () == Qt::Key_MediaRecord + || e->key () == Qt::Key_HomePage + || e->key () == Qt::Key_Favorites + || e->key () == Qt::Key_Search + || e->key () == Qt::Key_Standby + || e->key () == Qt::Key_OpenUrl + || e->key () == Qt::Key_LaunchMail + || e->key () == Qt::Key_LaunchMedia + ) + { + hideMenu (); + e->ignore(); + return; + } + +/* + else if ( e->key() == Qt::Key_Alt ) + { + hideMenu (); + m_canvasView->setFocus (); + emit runItem (); + return; + } + + + else if ( e->key () == Qt::Key_Tab ) + { +// m_listBox->setFocus (); + return; + } + + else if ( e->key () >= Qt::Key_0 && e->key () <= Qt::Key_9 ) + { + printf ( "%d \n", e->key () ); + emit runItemAt ( e->key () ); + return; + } + + else if ( e->key () == Qt::Key_Left ) + { + m_canvasView->setFocus (); + m_canvasView->emulatedKeyPress ( e ); + return; + } +*/ + + m_search->show (); + m_search->setText ( m_search->text () + e->text () ); + e->ignore(); +} + +#include "kbfxspinxmenu.moc" diff --git a/src/kbfxspinxmenu.h b/src/kbfxspinxmenu.h new file mode 100644 index 0000000..19986cc --- /dev/null +++ b/src/kbfxspinxmenu.h @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_SPINX_MENU_WIDGET_H +#define KBFX_SPINX_MENU_WIDGET_H + +#include <qapplication.h> +#include <qbitmap.h> +#include <qcanvas.h> +#include <qframe.h> +#include <qhbox.h> +#include <qimage.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qlineedit.h> +#include <qpixmap.h> +#include <qstringlist.h> +#include <qvbox.h> +#include <qwidget.h> + +#include <kdebug.h> +#include <klocale.h> + +//#include <kbfxdatasource.h> +#include <kbfxconfig.h> +#include <kbfxdatastack.h> +#include <kbfxpixmaplabel.h> +#include <kbfxplasmapixmapprovider.h> +#include <kbfxplasmapluginloader.h> + +//#include "kbfxplasmalistview.h" +//#include "kbfxplasmalistbox.h" +#include "kbfxplasmacanvasgroup.h" +#include "kbfxplasmacanvasview.h" +#include "kbfxplasmaindexview.h" +#include "kbfxsignal.h" +#include "kbfxspinxscrollbar.h" +#include "kbfxspinxtoolbar.h" +#include "kbfxspinxtoolbutton.h" +#include "kbfxspinxtop.h" +#include "kbfxspinxview.h" + + +class KbfxSpinxMenuWidget:public QWidget +{ + Q_OBJECT + public : + KbfxSpinxMenuWidget ( QWidget * parent = 0, const char * name = 0,WFlags fl =0 ); + virtual ~KbfxSpinxMenuWidget(); +// virtual void mouseMoveEvent(QMouseEvent * me); +// virtual void focusInEvent ( QFocusEvent * ) ; + virtual void keyPressEvent ( QKeyEvent * e ) ; + void grabEvent ( QKeyEvent * e ) { keyPressEvent ( e );} + void loadHistory(); + void resizeContent(); + void reinit(); + public slots: + void hideMenu(); +// void propergateMove(QMouseEvent * me); + void loadPluginLeft ( QString name ); + void loadPluginRight ( QString name ); + void enterPressed(); + void search_clear ( const ButtonState & ); +// void changeHeight(int h); + signals: + void nowHidden(); + void runItem(); + void runItemAt ( int i ); + void leads(); + void refresh(); + + private: + void init(); + QPoint menuPosition(); + void createMask(); + KbfxPlasmaCanvasView * m_canvasView; +// KbfxPlasmaCanvasView * m_indexView; + QCanvas * m_canvas ; +// KbfxPlasmaListBox * m_listBox; + KbfxPlasmaPluginLoader * m_loader; + KbfxSpinxTop * m_menuTop; + QString m_loadedListLeft; + QString m_loadedListRight; +// FIXME: canvasstack is depricated Interface + KbfxPlasmaCanvasStack * m_stack; + KbfxDataStack * m_stack_R; + QWidget * m_parent; + QLineEdit * m_search; + KbfxPixmapLabel * m_searchTag; + KbfxSpinxToolBar * m_toolBarBot; + KbfxSpinxToolBar * m_toolBarSide; + int m_h; + +/* SUPER NEW LAYOUT FIX HERE */ + + QBoxLayout * m_fixedFrame; + QBoxLayout * m_middleFrame; + QCanvas * m_appCanvas; + QCanvas * m_indexCanvas; + QCanvas * m_indexLeftCanvas; + + KbfxPlasmaIndexView * m_indexView; + + KbfxPlasmaIndexView * m_indexLeftView; + KbfxSpinxTop * m_kbfxSpinxTop; +}; + +#endif diff --git a/src/kbfxspinxpopup.cpp b/src/kbfxspinxpopup.cpp new file mode 100644 index 0000000..2270eb8 --- /dev/null +++ b/src/kbfxspinxpopup.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +// +// C++ Implementation: kbfxspinxpopup +// +// Description: +// +// +// Author: Siraj Razick <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "kbfxspinxpopup.h" + +KbfxSpinxPopUp::KbfxSpinxPopUp ( QWidget * parent, const char * name ) :QPopupMenu ( parent,name ) +{ + m_mainItem = 0L; +} + + +KbfxSpinxPopUp::~KbfxSpinxPopUp() +{ +} + +void +KbfxSpinxPopUp::keyPressEvent ( QKeyEvent * e ) +{ +/* + if ( e->key() == Qt::Key_Tab ) + { + return ; + } + if ( e->key() == Qt::Key_Up ) + { + m_mainItem->grabEvent ( e ); +// e->ignore(); + return ; + } +*/ + m_mainItem->grabEvent ( e ); +} + +void +KbfxSpinxPopUp::addItem ( QWidget * item,int index ) +{ + m_mainItem = ( KbfxSpinxMenuWidget* ) item; + this->insertItem ( item,index ); + +} +#include "kbfxspinxpopup.moc" diff --git a/src/kbfxspinxpopup.h b/src/kbfxspinxpopup.h new file mode 100644 index 0000000..882d665 --- /dev/null +++ b/src/kbfxspinxpopup.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +// +// C++ Interface: kbfxspinxpopup +// +// Description: +// +// +// Author: Siraj Razick <[email protected]>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef KBFX_SPINX_POP_UP_H +#define KBFX_SPINX_POP_UP_H + +#include <qpopupmenu.h> +#include "kbfxspinxmenu.h" + + + +/** + @author Siraj Razick <[email protected]> +*/ +class KbfxSpinxPopUp : public QPopupMenu +{ + Q_OBJECT + + public: + KbfxSpinxPopUp ( QWidget * parent = 0, const char * name = 0 ) ; + + ~KbfxSpinxPopUp(); + virtual void keyPressEvent ( QKeyEvent * ke ); + void addItem ( QWidget * item,int index ); + private: + KbfxSpinxMenuWidget * m_mainItem; +}; + +#endif diff --git a/src/kbfxspinxscrollbar.cpp b/src/kbfxspinxscrollbar.cpp new file mode 100644 index 0000000..6fcff50 --- /dev/null +++ b/src/kbfxspinxscrollbar.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxspinxscrollbar.h" + +KbfxSpinxScrollBar::KbfxSpinxScrollBar ( QWidget * parent, const char *name, int type ) : + QWidget ( parent, name ) +{ + if (type == 0){ + m_normal = ( *KbfxPlasmaPixmapProvider::pixmap ( "scrollnormal" ) ); + } else { + m_normal = ( *KbfxPlasmaPixmapProvider::pixmap ( "scrollnormalbot" ) ); + } + QImage _tmp_img = m_normal.convertToImage(); + _tmp_img = _tmp_img.smoothScale ( ConfigInit().m_itemView_w, m_normal.height (),QImage::ScaleFree ); + m_normal = QPixmap ( _tmp_img ); + + this->resize ( m_normal.width (), m_normal.height () ); + + _x = this->x () /40; + _y = this->y (); + w = this->width () / 40; + h = this->height () / 2; + _x += ( this->width () - w ) / 2; + _y += ( this->height () - h ) / 2; + m_triAngle = QPointArray ( 3 ); + m_dir = DOWN; + m_timer = new QTimer ( this,"ScrollTimer" ); + connect ( m_timer,SIGNAL ( timeout() ),this,SLOT ( timeoutslot() ) ); + m_pressed = false; + +} + +KbfxSpinxScrollBar::~KbfxSpinxScrollBar () +{} + +void +KbfxSpinxScrollBar::paintEvent ( QPaintEvent * pe ) +{ + QRect r = pe->rect(); + QPainter p; + p.begin ( this ); + p.drawPixmap ( QRect ( 0, 0, m_normal.width (), m_normal.height () ), + m_normal ); + p.setPen ( QColor ( 255,255,255 ) ); + if ( m_pressed == false ) + p.setBrush ( QColor ( 255,255,255 ) ); + else + p.setBrush ( QColor ( 0,0,0 ) ); + + p.drawPolygon ( m_triAngle ); + p.end (); + +} + +void +KbfxSpinxScrollBar::setType ( Direction dir ) +{ + if ( dir == DOWN ) + { + m_triAngle.setPoint ( 0, _x, _y ); + m_triAngle.setPoint ( 1, _x + w, _y ); + m_triAngle.setPoint ( 2, _x + w / 2, _y + h ); + + } + else if ( dir == UP ) + { + m_triAngle.setPoint ( 0, _x, _y + h ); + m_triAngle.setPoint ( 1, _x + w, _y + h ); + m_triAngle.setPoint ( 2, _x + w / 2, _y ); + } + m_dir = dir; +} + + +void +KbfxSpinxScrollBar::mousePressEvent ( QMouseEvent * me ) +{ + me = me; + m_pressed = true; + m_timer->start ( 50,false ); + update(); +} + +void +KbfxSpinxScrollBar::mouseReleaseEvent ( QMouseEvent * me ) +{ + me = me; + m_pressed = false; + m_timer->stop(); + update(); +} + + +void +KbfxSpinxScrollBar::enterEvent ( QEvent * e ) +{ + e = e; + m_pressed = true; + m_timer->start ( 50,false ); + update(); +} + +void +KbfxSpinxScrollBar::leaveEvent ( QEvent *e ) +{ + e =e ; + m_pressed = false; + m_timer->stop(); + update(); + +} + + +void +KbfxSpinxScrollBar::timeoutslot() +{ + if ( m_dir == DOWN ) + emit scroll ( 0,20 ); + else if ( m_dir == UP ) + emit scroll ( 0,-20 ); +} + +#include "kbfxspinxscrollbar.moc" diff --git a/src/kbfxspinxscrollbar.h b/src/kbfxspinxscrollbar.h new file mode 100644 index 0000000..c159bc3 --- /dev/null +++ b/src/kbfxspinxscrollbar.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_SPINX_SCROLL_BAR_H +#define KBFX_SPINX_SCROLL_BAR_H + +#include <qimage.h> +#include <qpainter.h> +#include <qpixmap.h> +#include <qpointarray.h> +#include <qtimer.h> +#include <qwidget.h> + +#include <kbfxplasmapixmapprovider.h> + + +class QWidget; + +class KbfxSpinxScrollBar:public QWidget +{ + + Q_OBJECT + public: + typedef enum {UP,DOWN,LEFT,RIGHT} Direction; + KbfxSpinxScrollBar ( QWidget * parent = 0,const char * name = 0,int type = 0 ); + ~KbfxSpinxScrollBar(); + virtual void paintEvent ( QPaintEvent * ev ); + virtual void mousePressEvent ( QMouseEvent * me ); + virtual void mouseReleaseEvent ( QMouseEvent * me ); + virtual void enterEvent ( QEvent * e ); + virtual void leaveEvent ( QEvent * e ); + void setType ( Direction dir ); + public slots: + void timeoutslot(); + + signals: + void scrollUp(); + void scrollDown(); + void scroll ( int , int ); + + private: + QPixmap m_normal; + QPixmap m_hover; + QPixmap m_presseod; + QPointArray m_triAngle; + Direction m_dir; + QTimer * m_timer; + bool m_pressed; + + + // + int _x; + int _y; + int w; + int h; +}; + +#endif diff --git a/src/kbfxspinxtoolbar.cpp b/src/kbfxspinxtoolbar.cpp new file mode 100644 index 0000000..8a35f15 --- /dev/null +++ b/src/kbfxspinxtoolbar.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxspinxtoolbar.h" + +KbfxSpinxToolBar::KbfxSpinxToolBar ( QWidget * parent , const char * name , WFlags l ) :QWidget ( parent,name,l ) +{ + + _y = 0; + m_bg = ( *KbfxPlasmaPixmapProvider::pixmap ( "botbg" ) ); +// _x = m_bg.width(); + _x = ConfigInit().m_botBar_w; +} + + +KbfxSpinxToolBar::~KbfxSpinxToolBar() +{} + +void +KbfxSpinxToolBar::setSize ( QSize size ) +{ + this->resize ( size ); + _x = size.width(); + _y = size.height(); + +} + + +void KbfxSpinxToolBar::addButton ( KbfxSpinxToolButton * btn ) +{ +// KbfxSpinxToolButton * _btn = btn; + _x -= btn->width(); +// btn->resize(this->height()-10,this->height()-10); + btn->move ( _x, ( this->height()-btn->height() ) /4 ); + btn->show(); + btn->update(); +} + +void KbfxSpinxToolBar::paintEvent ( QPaintEvent * pe ) +{ + pe = pe ; + QPainter p; + p.begin ( this ); + p.drawPixmap ( QRect ( 0,0,ConfigInit().m_botBar_w,ConfigInit().m_botBar_h ),m_bg ); + p.end(); +} + + +#include "kbfxspinxtoolbar.moc" diff --git a/src/kbfxspinxtoolbar.h b/src/kbfxspinxtoolbar.h new file mode 100644 index 0000000..7ad8539 --- /dev/null +++ b/src/kbfxspinxtoolbar.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_SPINX_TOOL_BAR_H +#define KBFX_SPINX_TOOL_BAR_H + +#include <qpainter.h> +#include <qpixmap.h> +#include <qstring.h> +#include <qwidget.h> + +#include <kbfxconfig.h> +#include <kbfxplasmapixmapprovider.h> + +#include "kbfxspinxtoolbutton.h" + +class KbfxSpinxToolBar:public QWidget +{ + + Q_OBJECT + public: + KbfxSpinxToolBar ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ); + virtual ~KbfxSpinxToolBar(); + virtual void paintEvent ( QPaintEvent * pe ); + + void addButton ( KbfxSpinxToolButton * btn ); + void setSize ( QSize s ); + + private: + int _x; + int _y; + int m_buttonWidth; + int m_buttonHeight; + QPixmap m_bg; + + +}; + +#endif diff --git a/src/kbfxspinxtoolbutton.cpp b/src/kbfxspinxtoolbutton.cpp new file mode 100644 index 0000000..3230e14 --- /dev/null +++ b/src/kbfxspinxtoolbutton.cpp @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxspinxtoolbutton.h" + +KbfxSpinxToolButton::KbfxSpinxToolButton ( QWidget * parent , const char * name ) :QLabel ( parent,name,Qt::WStaticContents | Qt::WNoAutoErase |Qt::WPaintDesktop ) +{ + m_dataSource = 0; + m_dataGroup = 0; + m_fadeTime = ConfigInit().m_fadeTime; + + fade_timer = new QTimer ( this,"Fade Timer" ); + connect ( fade_timer,SIGNAL ( timeout() ),this,SLOT ( fade() ) ); +} + + +KbfxSpinxToolButton::~KbfxSpinxToolButton() +{} + +void KbfxSpinxToolButton::fade ( ) +{ + if ( m_fadeTime == 0 ) + { + m_current = m_fadePix; + } + else + { + QImage _final = m_fadePix.convertToImage (); + QImage _current = m_current.convertToImage (); + + if ( !fade_timer->isActive ()) + { + m_opacity = 0; + fade_timer->start( m_fadeTime, false); + } + if ( m_opacity > 0.9 ) + fade_timer->stop(); + m_opacity += 0.1; + + KImageEffect::blend ( _final, _current, m_opacity); + m_current = QPixmap ( _current ); + } + this->resize ( m_current.size() ); + this->update(); +} + +void +KbfxSpinxToolButton::enterEvent ( QEvent * e ) +{ + e = e; + m_fadePix = m_hover; + fade(); + this->setCursor ( QCursor ( Qt::PointingHandCursor ) ); +} + +void +KbfxSpinxToolButton::leaveEvent ( QEvent * e ) +{ + e = e; + m_fadePix = m_normal; + fade(); + this->setCursor ( QCursor ( Qt::ArrowCursor ) ); +} + +void +KbfxSpinxToolButton::setPixmaps ( QPixmap normal, QPixmap hover ) +{ + QSize _sizeNormal = normal.size(); + QImage _tmpHover = hover.convertToImage (); + _tmpHover = _tmpHover.smoothScale ( _sizeNormal, QImage::ScaleFree ); + + m_normal = normal; + m_hover = QPixmap ( _tmpHover ); + m_current = m_normal; + + resize ( m_current.size () ); + this->repaint(); + this->update(); +} + + +void +KbfxSpinxToolButton::setDataSource ( KbfxDataSource * src ) +{ + m_name = src->name(); + m_icon = src->icon(); + m_exe = src->command(); + m_dataSource = new KbfxDataSource(); + *m_dataSource = *src; // copy + KIconLoader *iconload = KGlobal::iconLoader (); + QString m_iconPath = iconload->iconPath ( m_icon, KIcon::Desktop, false ); + m_iconPixmap = QPixmap ( m_iconPath ); +} + +void +KbfxSpinxToolButton::paintEvent ( QPaintEvent * e ) +{ + QRect r = e->rect(); + QPainter p; + QPixmap buffer ( m_current.size() ); + buffer.fill(); + p.begin ( this ); + p.setPen ( QColor ( 255,255,255 ) ); + p.drawPixmap ( QRect ( 0, 0, m_current.width(), m_current.height() ), m_current ); + p.end(); +} + + +void +KbfxSpinxToolButton::mouseReleaseEvent ( QMouseEvent * me ) +{ + me = me; + if ( m_dataSource == 0 ) + return; + else + KRun::runCommand ( m_dataSource->command() ); + + emit clicked(); +} + +#include "kbfxspinxtoolbutton.moc" diff --git a/src/kbfxspinxtoolbutton.h b/src/kbfxspinxtoolbutton.h new file mode 100644 index 0000000..2c3d9bf --- /dev/null +++ b/src/kbfxspinxtoolbutton.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_SPINX_TOOL_BUTTON_H +#define KBFX_SPINX_TOOL_BUTTON_H + +#include <qcursor.h> +#include <qimage.h> +#include <qlabel.h> +#include <qpainter.h> +#include <qpixmap.h> +#include <qtimer.h> +#include <qtoolbutton.h> +#include <qwidget.h> + +#include <kiconloader.h> +#include <kimageeffect.h> +#include <krun.h> + +#include <kbfxconfig.h> +#include <kbfxdatagroup.h> +#include <kbfxdatasource.h> +#include <kbfxplasmapixmapprovider.h> + +class KbfxSpinxToolButton:public QLabel +{ + + Q_OBJECT + public: + typedef enum{SINGLE=0,EXPANDABLE} ButtonType; + + KbfxSpinxToolButton ( QWidget * parent = 0, const char * name = 0 ); + virtual ~KbfxSpinxToolButton(); + virtual void paintEvent ( QPaintEvent * pe ); + + virtual void enterEvent ( QEvent * e ); + virtual void leaveEvent ( QEvent * l ); + virtual void mouseReleaseEvent ( QMouseEvent * me ); + /* + virtual void mousePressEvent(QMouseEvent * me); + */ + void setDataSource ( KbfxDataSource * src ); +// void setDataGroup(KbfxDataGroup * gsrc); + void setName ( QString name ) {m_name =name;} + void setExec ( QString cmd ) { m_exe = cmd;} + void setType ( KbfxSpinxToolButton::ButtonType type ) { m_type = type;} + void setIcon ( QString path ); + void setPixmaps ( QPixmap , QPixmap ); + + public slots: + void fade(); + + signals: + void clicked(); + private: + QString m_name; + QString m_exe; + QString m_icon; + QString m_tooltip; + + QPixmap m_normal; + QPixmap m_pressed; + QPixmap m_hover; + QPixmap m_current; + QPixmap m_iconPixmap; + KbfxDataSource * m_dataSource; + KbfxDataGroup * m_dataGroup; + ButtonType m_type; + bool m_statePressed; + QTimer * fade_timer; + float m_opacity; + QPixmap m_fadePix; + int m_fadeTime; +}; + +#endif diff --git a/src/kbfxspinxtop.cpp b/src/kbfxspinxtop.cpp new file mode 100644 index 0000000..617e884 --- /dev/null +++ b/src/kbfxspinxtop.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxspinxtop.h" + +KbfxSpinxTop::KbfxSpinxTop ( QWidget * parent,const char * name ) :QWidget ( parent,name,Qt::WNoAutoErase | WStaticContents | Qt::WPaintClever | Qt::WNoAutoErase ) +{ + + m_background = ( *KbfxPlasmaPixmapProvider::pixmap ( "topbg" ) ); + m_currentTextBuffer = ""; + + this->resize ( ConfigInit().m_topBar_w,ConfigInit().m_topBar_h ); +// this->resize(m_background.size()); + loadFaceIcon(); + createDudeBox(); + m_userName=getUserName(); + +} + +KbfxSpinxTop::~KbfxSpinxTop() +{} + +void +KbfxSpinxTop::mousePressEvent ( QMouseEvent * e ) +{ + e = e; + emit sizeChange ( 10 ); +} + +void +KbfxSpinxTop::createDudeBox() +{ + m_dudeBox = ( *KbfxPlasmaPixmapProvider::pixmap ( "dudebox" ) ); +// int padding = ((m_dudeBox.height()-m_faceIcon.height()))/2; + + QPainter p; + p.begin ( &m_dudeBox ); +// p.drawPixmap(QRect(padding,padding,m_faceIcon.width(),m_faceIcon.height()),m_faceIcon); + p.drawPixmap ( QRect ( ConfigInit().m_faceIconX,ConfigInit().m_faceIconY,ConfigInit().m_faceIconW,ConfigInit().m_faceIconH ),m_faceIcon ); + p.end(); + +} + + +QString +KbfxSpinxTop::getUserName () +{ + KUser *user = new KUser (); + QString logInName ( user->fullName () ); +// Nookie says some might find it discriminating... We don't want that. + if ( logInName == "root" ) + logInName = QString ( "Administrator" ); + delete user; + return logInName.upper (); +} + + + +void +KbfxSpinxTop::loadFaceIcon() +{ + QImage UserImage ( ConfigInit().m_SpinxDudeImage ); + UserImage = UserImage.smoothScale ( 48, 48 ); + m_faceIcon = QPixmap ( UserImage ); +} + + +void +KbfxSpinxTop::paintEvent ( QPaintEvent * pe ) +{ + pe = pe; + QRect * r = new QRect ( 0,0,ConfigInit().m_topBar_w,ConfigInit().m_topBar_h ); + + m_pixmapbuff = new QPixmap(); + m_pixmapbuff->resize ( r->size() ); + m_pixmapbuff->fill ( this, r->topLeft() ); + + QPainter p; + p.begin ( m_pixmapbuff,this ); +// Draw commands are here + p.drawPixmap ( *r,m_background ); + p.setPen ( QColor ( ConfigInit().m_userNameColor ) ); + + p.drawPixmap ( QRect ( ConfigInit().m_facePos_x,ConfigInit().m_facePos_y,m_dudeBox.width(),m_dudeBox.height() ),m_dudeBox ); + if ( !ConfigInit().m_faceBoxHideText ) + { + QFont * _font = new QFont(ConfigInit().m_userNameFont); + p.setFont ( *_font ); +// p.setPen(QColor(199,187,206)); +// p.drawText(ConfigInit().m_userNamePos_x+1,ConfigInit().m_userNamePos_y+2,m_userName); + p.setPen ( QColor ( ConfigInit().m_userNameColor ) ); + p.drawText ( ConfigInit().m_userNamePos_x,ConfigInit().m_userNamePos_y,m_userName ); + delete _font; + } + p.end(); + + bitBlt ( this, r->x(), r->y(),m_pixmapbuff, 0, 0, + r->width(), r->height() ); + +// delete [] pe; + delete m_pixmapbuff; + delete r; +} + +#include "kbfxspinxtop.moc" diff --git a/src/kbfxspinxtop.h b/src/kbfxspinxtop.h new file mode 100644 index 0000000..b6cf811 --- /dev/null +++ b/src/kbfxspinxtop.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_SPINX_TOP_H +#define KBFX_SPINX_TOP_H + +#include <qimage.h> +#include <qpainter.h> +#include <qpixmap.h> +#include <qwidget.h> + +#include <kiconloader.h> +#include <klineedit.h> +#include <kuser.h> + +#include <kbfxconfig.h> +#include <kbfxplasmapixmapprovider.h> + +class KbfxSpinxTop:public QWidget +{ + Q_OBJECT + + public: + KbfxSpinxTop ( QWidget * parent = 0,const char * name = 0 ); + virtual ~KbfxSpinxTop(); + + virtual void paintEvent ( QPaintEvent * ); + virtual void mousePressEvent ( QMouseEvent * e ) ; + + public slots: + + signals: + void textChanged ( QString ); + void sizeChange ( int ); + + private: + void loadFaceIcon(); + void createDudeBox(); + QString getUserName(); + + QPixmap m_background; + QPixmap * m_pixmapbuff; + QPixmap m_faceIcon; + QPixmap m_dudeBox; + QString m_currentTextBuffer; + QString m_userName; + QPixmap m_iconPixmap; + QTimer * m_fadeTimer; + + +}; + +#endif diff --git a/src/kbfxspinxview.cpp b/src/kbfxspinxview.cpp new file mode 100644 index 0000000..65c01bc --- /dev/null +++ b/src/kbfxspinxview.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kbfxspinxview.h" + +KbfxSpinxView::KbfxSpinxView ( QWidget * parent , const char * name,WFlags flag ) :QFrame ( parent,name,flag ) +{ + setMinimumWidth ( 300 ); + setMinimumHeight ( 365 ); + setMouseTracking ( true ); +} + +KbfxSpinxView::~KbfxSpinxView() +{} + +#include "kbfxspinxview.moc" + diff --git a/src/kbfxspinxview.h b/src/kbfxspinxview.h new file mode 100644 index 0000000..42d1cb6 --- /dev/null +++ b/src/kbfxspinxview.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_SPINX_VIEW_H +#define KBFX_SPINX_VIEW_H + +#include <qframe.h> + +class KbfxSpinxView:public QFrame +{ + + Q_OBJECT + + public: + KbfxSpinxView ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ); + ~KbfxSpinxView(); + + public slots: + + private: +}; + +#endif diff --git a/src/kbfxtooltip.cpp b/src/kbfxtooltip.cpp new file mode 100644 index 0000000..bce755c --- /dev/null +++ b/src/kbfxtooltip.cpp @@ -0,0 +1,306 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#include "kbfxtooltip.h" + +KbfxToolTip::KbfxToolTip ( QWidget * parent, const char *name, WFlags fl ) : + QWidget ( parent, name, + fl | WStyle_Customize | WRepaintNoErase | WStyle_NoBorder | + WDestructiveClose | Qt::WPaintDesktop | Qt::WType_Popup | Qt:: + WPaintClever | Qt::WNoAutoErase | Qt::WResizeNoErase | Qt:: + WStaticContents | Qt::WNoAutoErase ) +{ + _animate = ConfigInit ().m_ToolTipAnimation; + m_fontTooltipFont = ConfigInit ().m_fontTooltipFont; + + logo = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit().m_SpinxTooltipLogo ) ) ? + QImage ( ConfigInit().m_SpinxTooltipLogo ) + : QImage ( ConfigInit().m_SpinxTooltipLogoDefault ); + + tooltip_win = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_SpinxTooltipWindow ) ) ? + QImage ( ConfigInit ().m_SpinxTooltipWindow ) + : QImage ( ConfigInit ().m_SpinxTooltipWindowDefault ); + + tooltip_mask = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit().m_SpinxTooltipMask ) ) ? + QImage ( ConfigInit().m_SpinxTooltipMask ) + : QImage ( ConfigInit().m_SpinxTooltipMaskDefault ); + + dude_img = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_SpinxDudeImage ) ) ? + QImage ( ConfigInit ().m_SpinxDudeImage ) + : QImage ( ConfigInit ().m_SpinxDudeImageDefault ); + + setUserImage (); + setBoundBox (); + setBackground ( QPixmap () ); + setWindow ( QPixmap () ); + KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_ToolTipAvatar ) ? + setAnimationImage ( ConfigInit ().m_ToolTipAvatar ) + : setAnimationImage ( ConfigInit ().m_ToolTipAvatarDefault ); + + _hide_timer = new QTimer ( this ); + _update_timer = new QTimer ( this ); + _move_timer = new QTimer ( this ); + + connect ( _hide_timer, SIGNAL ( timeout () ), this, SLOT ( hide () ) ); + connect ( _hide_timer, SIGNAL ( timeout () ), _agent, SLOT ( hide () ) ); + connect ( _update_timer, SIGNAL ( timeout () ), this, SLOT ( logoMove () ) ); + + QCursor kbfxCursor; + kbfxCursor.setShape ( Qt::PointingHandCursor ); + this->setCursor ( ( const QCursor ) kbfxCursor ); +} + +KbfxToolTip::~KbfxToolTip () +{ + delete _hide_timer; + delete _move_timer; + delete _update_timer; + delete _window; + delete _agent; + delete _agent_anim; +} + +void +KbfxToolTip::setWindow ( QPixmap win ) +{ + QImage m_win_img; + + ( win.isNull () ) ? + m_win_img = tooltip_win + : m_win_img = win.convertToImage (); + + m_win_img = m_win_img.smoothScale ( _bg.width (), 13 ); +// _window = new QLabel (this, "", Qt::WStaticContents | Qt::WNoAutoErase); + _window = new QLabel ( this, "" ); + _window->resize ( _bg.width (), 13 ); + _window->setBackgroundPixmap ( m_win_img ); + if ( _animate ) + _window->show (); + else + _window->hide (); +} + +void +KbfxToolTip::setAnimationImage ( QString path ) +{ + /* + _agent = new QLabel (this, "", + Qt::WStaticContents | + Qt::WNoAutoErase | Qt::WPaintDesktop); + */ + _agent = new QLabel ( this,"" ); + _agent->resize ( 100, 100 ); + + _agent_anim = new QMovie ( path ); + QPixmap agent_mask = _agent_anim->framePixmap (); + _agent->setBackgroundPixmap ( agent_mask ); + if ( agent_mask.mask () ) + _agent->setMask ( *agent_mask.mask () ); + _agent->repaint (); + + /*FIXME:Need to remove Hard Coded Values */ + _agent->move ( 200, 0 ); + + if ( _animate ) + _agent->show (); + else + _agent->close (); +} + + +void +KbfxToolTip::setBackground ( QPixmap bg ) +{ + + ( bg.isNull () ) ? + _bg = tooltip_mask + : _bg = bg.convertToImage (); + + /* animation check : Auto streatch */ + if ( _animate ) + { + QImage m_tmp = _bg; + _bg = m_tmp.smoothScale ( _bg.width () + 100, _bg.height () ); + } + + this->setBackgroundPixmap ( _bg ); + + QPixmap m_tmp ( _bg ); + if ( m_tmp.mask () ) + this->setMask ( ( *m_tmp.mask () ) ); + this->resize ( _bg.width (), _bg.height () ); + _maxW = _bg.width (); +} + +void +KbfxToolTip::setStartPos ( int _x_, int _y_ ) +{ + _x = _x_; + _y = _y_; + _logo_move_x = 100; + if ( _animate ) + { + _logo_move_x = 0; + _hide_timer->start ( 10000, TRUE ); + _move_timer->start ( _agent_anim->speed (), FALSE ); + _update_timer->start ( 2, FALSE ); + } + + move ( _x, _y ); +} + +void +KbfxToolTip::logoMove () +{ + QPainter p; + + if ( _logo_move_x < _bg.width () - 68 ) + { + _logo_move_x += 1; + _window->repaint (); + + p.begin ( _window ); + p.drawPixmap ( QRect ( _logo_move_x, 0, logo.width (), logo.height () ), + QPixmap ( logo ) ); + p.end (); + } + else + { + p.begin ( _window ); + p.drawPixmap ( QRect ( _bg.width () - 68, 0, logo.width (), logo.height () ), + QPixmap ( logo ) ); + p.end (); + } + + QPixmap agent_mask = _agent_anim->framePixmap (); + _agent->setBackgroundPixmap ( agent_mask ); + if ( agent_mask.mask () ) + _agent->setMask ( *agent_mask.mask () ); + _agent->repaint (); +} + +void +KbfxToolTip::setAnimated ( bool b ) +{ + _animate = b; +} + + +void +KbfxToolTip::setLabelText ( QString str ) +{ + _label_text = str; +} + +void +KbfxToolTip::setHeadingText ( QString str ) +{ + _heading_text = str; +} + +void +KbfxToolTip::setVersionText ( QString str ) +{ + _version_text = str; +} + +void +KbfxToolTip::hideToolTip () +{ + _move_timer->stop (); + _hide_timer->stop (); + + _agent->close (); + this->hide (); + this->close (); +} + + +void +KbfxToolTip::setUserImage () +{ + QImage userimage = dude_img; + userimage = userimage.smoothScale ( 48, 48 ); + _dude = QPixmap ( userimage ); +} + +void +KbfxToolTip::setBoundBox () +{ + _dude_box = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_SpinxTooltipDudebox ) ) ? + QPixmap ( ConfigInit ().m_SpinxTooltipDudebox ) + : QPixmap ( ConfigInit ().m_SpinxTooltipDudeboxDefault ); +} + + +void +KbfxToolTip::paintEvent ( QPaintEvent * pe ) +{ + + const QRect r = pe->rect (); + QFont *let = new QFont (m_fontTooltipFont); + + QPainter p; + p.begin ( this ); + p.setBackgroundMode ( Qt::TransparentMode ); + p.drawPixmap ( QRect ( 7, 16, _dude_box.width (), _dude_box.height () ), + _dude_box ); + int _paddingX = ( ( _dude_box.height () - _dude.height () ) / 2 ) + 16; + p.drawPixmap ( QRect + ( _paddingX - ( 55 - 48 ), _paddingX, _dude.width (), + _dude.height () ), _dude ); + + if ( _animate ) + {} + else + { + + p.drawPixmap ( QRect ( 126, 0, logo.width (), logo.height () ), + QPixmap ( QImage (ConfigInit ().m_SpinxTooltipLogo ) ) ); + } + + let->setBold ( TRUE ); + let->setPointSize ( 10 ); + p.setFont ( *let ); + p.setPen ( QColor ( 61, 94, 129 ) ); + p.drawText ( _dude_box.width () + 15, 30, "KBFX" ); + + p.setPen ( QColor ( 0, 0, 0 ) ); + let->setBold ( FALSE ); + let->setPointSize ( 8 ); + p.setFont ( *let ); + p.drawText ( ( _animate ) ? _dude_box.width () + 50 : _dude_box.width () + 4, + _dude_box.height () + 30, QString ( "Version " ).append ( APPLICATION_VERSION ) ); + + p.setPen ( ConfigInit ().m_fontTooltipColor ); + let->setBold ( TRUE ); + let->setPointSize ( 8 ); + p.setFont ( *let ); + + + p.drawText ( _dude_box.width () + 15, 43, ConfigInit ().m_ToolTipText ); + p.end (); + delete let; +} + +#include "kbfxtooltip.moc" diff --git a/src/kbfxtooltip.h b/src/kbfxtooltip.h new file mode 100644 index 0000000..b358f5a --- /dev/null +++ b/src/kbfxtooltip.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2006 + * Siraj Razick <[email protected]> + * PhobosK <[email protected]> + * see Also AUTHORS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KBFX_TOOL_TIP +#define KBFX_TOOL_TIP + +#include <qcursor.h> +#include <qimage.h> +#include <qlabel.h> +#include <qmovie.h> +#include <qpainter.h> +#include <qpixmap.h> +#include <qtimer.h> +#include <qwidget.h> + +#include <kdebug.h> +#include <kiconloader.h> +#include <kicontheme.h> +#include <kstandarddirs.h> +#include <ktip.h> +#include <kuser.h> + +#include <kbfxconfig.h> + +#include <kbfxplasmapixmapprovider.h> + +class KbfxToolTip:public QWidget +{ + + Q_OBJECT + public: + KbfxToolTip ( QWidget * parent=0,const char * name=0,WFlags fl=WType_TopLevel ); + ~KbfxToolTip(); + void setStartPos ( int x=0, int y=0 ); + virtual void paintEvent ( QPaintEvent *pe ); + void setBackground ( QPixmap bg ); + void setAnimationImage ( QString path ); + void setWindow ( QPixmap win ); + + public slots: + void hideToolTip(); + void logoMove(); + void setUserImage(); + void setBoundBox(); + void setAnimated ( bool ); + void setLabelText ( QString ); + void setHeadingText ( QString ); + void setVersionText ( QString ); + + private: + QTimer * _hide_timer; + QTimer * _move_timer; + QTimer * _update_timer; + int _x,_y; + int _maxW; + int _width; + int _height; + int _logo_move_x; + QPixmap _dude; + QPixmap _dude_box; + QImage _bg; + QLabel * _window; + QLabel * _agent; + QMovie * _agent_anim; + bool _animate; + QString _label_text; + QString _heading_text; + QString _version_text; + QFont m_fontTooltipFont; + QImage logo; + QImage tooltip_win; + QImage tooltip_mask; + QImage dude_img; +}; +#endif |