source: trunk/tools/qvfb/qvfb.cpp@ 561

Last change on this file since 561 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

File size: 33.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the tools applications of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qvfb.h"
43#include "qvfbview.h"
44#include "qvfbhdr.h"
45#ifdef Q_WS_X11
46#include "qvfbx11view.h"
47#endif
48#include "qvfbratedlg.h"
49#include "ui_config.h"
50#include "qanimationwriter.h"
51
52#include <deviceskin.h>
53
54#include <QMenuBar>
55#include <QMenu>
56#include <QApplication>
57#include <QMessageBox>
58#include <QComboBox>
59#include <QLabel>
60#include <QFileDialog>
61#include <QSlider>
62#include <QSpinBox>
63#include <QLayout>
64#include <QRadioButton>
65#include <QImage>
66#include <QPixmap>
67#include <QCheckBox>
68#include <QCursor>
69#include <QTime>
70#include <QScrollArea>
71#include <QProgressBar>
72#include <QPushButton>
73#include <QTextStream>
74#include <QFile>
75#include <QFileInfo>
76#include <QDebug>
77
78#include <unistd.h>
79#include <stdlib.h>
80#include <sys/types.h>
81
82QT_BEGIN_NAMESPACE
83
84// =====================================================================
85
86static const char *red_on_led_xpm[] = {
87"11 11 10 1",
88" c None",
89". c #FF0000",
90"+ c #FF4C4C",
91"@ c #FF7A7A",
92"# c #D30000",
93"$ c #FF9393",
94"% c #BA0000",
95"& c #FFFFFF",
96"* c #7F0000",
97"= c #000000",
98" ",
99" .++@@ ",
100" .....+@ ",
101" ##...$.+@ ",
102" %#..$&$.+ ",
103" *#...$..+ ",
104" *%#...... ",
105" =*%#..... ",
106" =*%###. ",
107" ===*. ",
108" "};
109
110static const char *red_off_led_xpm[] = {
111"11 11 12 1",
112" c None",
113". c #CDB7B4",
114"+ c #D2BFBD",
115"@ c #DBCBCA",
116"# c #E5D9D8",
117"$ c #BC9E9B",
118"% c #E2D6D5",
119"& c #AD8986",
120"* c #FFFFFF",
121"= c #A8817D",
122"- c #B2908D",
123"; c #6F4D4A",
124" ",
125" .++@# ",
126" .....@# ",
127" $$...%.@# ",
128" &$..%*%.@ ",
129" =-...%..+ ",
130" =&-...... ",
131" ;==-..... ",
132" ;=&-$$. ",
133" ;==&$ ",
134" "};
135
136static bool copyButtonConfiguration(const QString &prefix, int displayId)
137{
138 const QString destDir = QT_VFB_DATADIR(displayId).append("/");
139 const QFileInfo src(prefix + QLatin1String("defaultbuttons.conf"));
140 const QFileInfo dst(destDir + QLatin1String("defaultbuttons.conf"));
141 unlink(dst.absoluteFilePath().toLatin1().constData());
142 if (!src.exists())
143 return false;
144 const bool rc = QFile::copy(src.absoluteFilePath(), dst.absoluteFilePath());
145 if (!rc)
146 qWarning() << "Failed to copy the button configuration file " << src.absoluteFilePath() << " to " << dst.absoluteFilePath() << '.';
147 return rc;
148}
149
150// =====================================================================
151
152class AnimationSaveWidget : public QWidget {
153 Q_OBJECT
154public:
155 AnimationSaveWidget(QVFbAbstractView *v);
156 ~AnimationSaveWidget();
157 bool detectPpmtoMpegCommand();
158 void timerEvent(QTimerEvent *te);
159 void convertToMpeg(QString filename);
160 void removeTemporaryFiles();
161protected slots:
162 void toggleRecord();
163 void reset();
164 void save();
165private:
166 QVFbAbstractView *view;
167 QProgressBar *progressBar;
168 QLabel *statusText;
169 bool haveMpeg, savingAsMpeg, recording;
170 QCheckBox *mpegSave;
171 QAnimationWriter *animation;
172 QPushButton *recBt, *resetBt, *saveBt;
173 QLabel *timeDpy, *recLED;
174 int timerId, progressTimerId;
175 QPixmap recOn, recOff;
176 QTime tm;
177 int elapsed, imageNum;
178};
179
180// =====================================================================
181
182Zoomer::Zoomer(QVFb* target) :
183 qvfb(target)
184{
185 QVBoxLayout *layout = new QVBoxLayout(this);
186 QSlider *sl = new QSlider(Qt::Horizontal);
187 sl->setMinimum(10);
188 sl->setMaximum(64);
189 sl->setPageStep(1);
190 sl->setValue(32);
191 layout->addWidget(sl);
192 connect(sl,SIGNAL(valueChanged(int)),this,SLOT(zoom(int)));
193 label = new QLabel();
194 layout->addWidget(label);
195}
196
197void Zoomer::zoom(int z)
198{
199 double d = (double)z/32.0;
200 qvfb->setZoom(d);
201 label->setText(QString::number(d,'g',2));
202}
203
204// =====================================================================
205
206QVFb::QVFb( int display_id, int w, int h, int d, int r, const QString &skin, DisplayType displayType, QWidget *parent, Qt::WindowFlags flags )
207 : QMainWindow( parent, flags )
208{
209 this->displayType = displayType;
210 view = 0;
211 secondaryView = 0;
212 scroller = 0;
213 this->skin = 0;
214 currentSkinIndex = -1;
215 findSkins(skin);
216 zoomer = 0;
217 QPixmap pix(":/res/images/logo.png");
218 setWindowIcon( pix );
219 rateDlg = 0;
220 refreshRate = 30;
221 // Create the menu first to avoid scroll bars in the main window
222 createMenu( menuBar() );
223 init( display_id, w, h, d, r, skin );
224 enableCursor( true );
225}
226
227QVFb::~QVFb()
228{
229}
230
231void QVFb::popupMenu()
232{
233 QMenu *pm = new QMenu( this );
234 createMenu( pm );
235 pm->exec(QCursor::pos());
236}
237
238void QVFb::init( int display_id, int pw, int ph, int d, int r, const QString& skin_name )
239{
240 delete view;
241 view = 0;
242 delete secondaryView;
243 secondaryView = 0;
244 delete scroller;
245 scroller = 0;
246 delete skin;
247 skin = 0;
248
249 skinscaleH = skinscaleV = 1.0;
250 QVFbView::Rotation rot = ((r == 90) ? QVFbView::Rot90 :
251 ((r == 180) ? QVFbView::Rot180 :
252 ((r == 270) ? QVFbView::Rot270 :
253 QVFbView::Rot0 )));
254 if ( !skin_name.isEmpty() ) {
255 const bool vis = isVisible();
256 DeviceSkinParameters parameters;
257 QString readError;
258 if (parameters.read(skin_name,DeviceSkinParameters::ReadAll, &readError)) {
259 skin = new DeviceSkin(parameters, this);
260 connect(skin, SIGNAL(popupMenu()), this, SLOT(popupMenu()));
261 const int sw = parameters.screenSize().width();
262 const int sh = parameters.screenSize().height();
263 const int sd = parameters.screenDepth;
264 if (!pw) pw = sw;
265 if (!ph) ph = sh;
266 if (d < 0) {
267 if (sd)
268 d = sd;
269 else
270 d = -d;
271 }
272 if (vis)
273 hide();
274 menuBar()->hide();
275 scroller = 0;
276#ifdef Q_WS_X11
277 if (displayType == X11)
278 view = new QVFbX11View( display_id, pw, ph, d, rot, skin );
279 else
280#endif
281 view = new QVFbView( display_id, pw, ph, d, rot, skin );
282 skin->setView( view );
283 view->setContentsMargins( 0, 0, 0, 0 );
284 view->setTouchscreenEmulation(!parameters.hasMouseHover);
285 connect(skin, SIGNAL(skinKeyPressEvent(int,QString,bool)), view, SLOT(skinKeyPressEvent(int,QString,bool)));
286 connect(skin, SIGNAL(skinKeyReleaseEvent(int,QString,bool)), view, SLOT(skinKeyReleaseEvent(int,QString,bool)));
287
288 copyButtonConfiguration(skin->prefix(), view->displayId());
289
290 setCentralWidget( skin );
291 adjustSize();
292 skinscaleH = (double)sw/pw;
293 skinscaleV = (double)sh/ph;
294 if ( skinscaleH != 1.0 || skinscaleH != 1.0 )
295 setZoom(skinscaleH);
296 view->show();
297
298 if (parameters.hasSecondaryScreen()) {
299 const QSize ssize = parameters.secondaryScreenSize();
300 // assumes same depth and rotation
301#ifdef Q_WS_X11
302 if (displayType == X11)
303 secondaryView = new QVFbX11View( display_id+1, ssize.width(), ssize.height(), d, rot, skin );
304 else
305#endif
306 secondaryView = new QVFbView( display_id+1, ssize.width(), ssize.height(), d, rot, skin );
307 skin->setSecondaryView(secondaryView);
308 secondaryView->show();
309 }
310
311 if ( vis ) show();
312 } else {
313 qWarning("%s", qPrintable(readError));
314 }
315 }
316
317 // If we failed to get a skin or we were not supplied
318 // with one then fallback to a framebuffer without
319 // a skin
320 if (!skin){
321 // Default values
322 if (!pw)
323 pw = 240;
324 if (!ph)
325 ph = 320;
326 if (!d)
327 d = 32;
328 else if (d < 0)
329 d = -d;
330
331 if (currentSkinIndex != -1) {
332 clearMask();
333 setParent( 0, 0 );
334 move( pos() );
335 show();
336 //unset fixed size:
337 setMinimumSize(0,0);
338 setMaximumSize(QWIDGETSIZE_MAX,QWIDGETSIZE_MAX);
339 }
340 menuBar()->show();
341 scroller = new QScrollArea(this);
342 scroller->setFocusPolicy(Qt::NoFocus); // don't steal key events from the embedded app
343#ifdef Q_WS_X11
344 if (displayType == X11)
345 view = new QVFbX11View( display_id, pw, ph, d, rot, scroller );
346 else
347#endif
348 view = new QVFbView( display_id, pw, ph, d, rot, scroller );
349 scroller->setWidget(view);
350 view->setContentsMargins( 0, 0, 0, 0 );
351 setCentralWidget(scroller);
352 ph += 2; // avoid scrollbar
353 scroller->show();
354 // delete defaultbuttons.conf if it was left behind...
355 unlink(QFileInfo(QT_VFB_DATADIR(view->displayId()).append("/defaultbuttons.conf")).absoluteFilePath().toLatin1().constData());
356 if (secondaryView)
357 unlink(QFileInfo(QT_VFB_DATADIR(view->displayId() + 1).append("/defaultbuttons.conf")).absoluteFilePath().toLatin1().constData());
358 }
359 view->setRate(refreshRate);
360 if (secondaryView) {
361 secondaryView->setRate(refreshRate);
362 }
363 // Resize QVFb to the new size
364 QSize newSize = view->sizeHint();
365
366 // ... fudge factor
367 newSize += QSize(20, 35);
368
369 resize(newSize);
370
371 setWindowTitle(QString("Virtual framebuffer %1x%2 %3bpp Display :%4 Rotate %5")
372 .arg(view->displayWidth()).arg(view->displayHeight())
373 .arg(d).arg(display_id).arg(r));
374}
375
376void QVFb::enableCursor( bool e )
377{
378 if ( skin && skin->hasCursor() ) {
379 view->setCursor( Qt::BlankCursor );
380 if (secondaryView)
381 secondaryView->setCursor( Qt::BlankCursor );
382 } else {
383 view->setCursor( e ? Qt::ArrowCursor : Qt::BlankCursor );
384 if (secondaryView)
385 secondaryView->setCursor( e ? Qt::ArrowCursor : Qt::BlankCursor );
386 }
387 cursorAction->setChecked( e );
388}
389
390template <typename T>
391void QVFb::createMenu(T *menu)
392{
393 menu->addMenu( createFileMenu() );
394 menu->addMenu( createViewMenu() );
395 menu->addSeparator();
396 menu->addMenu( createHelpMenu() );
397}
398
399QMenu* QVFb::createFileMenu()
400{
401 QMenu *file = new QMenu( "File", this );
402 file->addAction( "Configure...", this, SLOT(configure()), 0 );
403 file->addSeparator();
404 file->addAction( "&Save image...", this, SLOT(saveImage()), 0 );
405 file->addAction( "&Animation...", this, SLOT(toggleAnimation()), 0 );
406 file->addSeparator();
407 file->addAction( "&Quit", qApp, SLOT(quit()) );
408 return file;
409}
410
411QMenu* QVFb::createViewMenu()
412{
413 viewMenu = new QMenu( "View", this );
414 cursorAction = viewMenu->addAction( "Show &Cursor", this,
415 SLOT(toggleCursor()) );
416 cursorAction->setCheckable(true);
417 if ( view )
418 enableCursor(true);
419 viewMenu->addAction( "&Refresh Rate...", this, SLOT(changeRate()) );
420 viewMenu->addSeparator();
421 viewMenu->addAction( "No rotation", this, SLOT(setRot0()) );
422 viewMenu->addAction( "90\260 rotation", this, SLOT(setRot90()) );
423 viewMenu->addAction( "180\260 rotation", this, SLOT(setRot180()) );
424 viewMenu->addAction( "270\260 rotation", this, SLOT(setRot270()) );
425 viewMenu->addSeparator();
426 viewMenu->addAction( "Zoom scale &0.5", this, SLOT(setZoomHalf()) );
427 viewMenu->addAction( "Zoom scale 0.75", this, SLOT(setZoom075()) );
428 viewMenu->addAction( "Zoom scale &1", this, SLOT(setZoom1()) );
429 viewMenu->addAction( "Zoom scale &2", this, SLOT(setZoom2()) );
430 viewMenu->addAction( "Zoom scale &3", this, SLOT(setZoom3()) );
431 viewMenu->addAction( "Zoom scale &4", this, SLOT(setZoom4()) );
432 viewMenu->addSeparator();
433 viewMenu->addAction( "Zoom scale...", this, SLOT(setZoom()) );
434 return viewMenu;
435}
436
437
438QMenu* QVFb::createHelpMenu()
439{
440 QMenu *help = new QMenu( "Help", this );
441 help->addAction("About...", this, SLOT(about()));
442 return help;
443}
444
445void QVFb::setZoom(double z)
446{
447 view->setZoom(z,z*skinscaleV/skinscaleH);
448 if (secondaryView)
449 secondaryView->setZoom(z,z*skinscaleV/skinscaleH);
450
451 if (skin) {
452 skin->setTransform(QMatrix().scale(z/skinscaleH,z/skinscaleV).rotate(90*view->displayRotation()));
453 if (secondaryView)
454 secondaryView->setFixedSize(
455 int(secondaryView->displayWidth()*z),
456 int(secondaryView->displayHeight()*z*skinscaleV/skinscaleH));
457 }
458}
459
460void QVFb::setRotation(QVFbView::Rotation r)
461{
462 view->setRotation(r);
463 if (secondaryView)
464 secondaryView->setRotation(r);
465 setZoom(view->zoomH());
466}
467
468void QVFb::setRot0()
469{
470 setRotation(QVFbView::Rot0);
471}
472
473void QVFb::setRot90()
474{
475 setRotation(QVFbView::Rot90);
476}
477
478void QVFb::setRot180()
479{
480 setRotation(QVFbView::Rot180);
481}
482
483void QVFb::setRot270()
484{
485 setRotation(QVFbView::Rot270);
486}
487
488void QVFb::setZoomHalf()
489{
490 setZoom(0.5);
491}
492
493void QVFb::setZoom075()
494{
495 setZoom(0.75);
496}
497
498void QVFb::setZoom1()
499{
500 setZoom(1);
501}
502
503void QVFb::setZoom()
504{
505 if ( !zoomer )
506 zoomer = new Zoomer(this);
507 zoomer->show();
508}
509
510void QVFb::setZoom2()
511{
512 setZoom(2);
513}
514
515void QVFb::setZoom3()
516{
517 setZoom(3);
518}
519
520void QVFb::setZoom4()
521{
522 setZoom(4);
523}
524
525void QVFb::saveImage()
526{
527 QImage img = view->image();
528 QString filename = QFileDialog::getSaveFileName(this, "Save Main Screen image", "snapshot.png", "Portable Network Graphics (*.png)");
529 if (!filename.isEmpty()){
530 if(!img.save(filename,"PNG"))
531 QMessageBox::critical(this, "Save Main Screen Image", "Save failed. Check that you have permission to write to the target directory.");
532 }
533 if (secondaryView) {
534 QImage img = view->image();
535 QString filename = QFileDialog::getSaveFileName(this, "Save Second Screen image", "snapshot.png", "Portable Network Graphics (*.png)");
536 if (!filename.isEmpty()) {
537 if(!img.save(filename,"PNG"))
538 QMessageBox::critical(this, "Save Second Screen Image", "Save failed. Check that you have permission to write to the target directory.");
539 }
540 }
541}
542
543void QVFb::toggleAnimation()
544{
545 static AnimationSaveWidget *animWidget = 0;
546 if ( !animWidget )
547 animWidget = new AnimationSaveWidget(view);
548 if ( animWidget->isVisible() )
549 animWidget->hide();
550 else
551 animWidget->show();
552}
553
554void QVFb::toggleCursor()
555{
556 enableCursor(cursorAction->isChecked());
557}
558
559void QVFb::changeRate()
560{
561 if ( !rateDlg ) {
562 rateDlg = new QVFbRateDialog( refreshRate, this );
563 connect( rateDlg, SIGNAL(updateRate(int)), this, SLOT(setRate(int)) );
564 }
565
566 rateDlg->show();
567}
568
569void QVFb::setRate(int i)
570{
571 refreshRate = i;
572 view->setRate(i);
573 if (secondaryView)
574 secondaryView->setRate(i);
575}
576
577
578void QVFb::about()
579{
580 QMessageBox::about(this, "About QVFB",
581 "<h2>The Qt for Embedded Linux Virtual X11 Framebuffer</h2>"
582 "<p>This application runs under Qt for X11, emulating a simple framebuffer, "
583 "which the Qt for Embedded Linux server and clients can attach to just as if "
584 "it was a hardware Linux framebuffer. "
585 "<p>With the aid of this development tool, you can develop Qt for Embedded "
586 "Linux applications under X11 without having to switch to a virtual console. "
587 "This means you can comfortably use your other development tools such "
588 "as GUI profilers and debuggers."
589 );
590}
591
592void QVFb::findSkins(const QString &currentSkin)
593{
594 skinnames.clear();
595 skinfiles.clear();
596 QDir dir(":/skins/","*.skin");
597 const QFileInfoList l = dir.entryInfoList();
598 int i = 1; // "None" is already in list at index 0
599 for (QFileInfoList::const_iterator it = l.begin(); it != l.end(); ++it) {
600 skinnames.append((*it).baseName()); // should perhaps be in file
601 skinfiles.append((*it).filePath());
602 if (((*it).baseName() + ".skin") == currentSkin)
603 currentSkinIndex = i;
604 i++;
605 }
606}
607
608class Config : public QDialog, public Ui::Config
609{
610public:
611 Config(QWidget *parent)
612 : QDialog(parent)
613 {
614 setupUi(this);
615 setModal(true);
616
617 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
618 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
619 }
620};
621
622void QVFb::configure()
623{
624 config = new Config(this);
625
626 int w = view->displayWidth();
627 int h = view->displayHeight();
628
629 // Need to block signals, because we connect to animateClick(),
630 // since QCheckBox doesn't have setChecked(bool) in 2.x.
631 chooseSize(QSize(w,h));
632 config->skin->insertItems(config->skin->count(), skinnames);
633 if (currentSkinIndex > 0)
634 config->skin->setCurrentIndex(currentSkinIndex);
635 config->skin->addItem(tr("Browse..."));
636 config->touchScreen->setChecked(view->touchScreenEmulation());
637 config->lcdScreen->setChecked(view->lcdScreenEmulation());
638 chooseDepth(view->displayDepth(), view->displayFormat());
639 config->rgbSwapped->setChecked(view->rgbSwapped());
640 connect(config->skin, SIGNAL(activated(int)), this, SLOT(skinConfigChosen(int)));
641 if ( view->gammaRed() == view->gammaGreen() && view->gammaGreen() == view->gammaBlue() ) {
642 config->gammaslider->setValue(int(view->gammaRed()*400));
643 config->rslider->setValue(100);
644 config->gslider->setValue(100);
645 config->bslider->setValue(100);
646 } else {
647 config->gammaslider->setValue(100);
648 config->rslider->setValue(int(view->gammaRed()*400));
649 config->gslider->setValue(int(view->gammaGreen()*400));
650 config->bslider->setValue(int(view->gammaBlue()*400));
651 }
652 connect(config->gammaslider, SIGNAL(valueChanged(int)), this, SLOT(setGamma400(int)));
653 connect(config->rslider, SIGNAL(valueChanged(int)), this, SLOT(setR400(int)));
654 connect(config->gslider, SIGNAL(valueChanged(int)), this, SLOT(setG400(int)));
655 connect(config->bslider, SIGNAL(valueChanged(int)), this, SLOT(setB400(int)));
656 updateGammaLabels();
657
658 double ogr=view->gammaRed(), ogg=view->gammaGreen(), ogb=view->gammaBlue();
659 qApp->setQuitOnLastWindowClosed(false);
660
661 hide();
662 if ( config->exec() ) {
663 int id = view->displayId(); // not settable yet
664 if ( config->size_176_220->isChecked() ) {
665 w=176; h=220;
666 } else if ( config->size_240_320->isChecked() ) {
667 w=240; h=320;
668 } else if ( config->size_320_240->isChecked() ) {
669 w=320; h=240;
670 } else if ( config->size_640_480->isChecked() ) {
671 w=640; h=480;
672 } else if ( config->size_800_480->isChecked() ) {
673 w=800; h=480;
674 } else if ( config->size_800_600->isChecked() ) {
675 w=800; h=600;
676 } else if ( config->size_1024_768->isChecked() ) {
677 w=1024; h=768;
678 } else {
679 w=config->size_width->value();
680 h=config->size_height->value();
681 }
682 int d;
683 if ( config->depth_1->isChecked() )
684 d=1;
685 else if ( config->depth_2gray->isChecked() )
686 d=2;
687 else if ( config->depth_4gray->isChecked() )
688 d=4;
689 else if ( config->depth_8->isChecked() )
690 d=8;
691 else if ( config->depth_12->isChecked() )
692 d=12;
693 else if ( config->depth_15->isChecked() )
694 d = 15;
695 else if ( config->depth_16->isChecked() )
696 d=16;
697 else if ( config->depth_18->isChecked() )
698 d=18;
699 else if ( config->depth_24->isChecked() )
700 d=24;
701 else
702 d=32;
703 QVFbView::PixelFormat displayFormat = config->depth_32_argb->isChecked()
704 ? QVFbView::ARGBFormat : QVFbView::DefaultFormat;
705 int skinIndex = config->skin->currentIndex();
706 if ( w != view->displayWidth() || h != view->displayHeight()
707 || d != view->displayDepth() || skinIndex != currentSkinIndex ) {
708 QVFbView::Rotation rot = view->displayRotation();
709 int r = ((rot == QVFbView::Rot90) ? 90 :
710 ((rot == QVFbView::Rot180) ? 180 :
711 ((rot == QVFbView::Rot270) ? 270 : 0 )));
712 currentSkinIndex = skinIndex;
713 init( id, w, h, d, r, skinIndex > 0 ? skinfiles[skinIndex-1] : QString::null );
714 }
715 view->setViewFormat(displayFormat);
716 view->setTouchscreenEmulation( config->touchScreen->isChecked() );
717 if (view->rgbSwapped() != config->rgbSwapped->isChecked()) {
718 //### the windowTitle logic is inside init(), and init isn't always invoked
719 QString caption = windowTitle();
720 if (!config->rgbSwapped->isChecked())
721 caption.replace(QLatin1String(" BGR"), QString());
722 else
723 caption.append(QLatin1String(" BGR"));
724 setWindowTitle(caption);
725 view->setRgbSwapped(config->rgbSwapped->isChecked());
726 }
727 bool lcdEmulation = config->lcdScreen->isChecked();
728 view->setLcdScreenEmulation( lcdEmulation );
729 if ( lcdEmulation )
730 setZoom3();
731 } else {
732 view->setGamma(ogr, ogg, ogb);
733 }
734 show();
735 qApp->setQuitOnLastWindowClosed(true);
736 delete config;
737 config=0;
738}
739
740void QVFb::chooseSize(const QSize& sz)
741{
742 config->size_width->blockSignals(true);
743 config->size_height->blockSignals(true);
744 config->size_width->setValue(sz.width());
745 config->size_height->setValue(sz.height());
746 config->size_width->blockSignals(false);
747 config->size_height->blockSignals(false);
748 config->size_custom->setChecked(true); // unless changed by settings below
749 config->size_176_220->setChecked(sz == QSize(176,220));
750 config->size_240_320->setChecked(sz == QSize(240,320));
751 config->size_320_240->setChecked(sz == QSize(320,240));
752 config->size_640_480->setChecked(sz == QSize(640,480));
753 config->size_800_480->setChecked(sz == QSize(800,480));
754 config->size_800_600->setChecked(sz == QSize(800,600));
755 config->size_1024_768->setChecked(sz == QSize(1024,768));
756}
757
758void QVFb::chooseDepth(int depth, QVFbView::PixelFormat displayFormat)
759{
760 config->depth_1->setChecked(depth==1);
761 config->depth_2gray->setChecked(depth==2);
762 config->depth_4gray->setChecked(depth==4);
763 config->depth_8->setChecked(depth==8);
764 config->depth_12->setChecked(depth==12);
765 config->depth_15->setChecked(depth==15);
766 config->depth_16->setChecked(depth==16);
767 config->depth_18->setChecked(depth==18);
768 config->depth_24->setChecked(depth==24);
769 config->depth_32->setChecked(depth==32 && displayFormat != QVFbView::ARGBFormat);
770 config->depth_32_argb->setChecked(depth==32 && displayFormat == QVFbView::ARGBFormat);
771}
772
773void QVFb::skinConfigChosen(int i)