⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qvfb.cpp

📁 Qt4.5 提供的qvfb,最新版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).** Contact: Qt Software Information (qt-info@nokia.com)**** This file is part of the tools applications of the Qt Toolkit.**** $QT_BEGIN_LICENSE:LGPL$** Commercial Usage** Licensees holding valid Qt Commercial licenses may use this file in** accordance with the Qt Commercial License Agreement provided with the** Software or, alternatively, in accordance with the terms contained in** a written agreement between you and Nokia.**** GNU Lesser General Public License Usage** Alternatively, this file may be used under the terms of the GNU Lesser** General Public License version 2.1 as published by the Free Software** Foundation and appearing in the file LICENSE.LGPL included in the** packaging of this file.  Please review the following information to** ensure the GNU Lesser General Public License version 2.1 requirements** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.**** In addition, as a special exception, Nokia gives you certain** additional rights. These rights are described in the Nokia Qt LGPL** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this** package.**** GNU General Public License Usage** Alternatively, this file may be used under the terms of the GNU** General Public License version 3.0 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.  Please review the following information to** ensure the GNU General Public License version 3.0 requirements will be** met: http://www.gnu.org/copyleft/gpl.html.**** If you are unsure which license is appropriate for your use, please** contact the sales department at qt-sales@nokia.com.** $QT_END_LICENSE$******************************************************************************/#include "qvfb.h"#include "qvfbview.h"#ifdef Q_WS_X11#include "qvfbx11view.h"#endif#include "qvfbratedlg.h"#include "ui_config.h"#include "qanimationwriter.h"#include <deviceskin.h>#include <QMenuBar>#include <QMenu>#include <QApplication>#include <QMessageBox>#include <QComboBox>#include <QLabel>#include <QFileDialog>#include <QSlider>#include <QSpinBox>#include <QLayout>#include <QRadioButton>#include <QImage>#include <QPixmap>#include <QCheckBox>#include <QCursor>#include <QTime>#include <QScrollArea>#include <QProgressBar>#include <QPushButton>#include <QTextStream>#include <QFile>#include <QFileInfo>#include <QDebug>#include <unistd.h>#include <stdlib.h>#include <sys/types.h>QT_BEGIN_NAMESPACE// =====================================================================static const char *red_on_led_xpm[] = {"11 11 10 1"," 	c None",".	c #FF0000","+	c #FF4C4C","@	c #FF7A7A","#	c #D30000","$	c #FF9393","%	c #BA0000","&	c #FFFFFF","*	c #7F0000","=	c #000000","           ","   .++@@   ","  .....+@  "," ##...$.+@ "," %#..$&$.+ "," *#...$..+ "," *%#...... "," =*%#..... ","  =*%###.  ","   ===*.   ","           "};static const char *red_off_led_xpm[] = {"11 11 12 1"," 	c None",".	c #CDB7B4","+	c #D2BFBD","@	c #DBCBCA","#	c #E5D9D8","$	c #BC9E9B","%	c #E2D6D5","&	c #AD8986","*	c #FFFFFF","=	c #A8817D","-	c #B2908D",";	c #6F4D4A","           ","   .++@#   ","  .....@#  "," $$...%.@# "," &$..%*%.@ "," =-...%..+ "," =&-...... "," ;==-..... ","  ;=&-$$.  ","   ;==&$   ","           "};static bool copyButtonConfiguration(const QString &prefix, int displayId){    const QString destDir = QString(QLatin1String("/tmp/qtembedded-%1/")).arg(displayId);    const QFileInfo src(prefix + QLatin1String("defaultbuttons.conf"));    const QFileInfo dst(destDir + QLatin1String("defaultbuttons.conf"));    unlink(dst.absoluteFilePath().toLatin1().constData());    if (!src.exists())        return false;    const bool rc = QFile::copy(src.absoluteFilePath(), dst.absoluteFilePath());    if (!rc)        qWarning() << "Failed to copy the button configuration file " << src.absoluteFilePath() << " to " <<  dst.absoluteFilePath() << '.';    return rc;}// =====================================================================class AnimationSaveWidget : public QWidget {    Q_OBJECTpublic:    AnimationSaveWidget(QVFbAbstractView *v);    ~AnimationSaveWidget();    bool detectPpmtoMpegCommand();    void timerEvent(QTimerEvent *te);    void convertToMpeg(QString filename);    void removeTemporaryFiles();protected slots:    void toggleRecord();    void reset();    void save();private:    QVFbAbstractView *view;    QProgressBar *progressBar;    QLabel *statusText;    bool haveMpeg, savingAsMpeg, recording;    QCheckBox *mpegSave;    QAnimationWriter *animation;    QPushButton *recBt, *resetBt, *saveBt;    QLabel *timeDpy, *recLED;    int timerId, progressTimerId;    QPixmap recOn, recOff;    QTime tm;    int elapsed, imageNum;};// =====================================================================Zoomer::Zoomer(QVFb* target) :    qvfb(target){    QVBoxLayout *layout = new QVBoxLayout(this);    QSlider *sl = new QSlider(Qt::Horizontal);    sl->setMinimum(10);    sl->setMaximum(64);    sl->setPageStep(1);    sl->setValue(32);    layout->addWidget(sl);    connect(sl,SIGNAL(valueChanged(int)),this,SLOT(zoom(int)));    label = new QLabel();    layout->addWidget(label);}void Zoomer::zoom(int z){    double d = (double)z/32.0;    qvfb->setZoom(d);    label->setText(QString::number(d,'g',2));}// =====================================================================QVFb::QVFb( int display_id, int w, int h, int d, int r, const QString &skin, DisplayType displayType, QWidget *parent, Qt::WindowFlags flags )    : QMainWindow( parent, flags ){    this->displayType = displayType;    view = 0;    secondaryView = 0;    scroller = 0;    this->skin = 0;    currentSkinIndex = -1;    findSkins(skin);    zoomer = 0;    QPixmap pix(":/res/images/logo.png");    setWindowIcon( pix );    rateDlg = 0;    refreshRate = 30;#if QT_VERSION >= 0x030000    // When compiling with Qt 3 we need to create the menu first to    // avoid scroll bars in the main window    createMenu( menuBar() );    init( display_id, w, h, d, r, skin );    enableCursor( true );#else    init( display_id, w, h, d, r, skin );    createMenu( menuBar() );#endif}QVFb::~QVFb(){}void QVFb::popupMenu(){    QMenu *pm = new QMenu( this );    createMenu( pm );    pm->exec(QCursor::pos());}void QVFb::init( int display_id, int pw, int ph, int d, int r, const QString& skin_name ){    delete view;    view = 0;    delete secondaryView;    secondaryView = 0;    delete scroller;    scroller = 0;    delete skin;    skin = 0;    skinscaleH = skinscaleV = 1.0;    QVFbView::Rotation rot = ((r ==  90) ? QVFbView::Rot90  :			     ((r == 180) ? QVFbView::Rot180 :			     ((r == 270) ? QVFbView::Rot270 :					   QVFbView::Rot0 )));    if ( !skin_name.isEmpty() ) {	const bool vis = isVisible();	DeviceSkinParameters parameters;	QString readError;	if (parameters.read(skin_name,DeviceSkinParameters::ReadAll, &readError)) {	    skin = new DeviceSkin(parameters, this);	    connect(skin, SIGNAL(popupMenu()), this, SLOT(popupMenu()));	    const int sw = parameters.screenSize().width();	    const int sh = parameters.screenSize().height();	    const int sd = parameters.screenDepth;            if (!pw) pw = sw;            if (!ph) ph = sh;            if (d < 0) {                if (sd)                    d = sd;                else                    d = -d;            }            if (vis)                hide();    	    menuBar()->hide();	    scroller = 0;#ifdef Q_WS_X11	    if (displayType == X11)		view = new QVFbX11View( display_id, pw, ph, d, rot, skin );	    else#endif		view = new QVFbView( display_id, pw, ph, d, rot, skin );	    skin->setView( view );	    view->setContentsMargins( 0, 0, 0, 0 );            view->setTouchscreenEmulation(!parameters.hasMouseHover);	    connect(skin, SIGNAL(skinKeyPressEvent(int,QString,bool)), view, SLOT(skinKeyPressEvent(int,QString,bool)));	    connect(skin, SIGNAL(skinKeyReleaseEvent(int,QString,bool)), view, SLOT(skinKeyReleaseEvent(int,QString,bool)));	    copyButtonConfiguration(skin->prefix(), view->displayId());	    setCentralWidget( skin );	    adjustSize();	    skinscaleH = (double)sw/pw;	    skinscaleV = (double)sh/ph;	    if ( skinscaleH != 1.0 || skinscaleH != 1.0 )		setZoom(skinscaleH);	    view->show();            if (parameters.hasSecondaryScreen()) {                const QSize ssize = parameters.secondaryScreenSize();                // assumes same depth and rotation#ifdef Q_WS_X11		if (displayType == X11)		    secondaryView = new QVFbX11View( display_id+1, ssize.width(), ssize.height(), d, rot, skin );		else#endif		    secondaryView = new QVFbView( display_id+1, ssize.width(), ssize.height(), d, rot, skin );                skin->setSecondaryView(secondaryView);                secondaryView->show();            }	    if ( vis ) show();	} else {	    qWarning("%s", qPrintable(readError));	}    }    // If we failed to get a skin or we were not supplied    //	    with one then fallback to a framebuffer without    //	    a skin    if (!skin){	// Default values	if (!pw)            pw = 240;	if (!ph)            ph = 320;        if (!d)            d = 32;        else if (d < 0)            d = -d;     	if (currentSkinIndex != -1) {	    clearMask();            setParent( 0, 0 );            move( pos() );            show();	    //unset fixed size:	    setMinimumSize(0,0);	    setMaximumSize(QWIDGETSIZE_MAX,QWIDGETSIZE_MAX);	}	menuBar()->show();	scroller = new QScrollArea(this);	scroller->setFocusPolicy(Qt::NoFocus); // don't steal key events from the embedded app#ifdef Q_WS_X11	if (displayType == X11)	    view = new QVFbX11View( display_id, pw, ph, d, rot, scroller );	else#endif	    view = new QVFbView( display_id, pw, ph, d, rot, scroller );	scroller->setWidget(view);	view->setContentsMargins( 0, 0, 0, 0 );	setCentralWidget(scroller);#if QT_VERSION >= 0x030000	ph += 2;					// avoid scrollbar#endif	scroller->show();	// delete defaultbuttons.conf if it was left behind...	unlink(QFileInfo(QString("/tmp/qtembedded-%1/defaultbuttons.conf").arg(view->displayId())).absoluteFilePath().toLatin1().constData());        if (secondaryView)            unlink(QFileInfo(QString("/tmp/qtembedded-%1/defaultbuttons.conf").arg(view->displayId()+1)).absoluteFilePath().toLatin1().constData());    }    view->setRate(refreshRate);    if (secondaryView) {        secondaryView->setRate(refreshRate);    }    // Resize QVFb to the new size    QSize newSize = view->sizeHint();    // ... fudge factor    newSize += QSize(20, 35);    resize(newSize);    setWindowTitle(QString("Virtual framebuffer %1x%2 %3bpp Display :%4 Rotate %5")               .arg(view->displayWidth()).arg(view->displayHeight())               .arg(d).arg(display_id).arg(r));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -