Ejemplo n.º 1
0
void PaintWidget::selectFigure( int layer, int obj)
{
	if( painter.inKeyPressedHandler ) return;

	GObjectInterface *o = painter.layers[layer]->object( obj );

	if(layer != painter.currentLayer)
	{
		painter.currentLayer = layer;
		painter.setFrame( painter.currentFrame, false );
		emit layerSelected();
	}

	if( o == 0 )
	{
		painter.selection.reset();
		emit figureSelected( layer, -1 );
		return;
	}


	if( !o->isVisible() || o->isBlocked())
	{
		painter.selection.reset();
		painter.update();
		return;
	}

	painter.selection.setSelected( o );
	painter.update();
	emit figureSelected( layer, obj );
}
Ejemplo n.º 2
0
void LayerList::selectionChanged(const QItemSelection &selected)
{
	bool on = selected.count() > 0;

	if(on) {
		QModelIndex cs = currentSelection();
		dataChanged(cs,cs);
		_selected = cs.data().value<net::LayerListItem>().id;
	} else {
		_selected = 0;
	}

	updateLockedControls();

	emit layerSelected(_selected);
}
Ejemplo n.º 3
0
/****************************************************************************
**
** Copyright (C) 2016 - 2017
**
** 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 <QApplication>
#include <QDesktopWidget>
#include <QRect>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMessageBox>
#include <QHeaderView>
#include <QEvent>
#include <QPixmap>
#include <QImage>
#include <QMimeData>
#include <QTableWidgetItem>
#include <QTreeWidgetItem>
#include <QVector2D>
#include "constants.h"
#include "paintlayer_widget.h"
#include "paintlayer_dockwidget.h"
#include "paintlayer_dialog.h"

//****************************************************************************/
PaintLayerWidget::PaintLayerWidget(const QString& iconDir, PaintLayerDockWidget* paintLayerDockWidget, QWidget* parent) :
    QWidget(parent),
    mPaintLayerDockWidget(paintLayerDockWidget)
{
    setWindowTitle(QString("Layers"));
    QHBoxLayout* mainLayout = new QHBoxLayout;
    QVBoxLayout* tableLayout = new QVBoxLayout;
    mIconDir = iconDir;
    mLayerIdCounter = 1;
    mListenToSceneId = 0;
    mListenToDeleteEvents = true;
    helperIntVector.clear();

    // Create table
    mTable = new QTableWidget(0, 4, this);
    mTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    mTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    mTable->setAcceptDrops(false);
    mTable->setShowGrid(false);
    mTable->viewport()->installEventFilter(this);
    QRect rect = QApplication::desktop()->screenGeometry();
    mTable->setColumnWidth(TOOL_LAYER_COLUMN_ICON, 2 * TOOL_LAYER_ICON_WIDTH);
    mTable->setColumnWidth(TOOL_LAYER_COLUMN_NAME, TOOL_LAYER_NAME_WIDTH);
    mTable->setColumnWidth(TOOL_LAYER_COLUMN_VISIBILITY, 2 * TOOL_LAYER_ICON_WIDTH);
    mTable->setColumnWidth(TOOL_LAYER_COLUMN_FILLER, rect.width());
    mTable->setSelectionBehavior(QAbstractItemView::SelectRows);
    setStyleSheet("QLineEdit{padding: 0 0px; margin-left: 0px; margin-right: 0px; max-height: 28px; height: 28px;}");
    connect(mTable, SIGNAL(clicked(QModelIndex)), this, SLOT(tableClicked(QModelIndex)));
    connect(mTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(handleTableDoubleClicked(QModelIndex)));

    // Set headers
    QStringList headers;
    headers << tr("Edit") << tr("Layer name") << tr("Visibility") << tr("");
    mTable->setHorizontalHeaderLabels(headers);
    QFont font;
    font.setBold(true);
    mTable->horizontalHeader()->setFont(font);
    mTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);

    // Contextmenu
    setContextMenuPolicy(Qt::CustomContextMenu);
    mContextMenu = new QMenu(mTable);
    mContextMenu->addAction(new QAction(TOOL_LAYER_ACTION_CREATE_LAYER, mTable));
    mContextMenu->addAction(new QAction(TOOL_LAYER_ACTION_EDIT_LAYER, mTable));
    mContextMenu->addAction(new QAction(TOOL_LAYER_ACTION_DELETE_LAYER, mTable));
    mContextMenu->addAction(new QAction(TOOL_LAYER_ACTION_RENAME_LAYER, mTable));
    mContextMenu->addAction(new QAction(TOOL_LAYER_ACTION_ALL_VISIBLE, mTable));
    //mContextMenu->addAction(new QAction(QString("TEST"), mTable));
    connect(mContextMenu, SIGNAL(triggered(QAction*)), this, SLOT(contextMenuItemSelected(QAction*)));

    // Layout
    tableLayout->addWidget(mTable);
    mainLayout->addLayout(tableLayout);
    setLayout(mainLayout);
}

//****************************************************************************/
PaintLayerWidget::~PaintLayerWidget(void)
{
    QVector<QtLayer*>::iterator it;
    for (it = mLayerVec.begin(); it != mLayerVec.end(); ++it)
        delete *it;

    mLayerVec.clear(); // The table is automatically deleted when this widget is deleted
}

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

        case QEvent::MouseButtonDblClick:
            mouseDblClickHandler(mouseEvent);
        break;

        break;
    }
    return QObject::eventFilter(object, event);
}

//****************************************************************************/
void PaintLayerWidget::tableClicked(QModelIndex index)
{
    // Toggle visibility
    int row = index.row();
    int col = index.column();
    QtLayer* layer = mLayerVec.at(row);
    if (col == TOOL_LAYER_COLUMN_VISIBILITY)
    {
        if (layer->visible)
            updateVisibilityIcon(row, false);
        else
            updateVisibilityIcon(row, true);
    }

    // Signal that layer is selected
    emit layerSelected(layer->layerId, layer->name);
}
Ejemplo n.º 4
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 <QPixmap>
#include <QImage>
#include <QMimeData>
#include <QTableWidgetItem>
#include <QTreeWidgetItem>
#include "tool_layerwidget.h"

namespace Magus
{
    //****************************************************************************/
    QtLayerWidget::QtLayerWidget(const QString& iconDir, QtSceneViewWidget* sceneViewWidget, QWidget* parent) : QWidget(parent)
    {
        setWindowTitle(QString("Layers"));
        QHBoxLayout* mainLayout = new QHBoxLayout;
        QVBoxLayout* tableLayout = new QVBoxLayout;
        mIconDir = iconDir;
        mLayerIdCounter = 1;
        mSceneViewWidget = sceneViewWidget;
        mListenToSceneViewWidget = 0;
        mListenToSceneId = 0;
        mListenToDropEvents = true;
        mListenToDeleteEvents = true;

        // Create table
        mTable = new QTableWidget(0, 3, this);
        mTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        mTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
        mTable->setAcceptDrops(true);
        mTable->setShowGrid(false);
        mTable->viewport()->installEventFilter(this);
        mTable->setColumnWidth(TOOL_LAYER_COLUMN_ICON, 2 * TOOL_LAYER_ICON_WIDTH);
        mTable->setColumnWidth(TOOL_LAYER_COLUMN_NAME, TOOL_LAYER_NAME_WIDTH);
        mTable->setColumnWidth(TOOL_LAYER_COLUMN_VISIBILITY, 2 * TOOL_LAYER_ICON_WIDTH);
        mTable->setSelectionBehavior(QAbstractItemView::SelectRows);
        setStyleSheet("QLineEdit{padding: 0 0px; margin-left: 0px; margin-right: 0px; max-height: 28px; height: 28px;}");
        connect(mTable, SIGNAL(clicked(QModelIndex)), this, SLOT(tableClicked(QModelIndex)));

        // Set headers
        QStringList headers;
        headers << tr("Layer") << tr("") << tr("Visibility");
        mTable->setHorizontalHeaderLabels(headers);
        QFont font;
        font.setBold(true);
        mTable->horizontalHeader()->setFont(font);

        // Contextmenu
        setContextMenuPolicy(Qt::CustomContextMenu);
        mContextMenu = new QMenu(mTable);
        mContextMenu->addAction(new QAction(TOOL_LAYER_ACTION_CREATE_LAYER, mTable));
        mContextMenu->addAction(new QAction(TOOL_LAYER_ACTION_DELETE_LAYER, mTable));
        mContextMenu->addAction(new QAction(TOOL_LAYER_ACTION_RENAME_LAYER, mTable));
        mContextMenu->addAction(new QAction(TOOL_LAYER_ACTION_ALL_VISIBLE, mTable));
        //mContextMenu->addAction(new QAction(QString("TEST"), mTable));
        connect(mContextMenu, SIGNAL(triggered(QAction*)), this, SLOT(contextMenuItemSelected(QAction*)));

        // Layout
        tableLayout->addWidget(mTable);
        mainLayout->addLayout(tableLayout);
        setLayout(mainLayout);
    }

    //****************************************************************************/
    QtLayerWidget::~QtLayerWidget(void)
    {
        QVector<QtLayer*>::iterator it;
        for (it = mLayerVec.begin(); it != mLayerVec.end(); ++it)
            delete *it;

        mLayerVec.clear(); // The table is automatically deleted when this widget is deleted
    }

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

            case QEvent::MouseButtonDblClick:
                mouseDblClickHandler(mouseEvent);
            break;

            case QEvent::Drop:
                dropHandler(object, event);
            break;
        }
        return QObject::eventFilter(object, event);
    }

    //****************************************************************************/
    void QtLayerWidget::tableClicked(QModelIndex index)
    {
        // Toggle visibility
        int row = index.row();
        int col = index.column();
        QtLayer* layer = mLayerVec.at(row);
        if (col == TOOL_LAYER_COLUMN_VISIBILITY)
        {
            if (layer->visible == true)
                updateVisibilityIcon(row, false);
            else
                updateVisibilityIcon(row, true);
        }

        // Set associated sceneview to visible (if mSceneView available)
        if (mSceneViewWidget)
            mSceneViewWidget->setSceneViewVisible(layer->layerId);

        // Signal that layer is selected
        emit layerSelected(layer->layerId, layer->name);
}