summaryrefslogtreecommitdiff
path: root/libopie/big-screen/example/owidgetstack_example.cpp
blob: a6b82018f5f49df815449786eacfb7c201549c37 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * You may use, modify and distribute this example without any limitation
 */

#include <qaction.h>
#include <qtoolbar.h>
#include <qpopupmenu.h>
#include <qmenubar.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qsignalmapper.h>

#include <qpe/resource.h>

#include "../owidgetstack.h"

#include "owidgetstack_example.h"

#include <qpe/qpeapplication.h>
#include <opie/oapplicationfactory.h>

OPIE_EXPORT_APP( OApplicationFactory<StackExample> )

StackExample::StackExample( QWidget* parent, const char* name, WFlags fl )
    : QMainWindow( parent, name, fl )
{
    m_stack = new OWidgetStack( this );
    setCentralWidget( m_stack );

    /* nice Signal Mapper ;) */
    QSignalMapper *sm = new QSignalMapper(this);
    connect(sm, SIGNAL(mapped(int) ), m_stack, SLOT(raiseWidget(int)) );

    /* toolbar first but this should be known from the other examples */
    setToolBarsMovable( false );

    /* only a menubar here */
    QToolBar* holder = new QToolBar( this );
    holder->setHorizontalStretchable( true );

    QMenuBar *bar = new QMenuBar( holder );
    QPopupMenu *menu = new QPopupMenu( this );

    QAction* a = new QAction( tr("Show MainWidget"), Resource::loadPixmap("zoom"),
                              QString::null, 0, this, 0 );
    sm->setMapping(a, 1 );
    connect(a, SIGNAL(activated() ),
            sm, SLOT(map() ) );
    a->addTo( menu );

    a = new QAction( tr("Show Details Small"), Resource::loadPixmap("zoom"),
                     QString::null, 0, this, 0 );
    sm->setMapping(a, 2 );
    connect(a, SIGNAL(activated() ),
            sm, SLOT(map() ) );
    a->addTo( menu );

    a = new QAction( tr("Show Details More"), Resource::loadPixmap("zoom"),
                     QString::null, 0, this, 0 );
    sm->setMapping(a, 3 );
    connect(a, SIGNAL(activated() ),
            sm, SLOT(map() ) );
    a->addTo( menu );

    a =  new QAction( tr("Show Details All"), Resource::loadPixmap("zoom"),
                      QString::null, 0, this, 0 );
    sm->setMapping(a, 4 );
    connect(a, SIGNAL(activated() ),
            sm, SLOT(map() ) );

    bar->insertItem( tr("Actions"), menu );

    /* now the gui */

    /* first widget, main widget */
    QWidget * wid = new QWidget( m_stack );
    QGridLayout *grid = new QGridLayout(wid, 2, 2 );

    QPushButton *btn = new QPushButton( tr("Show Details Small"), wid, "details1" );
    sm->setMapping(btn, 2 );
    connect(btn, SIGNAL(clicked()), sm, SLOT(map() ) );
    grid->addWidget( btn, 0, 0 );

    btn = new QPushButton( tr("Show Details Medium"), wid, "details2");
    sm->setMapping(btn, 3 );
    connect(btn, SIGNAL(clicked()), sm, SLOT(map() ) );
    grid->addWidget( btn, 0, 1 );

    btn = new QPushButton( tr("Show Details All"), wid, "details3");
    sm->setMapping(btn, 4 );
    connect(btn, SIGNAL(clicked()), sm, SLOT(map() ) );
    grid->addWidget( btn, 1, 1 );

    m_stack->addWidget( wid, 1 );
    m_main = wid;

    QLabel *lbl = new QLabel(m_stack );
    lbl->setText(tr("Only small Details are shown here. Määh") );
    m_stack->addWidget( lbl, 2 );

    lbl = new QLabel( m_stack );
    lbl->setText( tr("Some more details....Wo ist das Schaf?") );
    m_stack->addWidget( lbl, 3 );

    lbl = new QLabel( m_stack );
    lbl->setText( tr("<qt>Ne nicht in Bayerisch Gmain sondern in Berlin<br>Vermiss und meine Augen werden nicht eckig, da mein Bildschirm abgerundet ist<br>Es lebe Hamburg Süd,weiss du, verstehst du? ;)<br>Susi ist dOOf, es lebe die Ofenecke...", "hard to translate that") );
    m_stack->addWidget( lbl, 4 );


    /* THE signal mapper does all the magic */
    m_stack->raiseWidget( m_main );
}


StackExample::~StackExample() {

}



void StackExample::closeEvent( QCloseEvent* ev) {
    /* if the close even came when we displayed a details */
    if (m_stack->visibleWidget() != m_main ) {
        m_stack->raiseWidget( m_main );
        ev->ignore();
        return;
    }

    ev->accept();
}