コード例 #1
0
/****************************************************************************
**
** Copyright (C) 2016
**
** 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 <QFileInfo>
#include <QMenuBar>
#include <QFileDialog>
#include <QVBoxLayout>
#include <QHeaderView>
#include <QMessageBox>
#include <QProcess>
#include <QActionGroup>
#include "mainwindow.h"


//****************************************************************************/
MainWindow::MainWindow(void) : mIsClosing(false)
{
    mOutputFolder = "";
    mPostfix = "";
    mParameters = MODERN_DESKTOP_WITH_NMAP_OPTIONS;
    mRunNumber = 1;

    // Perform standard functions
    createActions();
    createMenus();

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

    // Set the table
    mTable = new QTableWidget();
    mTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    mTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    mTable->setSelectionMode(QAbstractItemView::NoSelection);
    mTable->verticalHeader()->setVisible(false);
    mTable->setColumnCount(2);
    mTable->setColumnWidth(0, 704);
    mTable->setColumnWidth(1, 128);
    mTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
    doClearMenuAction();
    setCentralWidget(mTable);

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

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

}

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

//****************************************************************************/
void MainWindow::createActions(void)
{
    // File
    mImportMenuAction = new QAction(QString("Import"), this);
    connect(mImportMenuAction, SIGNAL(triggered()), this, SLOT(doImportMenuAction()));

    mSetOutputDirMenuAction = new QAction(QString("Set output directory"), this);
    connect(mSetOutputDirMenuAction, SIGNAL(triggered()), this, SLOT(doSetOutputDirMenuAction()));

    mConvertMenuAction = new QAction(QString("Convert"), this);
    connect(mConvertMenuAction, SIGNAL(triggered()), this, SLOT(doConvertMenuAction()));

    mClearMenuAction = new QAction(QString("Clear file list"), this);
    connect(mClearMenuAction, SIGNAL(triggered()), this, SLOT(doClearMenuAction()));

    mQuitMenuAction = new QAction(QString("Quit"), this);
    connect(mQuitMenuAction, SIGNAL(triggered()), this, SLOT(doQuitMenuAction()));

    // Options
    mPostFixMenuAction = new QAction(QString("Apply postfix " + POSTFIX), this);
    mPostFixMenuAction->setCheckable(true);
    connect(mPostFixMenuAction, SIGNAL(triggered()), this, SLOT(doPostFixMenuAction()));

    mOptionsModernDesktopWithNmapMenuAction = new QAction(QString("Modern desktop with normal mapping"), this);
    mOptionsModernDesktopWithNmapMenuAction->setCheckable(true);
    mOptionsModernDesktopWithNmapMenuAction->setChecked(true);
    connect(mOptionsModernDesktopWithNmapMenuAction, SIGNAL(triggered()), this, SLOT(doOptionsModernDesktopWithNmapMenuAction()));

    mOptionsModernDesktopWithoutNmapMenuAction = new QAction(QString("Modern desktop without normal mapping"), this);
    mOptionsModernDesktopWithoutNmapMenuAction->setCheckable(true);
    connect(mOptionsModernDesktopWithoutNmapMenuAction, SIGNAL(triggered()), this, SLOT(doOptionsModernDesktopWithoutNmapMenuAction()));

    mOptionsGles2WithNmapMenuAction = new QAction(QString("GLES2 with normal mapping"), this);
    mOptionsGles2WithNmapMenuAction->setCheckable(true);
    connect(mOptionsGles2WithNmapMenuAction, SIGNAL(triggered()), this, SLOT(doOptionsGles2WithNmapMenuAction()));

    mOptionsGles2WithoutNmapMenuAction = new QAction(QString("GLES2 without normal mapping"), this);
    mOptionsGles2WithoutNmapMenuAction->setCheckable(true);
    connect(mOptionsGles2WithoutNmapMenuAction, SIGNAL(triggered()), this, SLOT(doOptionsGles2WithoutNmapMenuAction()));
}

//****************************************************************************/
void MainWindow::createMenus(void)
{
    mFileMenu = menuBar()->addMenu(QString("File"));
    mOptionsMenu = menuBar()->addMenu(QString("Options"));

    // File
    mFileMenu->addAction(mImportMenuAction);
    mFileMenu->addAction(mSetOutputDirMenuAction);
    mFileMenu->addAction(mConvertMenuAction);
    mFileMenu->addAction(mClearMenuAction);
    mFileMenu->addAction(mQuitMenuAction);

    // Options
    mOptionsMenu->addAction(mPostFixMenuAction);
    QMenu* subMenu = mOptionsMenu->addMenu(QString("Conversion parameters"));
    QActionGroup actionGroup(subMenu);
    actionGroup.setExclusive(true);
    actionGroup.addAction(mOptionsModernDesktopWithNmapMenuAction);
    actionGroup.addAction(mOptionsModernDesktopWithoutNmapMenuAction);
    actionGroup.addAction(mOptionsGles2WithNmapMenuAction);
    actionGroup.addAction(mOptionsGles2WithoutNmapMenuAction);
    subMenu->addActions(actionGroup.actions());
}
コード例 #2
0
ファイル: qt_menu.cpp プロジェクト: wgsyd/wgtf
QSharedPointer<QAction> QtMenu::createSharedQAction(IAction& action)
{
	auto qAction = getSharedQAction(action);
	if (qAction)
	{
		return qAction;
	}

	qAction.reset(new QForwardingAction(action.text(), QApplication::instance()), &QObject::deleteLater);
	sharedQActions_[&action] = qAction;

	qAction->setProperty("order", action.order());
	qAction->setEnabled(action.enabled());
	qAction->setVisible(action.visible());

	if (action.isSeparator())
	{
		qAction->setSeparator(true);
	}
	else
	{
		std::vector<QIcon> qIcons;
		auto icons = StringUtils::split(std::string(action.icon()), '|');
		for(auto& icon : icons)
		{			
			StringUtils::trim_string(icon);
			qIcons.push_back(QtMenu_Locals::generateIcon(icon.c_str()));
		}

		if(!qIcons.empty())
		{
			qAction->setIcon(qIcons[0]);
		}

		qAction->setShortcut(QKeySequence(action.shortcut()));

		if (action.isCheckable())
		{
			qAction->setCheckable(true);
			qAction->setChecked(action.checked());
		}

		QObject::connect(qAction.data(), &QAction::triggered, [&action]() {
			if (!action.enabled())
			{
				return;
			}
			action.execute();
		});

		connections_[&action] = action.signalShortcutChanged.connect([qAction](const char* shortcut) {
			TF_ASSERT(qAction != nullptr);
			qAction->setShortcut(QKeySequence(shortcut));
		});

		connections_[&action] = action.signalTextChanged.connect([qAction](const char* text) {
			TF_ASSERT(qAction != nullptr);
			qAction->setText(text);
		});

		connections_[&action] = action.signalVisibilityChanged.connect([qAction](bool visible) {
			TF_ASSERT(qAction != nullptr);
			qAction->setVisible(visible);
		});

		connections_[&action] = action.signalIconChanged.connect([qAction, qIcons](int index) {
			TF_ASSERT(qAction != nullptr);
			if(index >= 0 && index < (int)qIcons.size())
			{
				qAction->setIcon(qIcons[index]);
			}
		});

		const std::string groupID(action.group());
		if (!groupID.empty())
		{
			auto itr = groups_.find(groupID);
			if (itr == groups_.end())
			{
				groups_[groupID].reset(new QActionGroup(&menu_));
			}

			groups_.at(groupID)->addAction(qAction.data());
			TF_ASSERT(qAction->actionGroup());
		}
	}

	return qAction;
}
コード例 #3
0
ファイル: status_manager.cpp プロジェクト: manhere/booxsdk
void StatusActionGroup::addAction(StatusActionPtr & action)
{
    action->setCheckable(true);
    action->setActionGroup(actionGroup());
    actions_.push_back(action);
}