summaryrefslogtreecommitdiff
path: root/noncore/graphics/opie-eye/gui/mainwindow.cpp
blob: a90231be7469230df7a912289660bc6bcf1c6259 (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
/*
 * GPLv2 zecke@handhelds.org
 * No WArranty...
 */
#include "mainwindow.h"
#include "imageview.h"

#include "iconview.h"
#include "filesystem.h"
#include "imageinfoui.h"
#include "viewmodebutton.h"

#include <iface/ifaceinfo.h>
#include <iface/dirview.h>

#include <opie2/odebug.h>
#include <opie2/owidgetstack.h>
#include <opie2/oapplicationfactory.h>
#include <opie2/otabwidget.h>
#include <opie2/okeyconfigwidget.h>

#include <qpe/resource.h>
#include <qpe/config.h>
#include <qpe/ir.h>
#include <qpe/applnk.h>

#include <qtoolbar.h>
#include <qtoolbutton.h>
#include <qlayout.h>
#include <qdialog.h>
#include <qmap.h>
#include <qtimer.h>




OPIE_EXPORT_APP_V2( Opie::Core::OApplicationFactory<PMainWindow>,"Opie Eye" )

PMainWindow::PMainWindow(QWidget* wid, const char* name, WFlags style)
    : QMainWindow( wid, name, style ), m_info( 0 ), m_disp( 0 )
{
    setCaption( QObject::tr("Opie Eye Caramba" ) );
    m_cfg = new Opie::Core::OConfig("phunkview");
    m_cfg->setGroup("Zecke_view" );
//    qDebug( "Process-wide OApplication object @ %0x", oApp );
    /*
     * Initialize ToolBar and IconView
     * And Connect Them
     */
    QToolBar *bar = new QToolBar( this );
    bar->setHorizontalStretchable( true );
    setToolBarsMovable( false );

    m_stack = new Opie::Ui::OWidgetStack( this );
    setCentralWidget( m_stack );

    m_view = new PIconView( m_stack, m_cfg );
    m_stack->addWidget( m_view, IconView );
    m_stack->raiseWidget( IconView );
    connect(m_view, SIGNAL(sig_display(const QString&)),
            this, SLOT(slotDisplay(const QString&)));
    connect(m_view, SIGNAL(sig_showInfo(const QString&)),
            this, SLOT(slotShowInfo(const QString&)) );

    m_stack->forceMode(Opie::Ui::OWidgetStack::NoForce);

    upButton = new QToolButton( bar );
    upButton->setIconSet(  Resource::loadIconSet( "up" ) );
    connect( upButton, SIGNAL(clicked()),
             m_view, SLOT(slotDirUp()) );

    fsButton = new PFileSystem( bar );
    connect( fsButton, SIGNAL( changeDir( const QString& ) ),
             m_view, SLOT(slotChangeDir( const QString& ) ) );

    QToolButton*btn = new QToolButton( bar );
    btn->setIconSet( Resource::loadIconSet( "edit" ) );
    connect( btn, SIGNAL(clicked()),
             m_view, SLOT(slotRename()) );

    if ( Ir::supported() ) {
        btn = new QToolButton( bar );
        btn->setIconSet( Resource::loadIconSet( "beam" ) );
        connect( btn, SIGNAL(clicked()),
                 m_view, SLOT(slotBeam()) );
    }

    btn = new QToolButton( bar );
    btn->setIconSet( Resource::loadIconSet( "trash" ) );
    connect( btn, SIGNAL(clicked() ),
             m_view, SLOT(slotTrash() ) );


    int mode = m_cfg->readNumEntry("ListViewMode", 1);
    if (mode < 1 || mode>3) mode = 1;
    viewModeButton = new ViewModeButton( bar,mode );
    connect( viewModeButton, SIGNAL(changeMode(int)),
             m_view, SLOT(slotChangeMode(int)));

    btn = new QToolButton( bar );
    btn->setIconSet( Resource::loadIconSet( "SettingsIcon" ) );
    connect( btn, SIGNAL(clicked() ),
             this, SLOT(slotConfig() ) );



    prevButton = new QToolButton(bar);
    prevButton->setIconSet( Resource::loadIconSet( "back" ) );
    connect(prevButton,SIGNAL(clicked()),m_view,SLOT(slotShowPrev()));

    nextButton = new QToolButton(bar);
    nextButton->setIconSet( Resource::loadIconSet( "forward" ) );
    connect(nextButton,SIGNAL(clicked()),m_view,SLOT(slotShowNext()));

    rotateButton = new QToolButton(bar);
    rotateButton->setIconSet( Resource::loadIconSet( "rotate" ) );
    rotateButton->setToggleButton(true);

    if (m_stack->mode() == Opie::Ui::OWidgetStack::SmallScreen) {
        rotateButton->setOn(true);
        autoRotate = true;
        prevButton->hide();
        nextButton->hide();
    } else {
        rotateButton->setOn(false);
        autoRotate = false;
    }

    connect(rotateButton,SIGNAL(toggled(bool)),this,SLOT(slotRotateToggled(bool)));

    btn = new QToolButton(bar);
    btn->setIconSet( Resource::loadIconSet( "1to1" ) );
    btn->setToggleButton(true);
    btn->setOn(false);
    connect(btn,SIGNAL(toggled(bool)),this,SLOT(slotScaleToggled(bool)));
    autoScale = true;

    btn = new QToolButton(bar);
    btn->setIconSet( Resource::loadIconSet( "mag" ) );
    btn->setToggleButton(true);
    btn->setOn(true);
    connect(btn,SIGNAL(toggled(bool)),this,SLOT(slotZoomerToggled(bool)));
    zoomerOn = true;
}

PMainWindow::~PMainWindow() {
    odebug << "Shutting down" << oendl;
}

void PMainWindow::slotZoomerToggled(bool how)
{
    zoomerOn = how;
    if (m_disp) {
        m_disp->setShowZoomer(zoomerOn);
    }
}

void PMainWindow::slotRotateToggled(bool how)
{
    autoRotate = how;
    if (m_disp) {
        m_disp->setAutoRotate(how);
    }
}

void PMainWindow::slotScaleToggled(bool how)
{
    autoScale = !how;
    if (!how) {
        autoRotate = how;
    }
    if (m_disp) {
        m_disp->setAutoScaleRotate(autoScale,autoRotate);
    }
    if (!autoScale) {
        rotateButton->setOn(false);
    }
    rotateButton->setEnabled(!how);
}

void PMainWindow::slotConfig() {
   /*
    * have a tab with the possible views
    * a tab for globals image cache size.. scaled loading
    * and one tab for the  KeyConfigs
    */
    QDialog dlg(this, 0, true);
    dlg.setCaption( tr("Phunk View - Config" ) );

    QHBoxLayout *lay = new QHBoxLayout(&dlg);
    Opie::Ui::OTabWidget *wid = new Opie::Ui::OTabWidget(&dlg );
    lay->addWidget( wid );
    ViewMap *vM = viewMap();
    ViewMap::Iterator _it = vM->begin();
    QMap<PDirView*, QWidget*> lst;

    for( ; _it != vM->end(); ++_it ) {
        PDirView *view = (_it.data())(*m_cfg);
        PInterfaceInfo *inf =  view->interfaceInfo();
        QWidget *_wid = inf->configWidget( *m_cfg );
        _wid->reparent(wid, QPoint() );
        lst.insert( view, _wid );
        wid->addTab( _wid, "fileopen", inf->name() );
    }

/*
 * Add the KeyConfigWidget
 */
    Opie::Ui::OKeyConfigWidget* keyWid = new Opie::Ui::OKeyConfigWidget( wid, "key config" );
    keyWid->setChangeMode( Opie::Ui::OKeyConfigWidget::Queue );
    keyWid->insert( tr("Browser Keyboard Actions"), m_view->manager() );

    if ( !m_info ) {
        initInfo();
    }
    keyWid->insert( tr("Imageinfo Keyboard Actions"), m_info->manager() );

    if ( !m_disp ) {
        initDisp();
    }
    keyWid->insert( tr("Imageview Keyboard Actions"), m_disp->manager() );

    keyWid->load();
    wid->addTab( keyWid, QString::fromLatin1("AppsIcon" ), tr("Keyboard Configuration") );


    bool act = ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted );

/*
 * clean up
 *apply changes
 */

    QMap<PDirView*, QWidget*>::Iterator it;
    for ( it = lst.begin(); it != lst.end(); ++it ) {
        if ( act )
            it.key()->interfaceInfo()->writeConfig(it.data(),  *m_cfg);
        delete it.key();
    }


    if ( act ) {
        m_view->resetView();
        keyWid->save();
        m_disp->manager()->save();
        m_info->manager()->save();
        m_view->manager()->save();
    }
    delete keyWid;
}

/*
 * create a new image info component
 * and detach the current one
 * we will make the other delete on exit
 */
template<class T>
void PMainWindow::initT( const char* name, T** ptr, int id) {
    if ( *ptr ) {
        (*ptr)->disconnect(this, SLOT(slotReturn()));
        (*ptr)->setDestructiveClose();
        m_stack->removeWidget( *ptr );
    }
    *ptr = new T(m_cfg, m_stack, name );
    m_stack->addWidget( *ptr, id );

    connect(*ptr, SIGNAL(sig_return()),
            this,SLOT(slotReturn()));

}
void PMainWindow::initInfo() {
    initT<imageinfo>( "Image Info", &m_info, ImageInfo );
    connect(m_info,SIGNAL(dispImage(const QString&)),this,SLOT(slotDisplay(const QString&)));
}
void PMainWindow::initDisp() {
    initT<ImageView>( "Image ScrollView", &m_disp, ImageDisplay );
    if (m_disp) {
        if (m_stack->mode() != Opie::Ui::OWidgetStack::SmallScreen) {
            m_disp->setMinimumSize(QApplication::desktop()->size()/2);
        }
        m_disp->setAutoScale(autoScale);
        m_disp->setAutoRotate(autoRotate);
        m_disp->setShowZoomer(zoomerOn);
        m_disp->setBackgroundColor(white);
        connect(m_disp,SIGNAL(dispImageInfo(const QString&)),this,SLOT(slotShowInfo(const QString&)));
        connect(m_disp,SIGNAL(dispNext()),m_view,SLOT(slotShowNext()));
        connect(m_disp,SIGNAL(dispPrev()),m_view,SLOT(slotShowPrev()));
        connect(m_disp,SIGNAL(toggleFullScreen()),this,SLOT(slotToggleFullScreen()));
        connect(m_disp,SIGNAL(hideMe()),this,SLOT(raiseIconView()));
    }
}

void PMainWindow::slotToggleFullScreen()
{
    odebug << "Toggle full " << oendl;
    if (!m_disp) return;
    bool current = !m_disp->fullScreen();
    m_disp->setFullScreen(current);
    odebug << "Current = " << current << oendl;
    if (current) {
        odebug << "full" << oendl;
        m_disp->setBackgroundColor(black);
        m_disp->reparent(0,QPoint(0,0));
        m_disp->setVScrollBarMode(QScrollView::AlwaysOff);
        m_disp->setHScrollBarMode(QScrollView::AlwaysOff);
        m_disp->resize(qApp->desktop()->width(), qApp->desktop()->height());
        m_disp->showFullScreen();
    } else {
        odebug << "window" << oendl;
        m_disp->setBackgroundColor(white);
        m_stack->addWidget(m_disp,ImageDisplay);
        m_disp->setVScrollBarMode(QScrollView::Auto);
        m_disp->setHScrollBarMode(QScrollView::Auto);
        m_stack->raiseWidget(m_disp);
        if (m_stack->mode() != Opie::Ui::OWidgetStack::SmallScreen) {
            m_disp->resize(m_disp->minimumSize());
        }
    }
}

/**
 * With big Screen the plan could be to 'detach' the image
 * window if visible and to create a ne wone
 * init* already supports it but I make no use of it for
 * now. We set filename and raise
 *
 * ### FIXME and talk to alwin
 */
void PMainWindow::slotShowInfo( const QString& inf ) {
    if ( !m_info ) {
        initInfo();
    }
    m_info->setPath( inf );
    if (m_stack->mode() == Opie::Ui::OWidgetStack::SmallScreen) {
        prevButton->hide();
        nextButton->hide();
        upButton->hide();
        fsButton->hide();
        viewModeButton->hide();
    }
    if (m_disp && m_disp->fullScreen() && m_disp->isVisible()) {
        m_disp->hide();
    }
    m_stack->raiseWidget( ImageInfo );
}

void PMainWindow::slotDisplay( const QString& inf ) {
    if ( !m_disp ) {
        initDisp();
    }
    m_disp->setImage( inf );
    if (m_stack->mode() == Opie::Ui::OWidgetStack::SmallScreen) {
        prevButton->show();
        nextButton->show();
        upButton->hide();
        fsButton->hide();
        viewModeButton->hide();
    }
    if (m_disp->fullScreen()) {
        m_disp->show();
    } else {
        m_stack->raiseWidget( ImageDisplay );
    }
}

void PMainWindow::slotReturn() {
    raiseIconView();
}


void PMainWindow::closeEvent( QCloseEvent* ev ) {
    /*
     * return from view
     * or properly quit
     */
    if ( m_stack->visibleWidget() == m_info ||
         m_stack->visibleWidget() == m_disp ) {
        raiseIconView();
        ev->ignore();
        return;
    }
    ev->accept();
    QTimer::singleShot(0, qApp, SLOT(closeAllWindows()));
}

void PMainWindow::raiseIconView() {
    if (m_stack->mode() == Opie::Ui::OWidgetStack::SmallScreen) {
        prevButton->hide();
        nextButton->hide();
        upButton->show();
        fsButton->show();
        viewModeButton->show();
    }
    if (m_disp && m_disp->fullScreen() && m_disp->isVisible()) {
        m_disp->hide();
    }
    m_stack->raiseWidget( IconView );
}

void PMainWindow::setDocument( const QString& showImg ) {
    QString file = showImg;
    DocLnk lnk(showImg);
    if (lnk.isValid() )
        file = lnk.file();

    slotDisplay( file );
}