Ejemplo n.º 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 <QHBoxLayout>
#include <QVBoxLayout>
#include <QMessageBox>
#include <QHeaderView>
#include <QEvent>
#include <QImage>
#include <QPixmap>
#include <QTreeWidgetItem>
#include "tool_sceneviewwidget.h"

namespace Magus
{
//****************************************************************************/
QtSceneViewWidget::QtSceneViewWidget(const QString& iconDir, QWidget* parent) : QWidget(parent)
{
    setWindowTitle(QString("Scene view"));
    mIconDir = iconDir;
    QVBoxLayout* mainLayout = new QVBoxLayout;
    mSearchLayout = new QHBoxLayout;
    mTreeLayout = new QVBoxLayout;

    // Create edit
    mSearchLine = new QLineEdit();
    connect(mSearchLine, SIGNAL(textChanged(QString)), this, SLOT(searchLineTextChanged(QString)));

    // Create findbutton
    QImage imageSearch(mIconDir + TOOL_SCENEVIEW_ICON_SEARCH);
    QPixmap pixMapSearch = QPixmap::fromImage(imageSearch).scaled(TOOL_SCENEVIEW_ICON_WIDTH, TOOL_SCENEVIEW_ICON_WIDTH);
    mSearchLabel = new QLabel();
    mSearchLabel->setPixmap(pixMapSearch);
    mSearchLabel->setContentsMargins(-8, -8, -8, -8);

    // Create clearbutton
    QImage imageClear(mIconDir + TOOL_SCENEVIEW_ICON_CLOSE);
    QPixmap pixMapClear = QPixmap::fromImage(imageClear).scaled(TOOL_SCENEVIEW_ICON_WIDTH, TOOL_SCENEVIEW_ICON_WIDTH);
    mSearchClearButton = new QPushButton();
    mSearchClearButton->setStyleSheet(QString("QPushButton {border: none; background: transparent;} QPushButton:hover {background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #565656, stop:1 #464646);}"));
    mSearchClearButton->setIcon(QIcon(pixMapClear));
    mSearchClearButton->setIconSize(QSize(TOOL_SCENEVIEW_ICON_WIDTH, TOOL_SCENEVIEW_ICON_WIDTH));
    mSearchClearButton->setContentsMargins(-8, -8, -8, -8);
    connect(mSearchClearButton, SIGNAL(clicked()), this, SLOT(clearSearchLine()));


    // Misc
    mVisibilityIconVisibleForGroups = true;
    mVisibilityIconVisibleForAssets = true;
    mDeletionIconVisibleForGroups = true;
    mDeletionIconVisibleForAssets = true;

    // Layout
    mSearchLayout->addWidget(mSearchLabel, 1);
    mSearchLayout->addWidget(mSearchLine, 2000);
    mSearchLayout->addWidget(mSearchClearButton, 1);
    setVisibilitySearchWidgets(false);
    mainLayout->addLayout(mSearchLayout, 1);
    mainLayout->addLayout(mTreeLayout, 2000);
    setLayout(mainLayout);
}

//****************************************************************************/
QtSceneViewWidget::~QtSceneViewWidget(void)
{
    // Delete all QtAssetGroups in mAssetGroupMap
    foreach (QtAssetGroup* group, mAssetGroupMap)
        delete group;

    mAssetGroupMap.clear();

}

//****************************************************************************/
bool QtSceneViewWidget::eventFilter(QObject* object, QEvent* event)
{
    QMouseEvent* mouseEvent = (QMouseEvent*) event;
    switch ((int) event->type())
    {
    case QEvent::MouseButtonPress:
        mouseClickHandler(mouseEvent);
        break;
    }
    return QObject::eventFilter(object, event);
}

//****************************************************************************/
void QtSceneViewWidget::mouseClickHandler(QMouseEvent* event)
{
    switch ((int) event->button())
    {
    case Qt::LeftButton:
    {
        // Get the selected item of the visible sceneview
        QTreeWidget* sceneView = getCurrentVisibleScene();
        if (sceneView)
        {
            QTreeWidgetItem* item = sceneView->itemAt(event->pos());
            int col = sceneView->columnAt(event->pos().x());
            if (itemIsGroup(item))
            {
                if (col == TOOL_SCENEVIEW_COLUMN_GROUP_CLOSE)
                {
                    handleDeletionOfGroup(sceneView, item);
                    return;
                }
                else if (col == TOOL_SCENEVIEW_COLUMN_GROUP_VISIBILITY)
                {
                    // Toggle visibility
                    toggleVisibilityOfGroup(item);
                }

                int groupId = getGroupIdOfGroupItem(item);
                emit groupSelected(sceneView, groupId);
            }
            else if (itemIsAsset(item))
            {
                if (col == TOOL_SCENEVIEW_COLUMN_ASSET_CLOSE)
                {
                    handleDeletionOfAsset(sceneView, item);
                    return;
                }
                else if (col == TOOL_SCENEVIEW_COLUMN_ASSET_VISIBILITY)
                {
                    // Toggle visibility
                    toggleVisibilityOfAsset(item);
                }

                int groupId = getGroupIdOfAssetItem(item);
                int assetId = getAssetIdOfAssetItem(item);
                emit assetSelected(sceneView, groupId, assetId);
            }
        }
    }
    break;

    case Qt::RightButton:
    {
        // TODO
    }
    break;
    }
}
Ejemplo n.º 2
0
void MainWindow::showSurfacesMenu(const QPoint &pos)
{
    QTreeWidget *tree = m_ui.surfacesTreeWidget;
    QTreeWidgetItem *item = tree->itemAt(pos);
    if (!item) {
        return;
    }

    QMenu menu(tr("Surfaces"), this);

    QAction *act = menu.addAction(tr("View Image"));
    act->setStatusTip(tr("View the currently selected surface"));
    connect(act, SIGNAL(triggered()),
            SLOT(showSelectedSurface()));

    act = menu.addAction(tr("Save Image"));
    act->setStatusTip(tr("Save the currently selected surface"));
    connect(act, SIGNAL(triggered()),
            SLOT(saveSelectedSurface()));

    menu.exec(tree->viewport()->mapToGlobal(pos));
}