Beispiel #1
0
/****************************************************************************
**
** Copyright (C) 2015
**
** This file is generated by the Magus toolkit
**
** 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."
**
****************************************************************************/

// Include
#include <QString>
#include <QFile>
#include <QMenuBar>
#include <QHBoxLayout>
#include <QPixmap>
#include "mainwindow.h"
#include "tool_filereader.h"
#include "tool_gradientwidget.h"
#include "tool_sceneviewwidget.h"
#include "tool_layered_sceneviewwidget.h"
#include "tool_glspherewidget.h"

//****************************************************************************/
MainWindow::MainWindow(void) : mIsClosing(false)
{
    mTextureSelection = 0;
    mTextureSelectionExt = 0;

	// Perform standard functions
    createActions();
    createMenus();
    createToolBars();
    createStatusBar();
    createDockWindows();

    // Set the title
    setWindowTitle(QString("Tools"));

    // Set the stylesheet of the application
    QFile File(QString("dark.qss"));
    File.open(QFile::ReadOnly);
    QString styleSheet = QLatin1String(File.readAll());
    setStyleSheet(styleSheet);
	showMaximized();
}

//****************************************************************************/
MainWindow::~MainWindow(void)
{

}

//****************************************************************************/
void MainWindow::closeEvent(QCloseEvent* event)
{
    mIsClosing = true;
}

//****************************************************************************/
void MainWindow::createActions(void)
{
    mGradientMenuAction = new QAction(QString("Gradient"), this);
    mGlSphereMenuAction = new QAction(QString("GL Sphere"), this);
    mTextureMenuAction = new QAction(QString("Texture selection"), this);
    mExtendedTextureMenuAction = new QAction(QString("Extended texture selection"), this);
    mLayerAndSceneViewMenuAction = new QAction(QString("Layer and Scene view"), this);
    connect(mGradientMenuAction, SIGNAL(triggered()), this, SLOT(doGradientMenuAction()));
    connect(mGlSphereMenuAction, SIGNAL(triggered()), this, SLOT(doGlSphereMenuAction()));
    connect(mTextureMenuAction, SIGNAL(triggered()), this, SLOT(doTextureMenuAction()));
    connect(mExtendedTextureMenuAction, SIGNAL(triggered()), this, SLOT(doExtendedTextureMenuAction()));
    connect(mLayerAndSceneViewMenuAction, SIGNAL(triggered()), this, SLOT(doLayerAndSceneViewMenuAction()));
}

//****************************************************************************/
void MainWindow::createMenus(void)
{
    mToolsMenu = menuBar()->addMenu(QString("Tools"));
    mToolsMenu->addAction(mGradientMenuAction);
    mToolsMenu->addAction(mGlSphereMenuAction);
    mToolsMenu->addAction(mTextureMenuAction);
    mToolsMenu->addAction(mExtendedTextureMenuAction);
    mToolsMenu->addAction(mLayerAndSceneViewMenuAction);
}

//****************************************************************************/
void MainWindow::createToolBars(void)
{

}

//****************************************************************************/
void MainWindow::createStatusBar(void)
{

}

//****************************************************************************/
void MainWindow::createDockWindows(void)
{

}

//****************************************************************************/
void MainWindow::doGradientMenuAction(void)
{
    QDialog dialog(this);
    dialog.setWindowTitle(QString("Gradient"));
    dialog.setMinimumWidth(480);
    dialog.setMaximumWidth(480);
    dialog.setMinimumHeight(448);
    dialog.setMaximumHeight(448);
    QHBoxLayout mainLayout;
    Magus::QtGradientWidget* gradientWidget = new Magus::QtGradientWidget();
    mainLayout.addWidget(gradientWidget);
    gradientWidget->setGradientDimension(440, 0.1f);
    dialog.setLayout(&mainLayout);
    dialog.exec(); // Note: don't delete the gradientWidget, because it is deleted when the dialog is deleted
}

//****************************************************************************/
void MainWindow::doGlSphereMenuAction(void)
{
    QDialog dialog(this);
    dialog.setWindowTitle(QString("GL Sphere"));
    dialog.setMinimumWidth(436);
    dialog.setMinimumHeight(408);
    QHBoxLayout mainLayout;
    QPixmap texture = QPixmap(QString("../../assets/textures/BeachStones.jpg"));
    Magus::QtGLSphereWidget* glWidget = new Magus::QtGLSphereWidget(0, 0);
    glWidget->setPixmap(texture, QString("../../assets/textures/BeachStones.jpg"), QString("BeachStones.jpg"));
    mainLayout.addWidget(glWidget);
    dialog.setLayout(&mainLayout);
    dialog.exec();
}

//****************************************************************************/
void MainWindow::doTextureMenuAction(void)
{
    // This example shows a dialog with a texture widget (QtSimpleTextureWidget). The textures are read separately from the filesystem by means of a
    // filereader (QtFileReader) and added as pixmaps to the texture widget.
    setCursor(Qt::WaitCursor);

    // Create dialog with texture widget
    QDialog dialog(this);
    dialog.setWindowTitle(QString("Texture"));
    dialog.setMinimumWidth(432);
    dialog.setMinimumHeight(408);
    QHBoxLayout mainLayout;
    Magus::QtSimpleTextureWidget textureSelection;
    mTextureSelection = &textureSelection;
    textureSelection.setContentsMargins(-8, -8, -8, -8);
    textureSelection.setTextureSize(QSize(122, 122));
    connect(&textureSelection, SIGNAL(doubleClicked(QString)), this, SLOT(textureSelected(QString)));
    mainLayout.addWidget(&textureSelection);
    dialog.setLayout(&mainLayout);

    // Create filereader and read the images from the filesystem
    Magus::QtFileReader fileReader;
    connect(&fileReader, SIGNAL(textureRead(QPixmap, QString, QString)), this, SLOT(textureRead(QPixmap, QString, QString)));
    fileReader.readTexturesRecursively(QString("../../assets/textures"));

    setCursor(Qt::ArrowCursor);
    dialog.exec();
}

//****************************************************************************/
void MainWindow::doExtendedTextureMenuAction(void)
{
    // This example shows a dialog with a extended texture widget (QtTextureWidgetEx). The textures are read separately
    // from the filesystem by means of a filereader (QtFileReader) and added as pixmaps to the texture widget.
    setCursor(Qt::WaitCursor);

    // Create dialog with texture widget
    QDialog dialog(this);
    dialog.setWindowTitle(QString("Texture"));
    dialog.setMinimumWidth(432);
    dialog.setMinimumHeight(412);
    QHBoxLayout mainLayout;
    Magus::QtExtendedTextureWidget textureSelection;
    mTextureSelectionExt = &textureSelection;
    connect(&textureSelection, SIGNAL(doubleClicked(QString,QString)), this, SLOT(textureSelected(QString)));
    textureSelection.setContentsMargins(-8, -8, -8, -8);
    mainLayout.addWidget(&textureSelection);
    dialog.setLayout(&mainLayout);

    // Create filereader and read the images from the filesystem
    Magus::QtFileReader fileReader;
    connect(&fileReader, SIGNAL(textureRead(QPixmap, QString, QString)), this, SLOT(textureReadExt(QPixmap, QString, QString)));
    fileReader.readTexturesRecursively(QString("../../assets/textures"));

    setCursor(Qt::ArrowCursor);
    dialog.exec();
}
Beispiel #2
0
TexturesGallery::TexturesGallery( TexturesManager* texturesManager ) :
    texturesManager_( texturesManager )
{
    texturesManager_->Observable::addObserver( this );

    // We are displaying images (big icons)
    // http://stackoverflow.com/a/14114878/3917854
    setViewMode( QListWidget::IconMode );
    setIconSize( QSize( 200,200 ) );
    setResizeMode( QListWidget::Adjust );

    // Whenever the user double-click over a texture, emit a "textureSelected"
    // signal.
    QObject::connect( this, &TexturesGallery::itemDoubleClicked,
                      [this]( QListWidgetItem* listItem ){
        TexturesGalleryItem* textureItem =
                dynamic_cast< TexturesGalleryItem* >( listItem );

        emit textureSelected( textureItem->textureID() );
    });
}