diff --git a/glabels/CMakeLists.txt b/glabels/CMakeLists.txt index 929902c..871d8ec 100644 --- a/glabels/CMakeLists.txt +++ b/glabels/CMakeLists.txt @@ -15,6 +15,7 @@ set (glabels_sources ColorPaletteDialog.cpp ColorPaletteItem.cpp ColorSwatch.cpp + Cursors.cpp FieldButton.cpp FieldMenu.cpp FieldMenuItem.cpp @@ -67,13 +68,14 @@ set (glabels_forms ) set (glabels_resource_files + cursors.qrc icons.qrc images.qrc ) qt4_wrap_cpp (glabels_moc_sources ${glabels_qobject_headers}) qt4_wrap_ui (glabels_forms_headers ${glabels_forms}) -qt4_add_resources(glabels_qrc_sources ${glabels_resource_files}) +qt4_add_resources (glabels_qrc_sources ${glabels_resource_files}) include (${QT_USE_FILE}) diff --git a/glabels/Cursors.cpp b/glabels/Cursors.cpp new file mode 100644 index 0000000..923adfb --- /dev/null +++ b/glabels/Cursors.cpp @@ -0,0 +1,60 @@ +/* Cursors.cpp + * + * Copyright (C) 2013 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels-qt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels-qt. If not, see . + */ + +#include "Cursors.h" + + +#include + + +glabels::Cursors::Barcode::Barcode() + : QCursor( QPixmap(":cursors/32x32/cursor_barcode.png"), 7, 7 ) +{ +} + + +glabels::Cursors::Box::Box() + : QCursor( QPixmap(":cursors/32x32/cursor_box.png"), 7, 7 ) +{ +} + + +glabels::Cursors::Ellipse::Ellipse() + : QCursor( QPixmap(":cursors/32x32/cursor_ellipse.png"), 7, 7 ) +{ +} + + +glabels::Cursors::Image::Image() + : QCursor( QPixmap(":cursors/32x32/cursor_image.png"), 7, 7 ) +{ +} + + +glabels::Cursors::Line::Line() + : QCursor( QPixmap(":cursors/32x32/cursor_line.png"), 7, 7 ) +{ +} + + +glabels::Cursors::Text::Text() + : QCursor( QPixmap(":cursors/32x32/cursor_text.png"), 7, 7 ) +{ +} diff --git a/glabels/Cursors.h b/glabels/Cursors.h new file mode 100644 index 0000000..d3491dc --- /dev/null +++ b/glabels/Cursors.h @@ -0,0 +1,83 @@ +/* Cursors.h + * + * Copyright (C) 2013 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels-qt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels-qt. If not, see . + */ + +#ifndef glabels_Cursors_h +#define glabels_Cursors_h + + +#include + + +namespace glabels +{ + + /// + /// Glabels Cursors + /// + namespace Cursors + { + + + class Barcode : public QCursor + { + public: + Barcode(); + }; + + + class Box : public QCursor + { + public: + Box(); + }; + + + class Ellipse : public QCursor + { + public: + Ellipse(); + }; + + + class Image : public QCursor + { + public: + Image(); + }; + + + class Line : public QCursor + { + public: + Line(); + }; + + + class Text : public QCursor + { + public: + Text(); + }; + + + } +} + +#endif // glabels_Cursors_h diff --git a/glabels/LabelModelObject.cpp b/glabels/LabelModelObject.cpp index 7afab10..b71a054 100644 --- a/glabels/LabelModelObject.cpp +++ b/glabels/LabelModelObject.cpp @@ -57,7 +57,7 @@ namespace glabels mShadowState = false; mShadowX = 1.3; mShadowY = 1.3; - mShadowColorNode = ColorNode( QColor::fromRgb(0x000000) ); + mShadowColorNode = ColorNode( QColor( 0, 0, 0 ) ); mShadowOpacity = 0.5; mSelectedFlag = false; @@ -768,6 +768,8 @@ namespace glabels { mW = w; mH = h; + + emit changed(); } diff --git a/glabels/LabelModelShapeObject.cpp b/glabels/LabelModelShapeObject.cpp index 62e3bed..00ebf71 100644 --- a/glabels/LabelModelShapeObject.cpp +++ b/glabels/LabelModelShapeObject.cpp @@ -43,7 +43,9 @@ namespace glabels mHandles << new HandleSouthWest( this ); mHandles << new HandleWest( this ); - /* TODO: initialize default line and fill poperties. */ + mLineWidth = 1.0; + mLineColorNode = ColorNode( QColor( 0, 0, 0 ) ); + mFillColorNode = ColorNode( QColor( 0, 255, 0 ) ); } diff --git a/glabels/MainWindow.cpp b/glabels/MainWindow.cpp index 084d9de..34a01bf 100644 --- a/glabels/MainWindow.cpp +++ b/glabels/MainWindow.cpp @@ -1021,7 +1021,7 @@ namespace glabels /// void MainWindow::objectsArrowMode() { - qDebug() << "ACTION: objects->Select Mode"; + mView->arrowMode(); } @@ -1039,7 +1039,7 @@ namespace glabels /// void MainWindow::objectsCreateBox() { - qDebug() << "ACTION: objects->Create->Box"; + mView->createBoxMode(); } diff --git a/glabels/View.cpp b/glabels/View.cpp index 2ee5439..fa9b077 100644 --- a/glabels/View.cpp +++ b/glabels/View.cpp @@ -27,6 +27,8 @@ #include "LabelModel.h" #include "LabelModelObject.h" +#include "LabelModelBoxObject.h" +#include "Cursors.h" #include "libglabels/Markup.h" #include "libglabels/FrameRect.h" @@ -130,9 +132,9 @@ glabels::View::setModel( LabelModel* model ) { setZoomReal( 1, false ); - connect( model, SIGNAL(changed()), this, SLOT(onModelChanged()) ); - connect( model, SIGNAL(selectionChanged()), this, SLOT(onModelSelectionChanged()) ); - connect( model, SIGNAL(sizeChanged()), this, SLOT(onModelSizeChanged()) ); + connect( model, SIGNAL(changed()), this, SLOT(update()) ); + connect( model, SIGNAL(selectionChanged()), this, SLOT(update()) ); + connect( model, SIGNAL(sizeChanged()), this, SLOT(update()) ); update(); } @@ -286,6 +288,33 @@ glabels::View::setZoomReal( double zoom, bool zoomToFitFlag ) } +/// +/// Arrow mode (normal mode) +/// +void +glabels::View::arrowMode() +{ + setCursor( Qt::ArrowCursor ); + + mInObjectCreateMode = false; + mState = IdleState; +} + + +/// +/// Create box mode +/// +void +glabels::View::createBoxMode() +{ + setCursor( Cursors::Box() ); + + mInObjectCreateMode = true; + mCreateObjectType = Box; + mState = IdleState; +} + + /// /// Resize Event Handler /// @@ -310,118 +339,6 @@ glabels::View::resizeEvent( QResizeEvent *event ) } -/// -/// Mouse Movement Event Handler -/// -void -glabels::View::mouseMoveEvent( QMouseEvent* event ) -{ - if ( mModel ) - { - /* - * Transform to label coordinates - */ - QTransform transform; - - transform.scale( mScale, mScale ); - transform.translate( mX0, mY0 ); - - QPointF pWorld = transform.inverted().map( event->posF() ); - double xWorld = pWorld.x(); - double yWorld = pWorld.y(); - - - /* - * Emit signal regardless of mode - */ - emit pointerMoved( xWorld, yWorld ); - - - /* - * Handle event as appropriate for mode - */ - if ( !mInObjectCreateMode ) - { - switch (mState) - { - - case IdleState: - if ( mModel->isSelectionAtomic() && - mModel->handleAt( mScale, xWorld, yWorld ) ) - { - setCursor( Qt::CrossCursor ); - } - else if ( mModel->objectAt( mScale, xWorld, yWorld ) ) - { - setCursor( Qt::SizeAllCursor ); - } - else - { - setCursor( Qt::ArrowCursor ); - } - break; - - case ArrowSelectRegion: - mSelectRegion.setX2( xWorld ); - mSelectRegion.setY2( yWorld ); - update(); - break; - - case ArrowMove: - mModel->moveSelection( (xWorld - mMoveLastX), - (yWorld - mMoveLastY) ); - mMoveLastX = xWorld; - mMoveLastY = yWorld; - update(); - break; - - case ArrowResize: - handleResizeMotion( xWorld, yWorld ); - update(); - break; - - default: - // Should not happen! - qWarning() << "Invalid arrow state."; - break; - - } - } - else - { - if ( mState != IdleState ) - { - switch (mCreateObjectType) - { - case Box: - // @TODO - break; - case Ellipse: - // @TODO - break; - case Line: - // @TODO - break; - case Image: - // @TODO - break; - case Text: - // @TODO - break; - case Barcode: - // @TODO - break; - default: - // Should not happen! - qWarning() << "Invalid create type."; - break; - } - } - } - } -} - - /// /// Mouse Button Press Event Handler /// @@ -451,6 +368,10 @@ glabels::View::mousePressEvent( QMouseEvent* event ) if ( !mInObjectCreateMode ) { + // + // NORMAL MODE + // + LabelModelObject* object = 0; Handle* handle = 0; if ( mModel->isSelectionAtomic() && @@ -497,7 +418,6 @@ glabels::View::mousePressEvent( QMouseEvent* event ) mMoveLastY = yWorld; mState = ArrowMove; - update(); } else { @@ -519,6 +439,53 @@ glabels::View::mousePressEvent( QMouseEvent* event ) update(); } } + else + { + // + // OBJECT CREATION MODE + // + + if ( mState == IdleState ) + { + switch ( mCreateObjectType ) + { + case Box: + mCreateObject = new LabelModelBoxObject(); + break; + case Ellipse: + // mCreateObject = new LabelModelEllipseObject(); + break; + case Line: + // mCreateObject = new LabelModelLineObject(); + break; + case Image: + // mCreateObject = new LabelModelImageObject(); + break; + case Text: + // mCreateObject = new LabelModelTextObject(); + break; + case Barcode: + // mCreateObject = new LabelModelBarcodeObject(); + break; + default: + Q_ASSERT_X( false, "View::::mousePressEvent", "Invalid creation type" ); + break; + } + + mCreateObject->setPosition( xWorld, yWorld ); + mCreateObject->setSize( 0, 0 ); + mModel->addObject( mCreateObject ); + + mModel->unselectAll(); + mModel->selectObject( mCreateObject ); + + mCreateX0 = xWorld; + mCreateY0 = yWorld; + + mState = CreateDrag; + } + + } } else if ( event->button() & Qt::RightButton ) @@ -532,6 +499,123 @@ glabels::View::mousePressEvent( QMouseEvent* event ) } +/// +/// Mouse Movement Event Handler +/// +void +glabels::View::mouseMoveEvent( QMouseEvent* event ) +{ + using std::min; + using std::max; + + if ( mModel ) + { + /* + * Transform to label coordinates + */ + QTransform transform; + + transform.scale( mScale, mScale ); + transform.translate( mX0, mY0 ); + + QPointF pWorld = transform.inverted().map( event->posF() ); + double xWorld = pWorld.x(); + double yWorld = pWorld.y(); + + + /* + * Emit signal regardless of mode + */ + emit pointerMoved( xWorld, yWorld ); + + + /* + * Handle event as appropriate for mode + */ + if ( !mInObjectCreateMode ) + { + /// + /// NORMAL MODE + /// + + switch (mState) + { + + case IdleState: + if ( mModel->isSelectionAtomic() && + mModel->handleAt( mScale, xWorld, yWorld ) ) + { + setCursor( Qt::CrossCursor ); + } + else if ( mModel->objectAt( mScale, xWorld, yWorld ) ) + { + setCursor( Qt::SizeAllCursor ); + } + else + { + setCursor( Qt::ArrowCursor ); + } + break; + + case ArrowSelectRegion: + mSelectRegion.setX2( xWorld ); + mSelectRegion.setY2( yWorld ); + update(); + break; + + case ArrowMove: + mModel->moveSelection( (xWorld - mMoveLastX), + (yWorld - mMoveLastY) ); + mMoveLastX = xWorld; + mMoveLastY = yWorld; + break; + + case ArrowResize: + handleResizeMotion( xWorld, yWorld ); + break; + + default: + // Should not happen! + Q_ASSERT_X( false, "View::::mouseMoveEvent", "Invalid state" ); + break; + + } + } + else + { + // + // OBJECT CREATION MODE + // + + if ( mState != IdleState ) + { + switch (mCreateObjectType) + { + case Box: + case Ellipse: + case Image: + case Text: + case Barcode: + mCreateObject->setPosition( min( xWorld, mCreateX0 ), + min( yWorld, mCreateY0 ) ); + mCreateObject->setSize( max(xWorld,mCreateX0) - min(xWorld,mCreateX0), + max(yWorld,mCreateY0) - min(yWorld,mCreateY0) ); + + break; + case Line: + mCreateObject->setSize( xWorld - mCreateX0, yWorld - mCreateY0 ); + break; + default: + // Should not happen! + Q_ASSERT_X( false, "View::::mouseMoveEvent", "Invalid creation mode" ); + break; + } + } + } + } +} + + /// /// Mouse Button Release Event Handler /// @@ -561,6 +645,9 @@ glabels::View::mouseReleaseEvent( QMouseEvent* event ) if ( !mInObjectCreateMode ) { + /// + /// NORMAL MODE + /// switch (mState) { @@ -582,7 +669,6 @@ glabels::View::mouseReleaseEvent( QMouseEvent* event ) default: mState = IdleState; - update(); break; } @@ -590,7 +676,27 @@ glabels::View::mouseReleaseEvent( QMouseEvent* event ) } else { + // + // OBJECT CREATION MODE + // + + if ( (fabs(mCreateObject->w()) < 4) && (fabs(mCreateObject->h()) < 4) ) + { + switch (mCreateObjectType) + { + case Text: + mCreateObject->setSize( 0, 0 ); + break; + case Line: + mCreateObject->setSize( 72, 0 ); + break; + default: + mCreateObject->setSize( 72, 72 ); + break; + } + } + arrowMode(); } } } diff --git a/glabels/View.h b/glabels/View.h index 4c54815..0676fcd 100644 --- a/glabels/View.h +++ b/glabels/View.h @@ -116,8 +116,8 @@ namespace glabels ///////////////////////////////////// protected: void resizeEvent( QResizeEvent* event ); - void mouseMoveEvent( QMouseEvent* event ); void mousePressEvent( QMouseEvent* event ); + void mouseMoveEvent( QMouseEvent* event ); void mouseReleaseEvent( QMouseEvent* event ); void leaveEvent( QEvent* event ); void paintEvent( QPaintEvent* event ); diff --git a/glabels/cursors.qrc b/glabels/cursors.qrc new file mode 100644 index 0000000..a940cac --- /dev/null +++ b/glabels/cursors.qrc @@ -0,0 +1,12 @@ + + + + + cursors/32x32/cursor_barcode.png + cursors/32x32/cursor_box.png + cursors/32x32/cursor_ellipse.png + cursors/32x32/cursor_image.png + cursors/32x32/cursor_line.png + cursors/32x32/cursor_text.png + + diff --git a/glabels/cursors/32x32/cursor_barcode.png b/glabels/cursors/32x32/cursor_barcode.png new file mode 100644 index 0000000..59ba928 Binary files /dev/null and b/glabels/cursors/32x32/cursor_barcode.png differ diff --git a/glabels/cursors/32x32/cursor_box.png b/glabels/cursors/32x32/cursor_box.png new file mode 100644 index 0000000..c30c0d4 Binary files /dev/null and b/glabels/cursors/32x32/cursor_box.png differ diff --git a/glabels/cursors/32x32/cursor_ellipse.png b/glabels/cursors/32x32/cursor_ellipse.png new file mode 100644 index 0000000..40924af Binary files /dev/null and b/glabels/cursors/32x32/cursor_ellipse.png differ diff --git a/glabels/cursors/32x32/cursor_image.png b/glabels/cursors/32x32/cursor_image.png new file mode 100644 index 0000000..e5b4781 Binary files /dev/null and b/glabels/cursors/32x32/cursor_image.png differ diff --git a/glabels/cursors/32x32/cursor_line.png b/glabels/cursors/32x32/cursor_line.png new file mode 100644 index 0000000..31d8c6e Binary files /dev/null and b/glabels/cursors/32x32/cursor_line.png differ diff --git a/glabels/cursors/32x32/cursor_text.png b/glabels/cursors/32x32/cursor_text.png new file mode 100644 index 0000000..cda6b21 Binary files /dev/null and b/glabels/cursors/32x32/cursor_text.png differ