/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
** the names of its contributors may be used to endorse or promote
** products derived from this software without specific prior written
** permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
**
****************************************************************************/#include <QtGui>#include "mainwindow.h"#include "tabletcanvas.h"
MainWindow::MainWindow(TabletCanvas *canvas)
{
myCanvas = canvas;
createActions();
createMenus();
myCanvas->setColor(Qt::red);
myCanvas->setLineWidthType(TabletCanvas::LineWidthPressure);
myCanvas->setAlphaChannelType(TabletCanvas::NoAlpha);
myCanvas->setColorSaturationType(TabletCanvas::NoSaturation);
setWindowTitle(tr("Tablet Example"));
setCentralWidget(myCanvas);
}
void MainWindow::brushColorAct()
{
QColor color =QColorDialog::getColor(myCanvas->color());
if (color.isValid())
myCanvas->setColor(color);
}
void MainWindow::alphaActionTriggered(QAction*action)
{
if (action == alphaChannelPressureAction) {
myCanvas->setAlphaChannelType(TabletCanvas::AlphaPressure);
} elseif (action == alphaChannelTiltAction) {
myCanvas->setAlphaChannelType(TabletCanvas::AlphaTilt);
} else {
myCanvas->setAlphaChannelType(TabletCanvas::NoAlpha);
}
}
void MainWindow::lineWidthActionTriggered(QAction*action)
{
if (action == lineWidthPressureAction) {
myCanvas->setLineWidthType(TabletCanvas::LineWidthPressure);
} elseif (action == lineWidthTiltAction) {
myCanvas->setLineWidthType(TabletCanvas::LineWidthTilt);
} else {
myCanvas->setLineWidthType(TabletCanvas::NoLineWidth);
}
}
void MainWindow::saturationActionTriggered(QAction*action)
{
if (action == colorSaturationVTiltAction) {
myCanvas->setColorSaturationType(TabletCanvas::SaturationVTilt);
} elseif (action == colorSaturationHTiltAction) {
myCanvas->setColorSaturationType(TabletCanvas::SaturationHTilt);
} elseif (action == colorSaturationPressureAction) {
myCanvas->setColorSaturationType(TabletCanvas::SaturationPressure);
} else {
myCanvas->setColorSaturationType(TabletCanvas::NoSaturation);
}
}
void MainWindow::saveAct()
{
QString path =QDir::currentPath() +"/untitled.png";
QString fileName =QFileDialog::getSaveFileName(this, tr("Save Picture"),
path);
if (!myCanvas->saveImage(fileName))
QMessageBox::information(this,"Error Saving Picture","Could not save the image");
}
void MainWindow::loadAct()
{
QString fileName =QFileDialog::getOpenFileName(this, tr("Open Picture"),QDir::currentPath());
if (!myCanvas->loadImage(fileName))
QMessageBox::information(this,"Error Opening Picture","Could not open picture");
}
void MainWindow::aboutAct()
{
QMessageBox::about(this, tr("About Tablet Example"),
tr("This example shows use of a Wacom tablet in Qt"));
}
void MainWindow::createActions()
{
brushColorAction =newQAction(tr("&Brush Color..."),this);
brushColorAction->setShortcut(tr("Ctrl+C"));
connect(brushColorAction, SIGNAL(triggered()),this, SLOT(brushColorAct()));
alphaChannelPressureAction =newQAction(tr("&Pressure"),this);
alphaChannelPressureAction->setCheckable(true);
alphaChannelTiltAction =newQAction(tr("&Tilt"),this);
alphaChannelTiltAction->setCheckable(true);
noAlphaChannelAction =newQAction(tr("No Alpha Channel"),this);
noAlphaChannelAction->setCheckable(true);
noAlphaChannelAction->setChecked(true);
alphaChannelGroup =newQActionGroup(this);
alphaChannelGroup->addAction(alphaChannelPressureAction);
alphaChannelGroup->addAction(alphaChannelTiltAction);
alphaChannelGroup->addAction(noAlphaChannelAction);
connect(alphaChannelGroup, SIGNAL(triggered(QAction*)),this, SLOT(alphaActionTriggered(QAction*)));
colorSaturationVTiltAction =newQAction(tr("&Vertical Tilt"),this);
colorSaturationVTiltAction->setCheckable(true);
colorSaturationHTiltAction =newQAction(tr("&Horizontal Tilt"),this);
colorSaturationHTiltAction->setCheckable(true);
colorSaturationPressureAction =newQAction(tr("&Pressure"),this);
colorSaturationPressureAction->setCheckable(true);
noColorSaturationAction =newQAction(tr("&No Color Saturation"),this);
noColorSaturationAction->setCheckable(true);
noColorSaturationAction->setChecked(true);
colorSaturationGroup =newQActionGroup(this);
colorSaturationGroup->addAction(colorSaturationVTiltAction);
colorSaturationGroup->addAction(colorSaturationHTiltAction);
colorSaturationGroup->addAction(colorSaturationPressureAction);
colorSaturationGroup->addAction(noColorSaturationAction);
connect(colorSaturationGroup, SIGNAL(triggered(QAction*)),this, SLOT(saturationActionTriggered(QAction*)));
lineWidthPressureAction =newQAction(tr("&Pressure"),this);
lineWidthPressureAction->setCheckable(true);
lineWidthPressureAction->setChecked(true);
lineWidthTiltAction =newQAction(tr("&Tilt"),this);
lineWidthTiltAction->setCheckable(true);
lineWidthFixedAction =newQAction(tr("&Fixed"),this);
lineWidthFixedAction->setCheckable(true);
lineWidthGroup =newQActionGroup(this);
lineWidthGroup->addAction(lineWidthPressureAction);
lineWidthGroup->addAction(lineWidthTiltAction);
lineWidthGroup->addAction(lineWidthFixedAction);
connect(lineWidthGroup, SIGNAL(triggered(QAction*)),this, SLOT(lineWidthActionTriggered(QAction*)));
exitAction =newQAction(tr("E&xit"),this);
exitAction->setShortcuts(QKeySequence::Quit);
connect(exitAction, SIGNAL(triggered()),this, SLOT(close()));
loadAction =newQAction(tr("&Open..."),this);
loadAction->setShortcuts(QKeySequence::Open);
connect(loadAction, SIGNAL(triggered()),this, SLOT(loadAct()));
saveAction =newQAction(tr("&Save As..."),this);
saveAction->setShortcuts(QKeySequence::SaveAs);
connect(saveAction, SIGNAL(triggered()),this, SLOT(saveAct()));
aboutAction =newQAction(tr("A&bout"),this);
aboutAction->setShortcut(tr("Ctrl+B"));
connect(aboutAction, SIGNAL(triggered()),this, SLOT(aboutAct()));
aboutQtAction =newQAction(tr("About &Qt"),this);
aboutQtAction->setShortcut(tr("Ctrl+Q"));
connect(aboutQtAction, SIGNAL(triggered()),
qApp, SLOT(aboutQt()));
}
void MainWindow::createMenus()
{
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(loadAction);
fileMenu->addAction(saveAction);
fileMenu->addSeparator();
fileMenu->addAction(exitAction);
brushMenu = menuBar()->addMenu(tr("&Brush"));
brushMenu->addAction(brushColorAction);
tabletMenu = menuBar()->addMenu(tr("&Tablet"));
lineWidthMenu = tabletMenu->addMenu(tr("&Line Width"));
lineWidthMenu->addAction(lineWidthPressureAction);
lineWidthMenu->addAction(lineWidthTiltAction);
lineWidthMenu->addAction(lineWidthFixedAction);
alphaChannelMenu = tabletMenu->addMenu(tr("&Alpha Channel"));
alphaChannelMenu->addAction(alphaChannelPressureAction);
alphaChannelMenu->addAction(alphaChannelTiltAction);
alphaChannelMenu->addAction(noAlphaChannelAction);
colorSaturationMenu = tabletMenu->addMenu(tr("&Color Saturation"));
colorSaturationMenu->addAction(colorSaturationVTiltAction);
colorSaturationMenu->addAction(colorSaturationHTiltAction);
colorSaturationMenu->addAction(noColorSaturationAction);
helpMenu = menuBar()->addMenu("&Help");
helpMenu->addAction(aboutAction);
helpMenu->addAction(aboutQtAction);
}
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter
ou par MP !