21,489
社区成员
发帖
与我相关
我的任务
分享
#include <QtGui>
#include "mainwindow.h"
#include <QLabel>
#include <QSplitter>
#include <QHBoxLayout>
#include <QSlider>
#include <QSpinBox>
int spinBox1value;
int spinBox2value;
MainWindow::MainWindow()
: QMainWindow()
{
QSplitter *MainSplitter = new QSplitter(Qt::Horizontal);
area = new SvgWindow;
area->resize(289,maximumHeight ());
area->setStyleSheet("background-color:gray;");
QSplitter * WidgetRight = new QSplitter(Qt::Vertical);
//WidgetRight->setWindowTitle("Enter Your Age");
QWidget *SubWidget1 = new QWidget;
QWidget *SubWidget2 = new QWidget;
////////////////////////////////////////////////////////////////////////////////
QSpinBox *spinBox1 = new QSpinBox;
QSlider *slider1 = new QSlider(Qt::Horizontal);
spinBox1->setRange(0, 130);
slider1->setRange(0, 130);
QObject::connect(spinBox1, SIGNAL(valueChanged(int)),
slider1, SLOT(setValue(int)));
QObject::connect(slider1, SIGNAL(valueChanged(int)),
spinBox1, SLOT(setValue(int)));
QObject::connect(spinBox1, SIGNAL(valueChanged(int)),
this,SLOT(GetValue1(int)));
QObject::connect(spinBox1, SIGNAL(valueChanged(int)),
area,SLOT(SpinBoxEvent(int)));
spinBox1->setValue(35);
QHBoxLayout *layout1 = new QHBoxLayout;
layout1->addWidget(spinBox1);
layout1->addWidget(slider1);
SubWidget1->setLayout(layout1);
////////////////////////////////////////////////////////////////////////////
QSpinBox *spinBox2 = new QSpinBox;
QSlider *slider2 = new QSlider(Qt::Horizontal);
spinBox2->setRange(0, 130);
slider2->setRange(0, 130);
QObject::connect(spinBox2, SIGNAL(valueChanged(int)),
slider2, SLOT(setValue(int)));
QObject::connect(slider2, SIGNAL(valueChanged(int)),
spinBox2, SLOT(setValue(int)));
spinBox2->setValue(35);
QHBoxLayout *layout2 = new QHBoxLayout;
layout2->addWidget(spinBox2);
layout2->addWidget(slider2);
SubWidget2->setLayout(layout2);
/////////////////////////////////////////////////////////////////////////////
WidgetRight->addWidget(SubWidget1);
WidgetRight->addWidget(SubWidget2);
MainSplitter->addWidget(area);
MainSplitter->addWidget(WidgetRight);
setCentralWidget(MainSplitter);
QMenu *fileMenu = new QMenu(tr("&File"), this);
QAction *openAction = fileMenu->addAction(tr("&Open..."));
openAction->setShortcut(QKeySequence(tr("Ctrl+O")));
QAction *quitAction = fileMenu->addAction(tr("E&xit"));
quitAction->setShortcut(QKeySequence(tr("Ctrl+Q")));
menuBar()->addMenu(fileMenu);
QMenu *rendererMenu = new QMenu(tr("&Renderer"), this);
nativeAction = rendererMenu->addAction(tr("&Native"));
nativeAction->setCheckable(true);
nativeAction->setChecked(true);
#ifndef QT_NO_OPENGL
glAction = rendererMenu->addAction(tr("&OpenGL"));
glAction->setCheckable(true);
#endif
imageAction = rendererMenu->addAction(tr("&Image"));
imageAction->setCheckable(true);
QActionGroup *rendererGroup = new QActionGroup(this);
rendererGroup->addAction(nativeAction);
#ifndef QT_NO_OPENGL
rendererGroup->addAction(glAction);
#endif
rendererGroup->addAction(imageAction);
menuBar()->addMenu(rendererMenu);
connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
connect(rendererGroup, SIGNAL(triggered(QAction *)),
this, SLOT(setRenderer(QAction *)));
//setCentralWidget(area);
setWindowTitle(tr("SVG Viewer"));
}
void MainWindow::openFile(const QString &path)
{
QString fileName;
if (path.isNull())
fileName = QFileDialog::getOpenFileName(this, tr("Open SVG File"),
currentPath, "*.svg");
else
fileName = path;
if (!fileName.isEmpty()) {
area->openFile(fileName);
if (!fileName.startsWith(":/")) {
currentPath = fileName;
setWindowTitle(tr("%1 - SVGViewer").arg(currentPath));
}
}
}
void MainWindow::setRenderer(QAction *action)
{
if (action == nativeAction)
area->setRenderer(SvgWindow::Native);
#ifndef QT_NO_OPENGL
else if (action == glAction)
area->setRenderer(SvgWindow::OpenGL);
#endif
else if (action == imageAction)
area->setRenderer(SvgWindow::Image);
}
void MainWindow::GetValue1(int value1)
{
spinBox1value=spinBox1->value();
}