summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/autorotateapplet/autorotate.cpp60
1 files changed, 24 insertions, 36 deletions
diff --git a/noncore/applets/autorotateapplet/autorotate.cpp b/noncore/applets/autorotateapplet/autorotate.cpp
index 4733860..35a11db 100644
--- a/noncore/applets/autorotateapplet/autorotate.cpp
+++ b/noncore/applets/autorotateapplet/autorotate.cpp
@@ -1,110 +1,98 @@
1/* 1/*
2 * copyright : (c) 2003 by Greg Gilbert 2 * copyright : (c) 2003 by Greg Gilbert
3 * email : greg@treke.net 3 * email : greg@treke.net
4 * based on the cardmon applet by Max Reiss 4 * based on the cardmon applet by Max Reiss
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by * 7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or * 8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. * 9 * (at your option) any later version. *
10 * * 10 * *
11 *************************************************************************/ 11 *************************************************************************/
12 12
13
14#include "autorotate.h" 13#include "autorotate.h"
15 14
16#include <qpe/resource.h> 15/* OPIE */
17
18#include <opie/odevice.h> 16#include <opie/odevice.h>
19
20#include <qpe/applnk.h> 17#include <qpe/applnk.h>
21#include <qpe/config.h> 18#include <qpe/config.h>
19#include <qpe/resource.h>
22 20
21/* QT */
22#include <qapplication.h>
23#include <qfile.h>
23#include <qcopchannel_qws.h> 24#include <qcopchannel_qws.h>
24#include <qpainter.h>
25#include <qmessagebox.h> 25#include <qmessagebox.h>
26#include <qfile.h> 26#include <qpainter.h>
27#include <qtextstream.h> 27#include <qpixmap.h>
28#include <qimage.h>
28#include <qtimer.h> 29#include <qtimer.h>
29#include <qapplication.h> 30#include <qtextstream.h>
30 31
31using namespace Opie; 32using namespace Opie;
32 33
33AutoRotate::AutoRotate(QWidget * parent):QWidget(parent), 34AutoRotate::AutoRotate(QWidget * parent):QWidget(parent)
34 enabledPm( Resource::loadPixmap("autorotate/rotate") ),
35 disabledPm( Resource::loadPixmap("autorotate/norotate") )
36{ 35{
37 setFixedWidth ( AppLnk::smallIconSize() ); 36 setFixedWidth( AppLnk::smallIconSize() );
38 setFixedHeight ( AppLnk::smallIconSize() ); 37 setFixedHeight( AppLnk::smallIconSize() );
38
39 enabledPm.convertFromImage( Resource::loadImage("autorotate/rotate").smoothScale( height(), width() ) );
40 disabledPm.convertFromImage( Resource::loadImage("autorotate/norotate").smoothScale( height(), width() ) );
39 41
40 repaint(true); 42 repaint(true);
41 popupMenu = 0; 43 popupMenu = 0;
42 show(); 44 show();
43} 45}
44 46
45AutoRotate::~AutoRotate() 47AutoRotate::~AutoRotate()
46{ 48{
47 if (popupMenu) { 49 if (popupMenu) {
48 delete popupMenu; 50 delete popupMenu;
49 } 51 }
50} 52}
51 53
52void AutoRotate::mousePressEvent(QMouseEvent *) 54void AutoRotate::mousePressEvent(QMouseEvent *)
53{ 55{
54 QPopupMenu *menu = new QPopupMenu(this); 56 QPopupMenu *menu = new QPopupMenu(this);
55 57 menu->insertItem( isRotateEnabled()? "Disable Rotation" : "Enable Rotation" ,1 );
56 if (isRotateEnabled())
57 menu->insertItem("Disable Rotation",1);
58 else
59 menu->insertItem("Enable Rotation",1);
60
61 58
62 QPoint p = mapToGlobal(QPoint(0, 0)); 59 QPoint p = mapToGlobal(QPoint(0, 0));
63 QSize s = menu->sizeHint(); 60 QSize s = menu->sizeHint();
64 int opt = menu->exec(QPoint(p.x() + (width() / 2) - (s.width() / 2), 61 int opt = menu->exec(QPoint(p.x() + (width() / 2) - (s.width() / 2), p.y() - s.height()), 0);
65 p.y() - s.height()), 0); 62
66 63 if (opt==1)
67 if (opt==1) { 64 {
68 if (isRotateEnabled()) 65 setRotateEnabled( !isRotateEnabled() );
69 setRotateEnabled(false);
70 else
71 setRotateEnabled(true);
72
73 repaint(true); 66 repaint(true);
74 } 67 }
75 68
76 delete menu; 69 delete menu;
77} 70}
78 71
79void AutoRotate::paintEvent(QPaintEvent *) 72void AutoRotate::paintEvent(QPaintEvent *)
80{ 73{
81 QPainter p(this); 74 QPainter p(this);
82 75 p.drawPixmap( 0, 0, isRotateEnabled()? enabledPm : disabledPm );
83 if ( isRotateEnabled() ) {
84 p.drawPixmap(0, 0, enabledPm );
85 } else {
86 p.drawPixmap(0, 0, disabledPm );
87 }
88} 76}
89 77
90void AutoRotate::setRotateEnabled(bool status) 78void AutoRotate::setRotateEnabled(bool status)
91{ 79{
92 Config cfg( "qpe" ); 80 Config cfg( "qpe" );
93 cfg.setGroup( "Appearance" ); 81 cfg.setGroup( "Appearance" );
94 cfg.writeEntry( "rotateEnabled",status ); 82 cfg.writeEntry( "rotateEnabled", status );
95 83
96} 84}
97bool AutoRotate::isRotateEnabled() 85bool AutoRotate::isRotateEnabled()
98{ 86{
99 Config cfg( "qpe" ); 87 Config cfg( "qpe" );
100 cfg.setGroup( "Appearance" ); 88 cfg.setGroup( "Appearance" );
101 89
102 bool res = cfg.readBoolEntry( "rotateEnabled" ); 90 bool res = cfg.readBoolEntry( "rotateEnabled" );
103 91
104 if (res ) 92 if (res )
105 qDebug("Enabled"); 93 qDebug("Enabled");
106 else 94 else
107 qDebug("Disabled"); 95 qDebug("Disabled");
108 return res; 96 return res;
109} 97}
110 98