summaryrefslogtreecommitdiff
path: root/noncore/applets/autorotateapplet/autorotate.cpp
blob: 28b631bc32b52650788d39d2ac4d3fea322d3200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * copyright   : (c) 2003 by Greg Gilbert
 * email       : greg@treke.net
 * based on the cardmon applet by Max Reiss
 *                                                                       *
 * This program is free software; you can redistribute it and/or modify  *
 * it under the terms of the GNU General Public License as published by  *
 * the Free Software Foundation; either version 2 of the License, or     *
 * (at your option) any later version.                                   *
 *                                                                       *
 *************************************************************************/

#include "autorotate.h"

/* OPIE */
#include <opie2/odebug.h>
#include <opie2/otaskbarapplet.h>
#include <opie2/oresource.h>
#include <qpe/applnk.h>
#include <qpe/config.h>
using namespace Opie::Core;

/* QT */
#include <qpainter.h>

AutoRotate::AutoRotate(QWidget * parent):QWidget(parent)
{
    setFixedWidth( AppLnk::smallIconSize() );
    setFixedHeight( AppLnk::smallIconSize() );

    enabledPm = Opie::Core::OResource::loadImage("autorotate/rotate", Opie::Core::OResource::SmallIcon);
    disabledPm = Opie::Core::OResource::loadImage("autorotate/norotate", Opie::Core::OResource::SmallIcon);

    repaint(true);
    popupMenu = 0;
    show();
}

AutoRotate::~AutoRotate()
{
    if (popupMenu) {
        delete popupMenu;
    }
}

int AutoRotate::position()
{
    return 7;
}

void AutoRotate::mousePressEvent(QMouseEvent *)
{
    QPopupMenu *menu = new QPopupMenu(this);
    menu->insertItem( isRotateEnabled()? "Disable Rotation" : "Enable Rotation" ,1 );

    QPoint p = mapToGlobal(QPoint(0, 0));
    QSize s = menu->sizeHint();
    int opt = menu->exec(QPoint(p.x() + (width() / 2) - (s.width() / 2), p.y() - s.height()), 0);

    if (opt==1)
    {
        setRotateEnabled( !isRotateEnabled() );
        repaint(true);
    }

    delete menu;
}

void AutoRotate::paintEvent(QPaintEvent *)
{
    QPainter p(this);
    p.drawPixmap( 0, 0, isRotateEnabled()? enabledPm : disabledPm );
}

void AutoRotate::setRotateEnabled(bool status)
{
    Config cfg( "qpe" );
    cfg.setGroup( "Appearance" );
    cfg.writeEntry( "rotateEnabled", status );

}
bool AutoRotate::isRotateEnabled()
{
    Config cfg( "qpe" );
    cfg.setGroup( "Appearance" );

    bool res = cfg.readBoolEntry( "rotateEnabled" );

    if (res )
        odebug << "Enabled" << oendl; 
    else
        odebug << "Disabled" << oendl; 
    return res;
}

EXPORT_OPIE_APPLET_v1( AutoRotate )