📄 qvfb.cpp
字号:
}void QVFb::enableCursor( bool e ){ if ( skin && skin->hasCursor() ) { view->setCursor( Qt::BlankCursor ); if (secondaryView) secondaryView->setCursor( Qt::BlankCursor ); } else { view->setCursor( e ? Qt::ArrowCursor : Qt::BlankCursor ); if (secondaryView) secondaryView->setCursor( e ? Qt::ArrowCursor : Qt::BlankCursor ); } cursorAction->setChecked( e );}template <typename T>void QVFb::createMenu(T *menu){ menu->addMenu( createFileMenu() ); menu->addMenu( createViewMenu() ); menu->addSeparator(); menu->addMenu( createHelpMenu() );}QMenu* QVFb::createFileMenu(){ QMenu *file = new QMenu( "File", this ); file->addAction( "Configure...", this, SLOT(configure()), 0 ); file->addSeparator(); file->addAction( "&Save image...", this, SLOT(saveImage()), 0 ); file->addAction( "&Animation...", this, SLOT(toggleAnimation()), 0 ); file->addSeparator(); file->addAction( "&Quit", qApp, SLOT(quit()) ); return file;}QMenu* QVFb::createViewMenu(){ viewMenu = new QMenu( "View", this ); cursorAction = viewMenu->addAction( "Show &Cursor", this, SLOT(toggleCursor()) ); cursorAction->setCheckable(true); if ( view ) enableCursor(true); viewMenu->addAction( "&Refresh Rate...", this, SLOT(changeRate()) ); viewMenu->addSeparator(); viewMenu->addAction( "No rotation", this, SLOT(setRot0()) ); viewMenu->addAction( "90\260 rotation", this, SLOT(setRot90()) ); viewMenu->addAction( "180\260 rotation", this, SLOT(setRot180()) ); viewMenu->addAction( "270\260 rotation", this, SLOT(setRot270()) ); viewMenu->addSeparator(); viewMenu->addAction( "Zoom scale &0.5", this, SLOT(setZoomHalf()) ); viewMenu->addAction( "Zoom scale 0.75", this, SLOT(setZoom075()) ); viewMenu->addAction( "Zoom scale &1", this, SLOT(setZoom1()) ); viewMenu->addAction( "Zoom scale &2", this, SLOT(setZoom2()) ); viewMenu->addAction( "Zoom scale &3", this, SLOT(setZoom3()) ); viewMenu->addAction( "Zoom scale &4", this, SLOT(setZoom4()) ); viewMenu->addSeparator(); viewMenu->addAction( "Zoom scale...", this, SLOT(setZoom()) ); return viewMenu;}QMenu* QVFb::createHelpMenu(){ QMenu *help = new QMenu( "Help", this ); help->addAction("About...", this, SLOT(about())); return help;}void QVFb::setZoom(double z){ view->setZoom(z,z*skinscaleV/skinscaleH); if (secondaryView) secondaryView->setZoom(z,z*skinscaleV/skinscaleH); if (skin) { skin->setTransform(QMatrix().scale(z/skinscaleH,z/skinscaleV).rotate(90*view->displayRotation())); if (secondaryView) secondaryView->setFixedSize( int(secondaryView->displayWidth()*z), int(secondaryView->displayHeight()*z*skinscaleV/skinscaleH)); }}void QVFb::setRotation(QVFbView::Rotation r){ view->setRotation(r); if (secondaryView) secondaryView->setRotation(r); setZoom(view->zoomH());}void QVFb::setRot0(){ setRotation(QVFbView::Rot0);}void QVFb::setRot90(){ setRotation(QVFbView::Rot90);}void QVFb::setRot180(){ setRotation(QVFbView::Rot180);}void QVFb::setRot270(){ setRotation(QVFbView::Rot270);}void QVFb::setZoomHalf(){ setZoom(0.5);}void QVFb::setZoom075(){ setZoom(0.75);}void QVFb::setZoom1(){ setZoom(1);}void QVFb::setZoom(){ if ( !zoomer ) zoomer = new Zoomer(this); zoomer->show();}void QVFb::setZoom2(){ setZoom(2);}void QVFb::setZoom3(){ setZoom(3);}void QVFb::setZoom4(){ setZoom(4);}void QVFb::saveImage(){ QImage img = view->image(); QString filename = QFileDialog::getSaveFileName(this, "Save Main Screen image", "snapshot.png", "Portable Network Graphics (*.png)"); if (!filename.isEmpty()){ if(!img.save(filename,"PNG")) QMessageBox::critical(this, "Save Main Screen Image", "Save failed. Check that you have permission to write to the target directory."); } if (secondaryView) { QImage img = view->image(); QString filename = QFileDialog::getSaveFileName(this, "Save Second Screen image", "snapshot.png", "Portable Network Graphics (*.png)"); if (!filename.isEmpty()) { if(!img.save(filename,"PNG")) QMessageBox::critical(this, "Save Second Screen Image", "Save failed. Check that you have permission to write to the target directory."); } }}void QVFb::toggleAnimation(){ static AnimationSaveWidget *animWidget = 0; if ( !animWidget ) animWidget = new AnimationSaveWidget(view); if ( animWidget->isVisible() ) animWidget->hide(); else animWidget->show();}void QVFb::toggleCursor(){ enableCursor(cursorAction->isChecked());}void QVFb::changeRate(){ if ( !rateDlg ) { rateDlg = new QVFbRateDialog( refreshRate, this ); connect( rateDlg, SIGNAL(updateRate(int)), this, SLOT(setRate(int)) ); } rateDlg->show();}void QVFb::setRate(int i){ refreshRate = i; view->setRate(i); if (secondaryView) secondaryView->setRate(i);}void QVFb::about(){ QMessageBox::about(this, "About QVFB", "<h2>The Qt for Embedded Linux Virtual X11 Framebuffer</h2>" "<p>This application runs under Qt for X11, emulating a simple framebuffer, " "which the Qt for Embedded Linux server and clients can attach to just as if " "it was a hardware Linux framebuffer. " "<p>With the aid of this development tool, you can develop Qt for Embedded " "Linux applications under X11 without having to switch to a virtual console. " "This means you can comfortably use your other development tools such " "as GUI profilers and debuggers." );}void QVFb::findSkins(const QString ¤tSkin){ skinnames.clear(); skinfiles.clear(); QDir dir(":/skins/","*.skin"); const QFileInfoList l = dir.entryInfoList(); int i = 1; // "None" is already in list at index 0 for (QFileInfoList::const_iterator it = l.begin(); it != l.end(); ++it) { skinnames.append((*it).baseName()); // should perhaps be in file skinfiles.append((*it).filePath()); if (((*it).baseName() + ".skin") == currentSkin) currentSkinIndex = i; i++; }}class Config : public QDialog, public Ui::Config{public: Config(QWidget *parent) : QDialog(parent) { setupUi(this); setModal(true); connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept())); connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject())); }};void QVFb::configure(){ config = new Config(this); int w = view->displayWidth(); int h = view->displayHeight(); // Need to block signals, because we connect to animateClick(), // since QCheckBox doesn't have setChecked(bool) in 2.x. chooseSize(QSize(w,h)); config->skin->insertItems(config->skin->count(), skinnames); if (currentSkinIndex > 0) config->skin->setCurrentIndex(currentSkinIndex); config->skin->addItem(tr("Browse...")); config->touchScreen->setChecked(view->touchScreenEmulation()); config->lcdScreen->setChecked(view->lcdScreenEmulation()); chooseDepth(view->displayDepth(), view->displayFormat()); connect(config->skin, SIGNAL(activated(int)), this, SLOT(skinConfigChosen(int))); if ( view->gammaRed() == view->gammaGreen() && view->gammaGreen() == view->gammaBlue() ) { config->gammaslider->setValue(int(view->gammaRed()*400)); config->rslider->setValue(100); config->gslider->setValue(100); config->bslider->setValue(100); } else { config->gammaslider->setValue(100); config->rslider->setValue(int(view->gammaRed()*400)); config->gslider->setValue(int(view->gammaGreen()*400)); config->bslider->setValue(int(view->gammaBlue()*400)); } connect(config->gammaslider, SIGNAL(valueChanged(int)), this, SLOT(setGamma400(int))); connect(config->rslider, SIGNAL(valueChanged(int)), this, SLOT(setR400(int))); connect(config->gslider, SIGNAL(valueChanged(int)), this, SLOT(setG400(int))); connect(config->bslider, SIGNAL(valueChanged(int)), this, SLOT(setB400(int))); updateGammaLabels(); double ogr=view->gammaRed(), ogg=view->gammaGreen(), ogb=view->gammaBlue(); qApp->setQuitOnLastWindowClosed(false); hide(); if ( config->exec() ) { int id = view->displayId(); // not settable yet if ( config->size_176_220->isChecked() ) { w=176; h=220; } else if ( config->size_240_320->isChecked() ) { w=240; h=320; } else if ( config->size_320_240->isChecked() ) { w=320; h=240; } else if ( config->size_640_480->isChecked() ) { w=640; h=480; } else if ( config->size_800_600->isChecked() ) { w=800; h=600; } else if ( config->size_1024_768->isChecked() ) { w=1024; h=768; } else { w=config->size_width->value(); h=config->size_height->value(); } int d; if ( config->depth_1->isChecked() ) d=1; else if ( config->depth_4gray->isChecked() ) d=4; else if ( config->depth_8->isChecked() ) d=8; else if ( config->depth_12->isChecked() ) d=12; else if ( config->depth_15->isChecked() ) d = 15; else if ( config->depth_16->isChecked() ) d=16; else if ( config->depth_18->isChecked() ) d=18; else if ( config->depth_24->isChecked() ) d=24; else d=32; QVFbView::PixelFormat displayFormat = config->depth_32_argb->isChecked() ? QVFbView::ARGBFormat : QVFbView::DefaultFormat; int skinIndex = config->skin->currentIndex(); if ( w != view->displayWidth() || h != view->displayHeight() || d != view->displayDepth() || skinIndex != currentSkinIndex ) { QVFbView::Rotation rot = view->displayRotation(); int r = ((rot == QVFbView::Rot90) ? 90 : ((rot == QVFbView::Rot180) ? 180 : ((rot == QVFbView::Rot270) ? 270 : 0 ))); currentSkinIndex = skinIndex; init( id, w, h, d, r, skinIndex > 0 ? skinfiles[skinIndex-1] : QString::null ); } view->setViewFormat(displayFormat); view->setTouchscreenEmulation( config->touchScreen->isChecked() ); bool lcdEmulation = config->lcdScreen->isChecked(); view->setLcdScreenEmulation( lcdEmulation ); if ( lcdEmulation ) setZoom3(); } else { view->setGamma(ogr, ogg, ogb); } show(); qApp->setQuitOnLastWindowClosed(true); delete config; config=0;}void QVFb::chooseSize(const QSize& sz){ config->size_width->blockSignals(true); config->size_height->blockSignals(true); config->size_width->setValue(sz.width()); config->size_height->setValue(sz.height()); config->size_width->blockSignals(false); config->size_height->blockSignals(false); config->size_custom->setChecked(true); // unless changed by settings below config->size_176_220->setChecked(sz == QSize(176,220)); config->size_240_320->setChecked(sz == QSize(240,320)); config->size_320_240->setChecked(sz == QSize(320,240)); config->size_640_480->setChecked(sz == QSize(640,480)); config->size_800_600->setChecked(sz == QSize(800,600)); config->size_1024_768->setChecked(sz == QSize(1024,768));}void QVFb::chooseDepth(int depth, QVFbView::PixelFormat displayFormat){ config->depth_1->setChecked(depth==1); config->depth_4gray->setChecked(depth==4); config->depth_8->setChecked(depth==8); config->depth_12->setChecked(depth==12); config->depth_15->setChecked(depth==15); config->depth_16->setChecked(depth==16); config->depth_18->setChecked(depth==18); config->depth_24->setChecked(depth==24); config->depth_32->setChecked(depth==32 && displayFormat != QVFbView::ARGBFormat); config->depth_32_argb->setChecked(depth==32 && displayFormat == QVFbView::ARGBFormat);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -