00001 /* 00002 * copyright : (c) 2003 by Greg Gilbert 00003 * email : greg@treke.net 00004 * based on the cardmon applet by Max Reiss 00005 * * 00006 * This program is free software; you can redistribute it and/or modify * 00007 * it under the terms of the GNU General Public License as published by * 00008 * the Free Software Foundation; either version 2 of the License, or * 00009 * (at your option) any later version. * 00010 * * 00011 *************************************************************************/ 00012 00013 #include "autorotate.h" 00014 00015 /* OPIE */ 00016 #include <opie2/odebug.h> 00017 #include <opie2/otaskbarapplet.h> 00018 #include <opie2/oresource.h> 00019 #include <qpe/applnk.h> 00020 #include <qpe/config.h> 00021 using namespace Opie::Core; 00022 00023 /* QT */ 00024 #include <qpainter.h> 00025 00026 AutoRotate::AutoRotate(QWidget * parent):QWidget(parent) 00027 { 00028 setFixedWidth( AppLnk::smallIconSize() ); 00029 setFixedHeight( AppLnk::smallIconSize() ); 00030 00031 enabledPm = Opie::Core::OResource::loadImage("autorotate/rotate", Opie::Core::OResource::SmallIcon); 00032 disabledPm = Opie::Core::OResource::loadImage("autorotate/norotate", Opie::Core::OResource::SmallIcon); 00033 00034 repaint(true); 00035 popupMenu = 0; 00036 show(); 00037 } 00038 00039 AutoRotate::~AutoRotate() 00040 { 00041 if (popupMenu) { 00042 delete popupMenu; 00043 } 00044 } 00045 00046 int AutoRotate::position() 00047 { 00048 return 7; 00049 } 00050 00051 void AutoRotate::mousePressEvent(QMouseEvent *) 00052 { 00053 QPopupMenu *menu = new QPopupMenu(this); 00054 menu->insertItem( isRotateEnabled()? "Disable Rotation" : "Enable Rotation" ,1 ); 00055 00056 QPoint p = mapToGlobal(QPoint(0, 0)); 00057 QSize s = menu->sizeHint(); 00058 int opt = menu->exec(QPoint(p.x() + (width() / 2) - (s.width() / 2), p.y() - s.height()), 0); 00059 00060 if (opt==1) 00061 { 00062 setRotateEnabled( !isRotateEnabled() ); 00063 repaint(true); 00064 } 00065 00066 delete menu; 00067 } 00068 00069 void AutoRotate::paintEvent(QPaintEvent *) 00070 { 00071 QPainter p(this); 00072 p.drawPixmap( 0, 0, isRotateEnabled()? enabledPm : disabledPm ); 00073 } 00074 00075 void AutoRotate::setRotateEnabled(bool status) 00076 { 00077 Config cfg( "qpe" ); 00078 cfg.setGroup( "Appearance" ); 00079 cfg.writeEntry( "rotateEnabled", status ); 00080 00081 } 00082 bool AutoRotate::isRotateEnabled() 00083 { 00084 Config cfg( "qpe" ); 00085 cfg.setGroup( "Appearance" ); 00086 00087 bool res = cfg.readBoolEntry( "rotateEnabled" ); 00088 00089 if (res ) 00090 odebug << "Enabled" << oendl; 00091 else 00092 odebug << "Disabled" << oendl; 00093 return res; 00094 } 00095 00096 EXPORT_OPIE_APPLET_v1( AutoRotate ) 00097
1.4.2