1 #include "TestEllipse.h"
//#include <QtTest/QtTest>
/*
TestEllipse::TestEllipse( )
{
}
QRectF TestEllipse::boundingRect( ) const
{
}
void TestEllipse::paint( )
{
}
void TestEllipse::mouseMoveEvent( )
{
}
void TestEllipse::mousePressEvent( )
{
}
void TestEllipse::mouseReleaseEvent( )
{
}
void TestEllipse::getID( )
{
}
*/
1 //#include <QtTest/QtTest>
#include "TestIcon.h"
#include "icon.h"
6 TestIcon::TestIcon( )
{
}
13 void TestIcon::setPos( )
{
/* icon *test = new icon( );
test->setPos( 150, 300 );
QVERIFY( test->getXPos( )==150 );
QVERIFY( test->getYPos( )==300 );
*/
}
24 void TestIcon::setSize( )
{
/* icon *test = new icon( );
test->setSize( 2, 3 );
QVERIFY( test->getXSize( )== 2 );
QVERIFY( test->getYSize( )== 3 );
*/
}
35 void TestIcon::setShapetype( )
{
/* icon *test = new icon( );
test->setShapetype( "testIcon" );
QVERIFY( test->reportShapetype( )=="testIcon" );
*/
}
1 /****************************************************************************
**
** Copyright ( C ) 2011 Nokia Corporation and/or its subsidiary( -ies ).
** All rights reserved.
** Contact: Nokia Corporation ( qt-info@nokia.com )
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Nokia Corporation and its Subsidiary( -ies ) nor
** the names of its contributors may be used to endorse or promote
** products derived from this software without specific prior written
** permission.
**
** 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."
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtGui>
#include "borderlayout.h"
45 BorderLayout::BorderLayout( QWidget *parent, int margin, int spacing )
: QLayout( parent )
{
setMargin( margin );
setSpacing( spacing );
}
52 BorderLayout::BorderLayout( int spacing )
{
setSpacing( spacing );
}
57 BorderLayout::~BorderLayout( )
{
QLayoutItem *l;
while ( ( l = takeAt( 0 ) ) )
delete l;
}
64 void BorderLayout::addItem( QLayoutItem *item )
{
add( item, West );
}
69 void BorderLayout::addWidget( QWidget *widget, Position position )
{
add( new QWidgetItem( widget ), position );
}
74 Qt::Orientations BorderLayout::expandingDirections( ) const
{
return Qt::Horizontal | Qt::Vertical;
}
79 bool BorderLayout::hasHeightForWidth( ) const
{
return false;
}
84 int BorderLayout::count( ) const
{
return list.size( );
}
89 QLayoutItem *BorderLayout::itemAt( int index ) const
{
ItemWrapper *wrapper = list.value( index );
if ( wrapper )
return wrapper->item;
else
return 0;
}
98 QSize BorderLayout::minimumSize( ) const
{
return calculateSize( MinimumSize );
}
103 void BorderLayout::setGeometry( const QRect &rect )
{
ItemWrapper *center = 0;
int eastWidth = 0;
int westWidth = 0;
int northHeight = 0;
int southHeight = 0;
int centerHeight = 0;
int i;
QLayout::setGeometry( rect );
for ( i = 0; i < list.size( ); ++i ) {
ItemWrapper *wrapper = list.at( i );
QLayoutItem *item = wrapper->item;
Position position = wrapper->position;
if ( position == North ) {
item->setGeometry( QRect( rect.x( ), northHeight, rect.width( ),
item->sizeHint( ).height( ) ) );
northHeight += item->geometry( ).height( ) + spacing( );
} else if ( position == South ) {
item->setGeometry( QRect( item->geometry( ).x( ),
item->geometry( ).y( ), rect.width( ),
item->sizeHint( ).height( ) ) );
southHeight += item->geometry( ).height( ) + spacing( );
item->setGeometry( QRect( rect.x( ),
rect.y( ) + rect.height( ) - southHeight + spacing( ),
item->geometry( ).width( ),
item->geometry( ).height( ) ) );
} else if ( position == Center ) {
center = wrapper;
}
}
centerHeight = rect.height( ) - northHeight - southHeight;
for ( i = 0; i < list.size( ); ++i ) {
ItemWrapper *wrapper = list.at( i );
QLayoutItem *item = wrapper->item;
Position position = wrapper->position;
if ( position == West ) {
item->setGeometry( QRect( rect.x( ) + westWidth, northHeight,
item->sizeHint( ).width( ), centerHeight ) );
westWidth += item->geometry( ).width( ) + spacing( );
} else if ( position == East ) {
item->setGeometry( QRect( item->geometry( ).x( ), item->geometry( ).y( ),
item->sizeHint( ).width( ), centerHeight ) );
eastWidth += item->geometry( ).width( ) + spacing( );
item->setGeometry( QRect(
rect.x( ) + rect.width( ) - eastWidth + spacing( ),
northHeight, item->geometry( ).width( ),
item->geometry( ).height( ) ) );
}
}
if ( center )
center->item->setGeometry( QRect( westWidth, northHeight,
rect.width( ) - eastWidth - westWidth,
centerHeight ) );
}
172 QSize BorderLayout::sizeHint( ) const
{
return calculateSize( SizeHint );
}
177 QLayoutItem *BorderLayout::takeAt( int index )
{
if ( index >= 0 && index < list.size( ) ) {
ItemWrapper *layoutStruct = list.takeAt( index );
return layoutStruct->item;
}
return 0;
}
186 void BorderLayout::add( QLayoutItem *item, Position position )
{
list.append( new ItemWrapper( item, position ) );
}
191 QSize BorderLayout::calculateSize( SizeType sizeType ) const
{
QSize totalSize;
for ( int i = 0; i < list.size( ); ++i ) {
ItemWrapper *wrapper = list.at( i );
Position position = wrapper->position;
QSize itemSize;
if ( sizeType == MinimumSize )
itemSize = wrapper->item->minimumSize( );
else // ( sizeType == SizeHint )
itemSize = wrapper->item->sizeHint( );
if ( position == North || position == South || position == Center )
totalSize.rheight( ) += itemSize.height( );
if ( position == West || position == East || position == Center )
totalSize.rwidth( ) += itemSize.width( );
}
return totalSize;
}
1 #include "dragitem.h"
#include "markerbox.h"
int DragItem::next_id = 1;
6 DragItem::DragItem( QGraphicsItem *parent ) : QGraphicsItem( parent ){
setFlag( QGraphicsItem::ItemIsMovable );
setFlag( QGraphicsItem::ItemIsSelectable );
// allows setting of the base rectangle of dragitem
//base = QRectF( 0, 0, 0, 0 );
width = 0;
height = 0;
state = 0;
shape = Square;
id = next_id;
next_id++;
// selection boxes
markers[0] = new MarkerBox( );
markers[1] = new MarkerBox( );
markers[2] = new MarkerBox( );
markers[3] = new MarkerBox( );
markers[0]->setParentItem( this );
markers[1]->setParentItem( this );
markers[2]->setParentItem( this );
markers[3]->setParentItem( this );
markers[0]->setVisible( false );
markers[1]->setVisible( false );
markers[2]->setVisible( false );
markers[3]->setVisible( false );
}
35 int DragItem::getWidth( ){
return width;
}
39 int DragItem::getHeight( ){
return height;
}
43 void DragItem::setSize( int newWidth, int newHeight ){
width = newWidth;
height = newHeight;
}
48 int DragItem::getId( ){
return id;
}
52 int DragItem::getState( ){
return state;
}
56 void DragItem::setState( int x ){
state = x;
}
60 void DragItem::setShape( ShapeType newShape ){
shape = newShape;
}
64 QRectF DragItem::boundingRect( ) const{
return QRectF( 0, 0, width, height );
}
68 void DragItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ){
if( painter == 0 ){
// make a painter if none exists
painter = new QPainter( );
}
painter->setPen( Qt::NoPen );
if( this->isSelected( ) ){
// properly sets the marker boxes around selected objects
painter->setBrush( Qt::red );
markers[0]->setVisible( true );
markers[1]->setVisible( true );
markers[2]->setVisible( true );
markers[3]->setVisible( true );
// this next section grabs the scenePos of the object and offsets its markerboxes 3 pixels away from the corners of the obejcts
// boundingRect
QPointF pos = this->scenePos( ); // sets position to the upper left pixel
pos.rx( ) = -8;
pos.ry( ) = -8;
markers[0]->setPos( pos ); // upper left markerbox
pos = this->scenePos( );
pos.rx( ) = width+3;
pos.ry( ) = -8;
markers[1]->setPos( pos ); // upper right
pos = this->scenePos( );
pos.rx( ) = -8;
pos.ry( ) = height+3;
markers[2]->setPos( pos ); // lower left
pos = this->scenePos( );
pos.rx( ) = width+3;
pos.ry( ) = height+3;
markers[3]->setPos( pos ); // lower right
} else{
// if not selected, make the boxes invisible
painter->setBrush( Qt::black );
markers[0]->setVisible( false );
markers[1]->setVisible( false );
markers[2]->setVisible( false );
markers[3]->setVisible( false );
}
switch( shape ){
case Rectangle:{
painter->drawRect( QRectF( 0, 0, width, height ) );
break;
}
case Ellipse:{
painter->drawEllipse( QRectF( 0, 0, width, height ) );
break;
}
case Circle:{
painter->drawEllipse( QRectF( 0, 0, width, height ) );
break;
}
case Square:{
painter->drawRect( QRectF( 0, 0, width, height ) );
break;
}
default:{
printf( "Error in DragItem::paint, Why doesn't this DragItem have a shape type?\n" );
exit( 1 );
}
}
}
138 void DragItem::mousePressEvent( QGraphicsSceneMouseEvent *event ){
event->accept( );
QPointF pos = event->scenePos( );
pos.rx( ) -= 0.5 * width; // this centers the object on the cursor
pos.ry( ) -= 0.5 * height;
this->grabMouse( ); // DragItem will take all mouse actions
this->setOpacity( 0.5 ); // Dims the object when dragging to indicate dragging
state = 2;
}
148 void DragItem::mouseMoveEvent( QGraphicsSceneMouseEvent *event ){
// Centers the cursor while dragging, as opposed to dragging by the top-left most pixel
QPointF pos = event->scenePos( );
pos.rx( ) -= 0.5 * width;
pos.ry( ) -= 0.5 * height;
this->setPos( pos );
}
157 void DragItem::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ){
/*
This resets the object's coordinates to the cursor's coordinates when the
mouse is released, as opposed to creating a new object and then deleting the old one.
Also puts opacity back to normal.
*/
// Centers the cursor while dragging, as opposed to dragging by the top-left most pixel
QPointF pos = event->scenePos( );
pos.rx( ) -= 0.5 * width;
pos.ry( ) -= 0.5 * height;
this->setPos( pos );
this->setOpacity( 1.0 );
this->ungrabMouse( ); // release mouse back to DragScene
}
1 #include "dragscene.h"
#include "dragitem.h"
#include <QList>
#include <QGraphicsSceneDragDropEvent>
#include <QXmlStreamWriter>
#include <QIODevice>
9 DragScene::DragScene( QObject* parent, int initHeight, int initWidth ){
this->setSceneRect( QRectF( 0, 0, initHeight, initWidth ) );
createMode = Square;
sceneCreate = false;
gridSize = 10;
grid = true;
}
17 void DragScene::setCreateMode( ShapeType newType ){
createMode = newType;
}
21 ShapeType DragScene::getCreateMode( ){
return createMode;
}
25 QList<DragItem*> DragScene::getObjectList( ){
return scene_items;
}
29 bool DragScene::getSceneCreate( ){
return sceneCreate;
}
33 void DragScene::setSceneCreate( bool a ){
sceneCreate = a;
}
37 void DragScene::setGrid( bool a ){
grid = a;
update( );
}
42 void DragScene::setGridSize( int newSize ){
gridSize = newSize;
update( );
}
47 bool DragScene::getGrid( ){
return grid;
}
51 int DragScene::getGridSize( ){
return gridSize;
}
55 void DragScene::mousePressEvent( QGraphicsSceneMouseEvent *event ){
// this block checks if an object is under the cursor, if so, select it
if( this->itemAt( event->scenePos( ) ) ){
int index;
// object bounds checking shenanigans below
for( int i = 0; i < scene_items.size( ); i++ ){
if( ( int )event->scenePos( ).x( ) >= ( int )scene_items.at( i )->x( ) &&
( int )event->scenePos( ).x( ) <= ( ( int )( scene_items.at( i )->x( )+( int )scene_items.at( i )->getWidth( ) ) ) &&
( int )event->scenePos( ).y( ) >= ( int )scene_items.at( i )->y( ) &&
( int )event->scenePos( ).y( ) <= ( ( int )( scene_items.at( i )->y( )+( int )scene_items.at( i )->getHeight( ) ) ) ){
index = i;
}
}
DragItem *item = scene_items.at( index );
item->setSelected( true );
} else if( this->selectedItems( ).size( ) == 0 && sceneCreate ){
// if there is no object under the cursor, the number of selected items is zero, and sceneCreate is true, create an new item
DragItem *newItem = new DragItem( );
newItem->setShape( createMode );
switch( createMode ){
case Square:{
newItem->setSize( 25, 25 );
break;
}
case Rectangle:{
newItem->setSize( 60, 25 );
break;
}
case Circle:{
newItem->setSize( 25, 25 );
break;
}
case Ellipse:{
newItem->setSize( 60, 25 );
break;
}
default:{
printf( "Error in DragScene::mouseDoubleClickEvent, Why doesn't the scene have a static createMode set?\n" );
exit( 1 );
}
}
this->addItem( newItem );
newItem->setPos( event->scenePos( ) );
scene_items.append( newItem );
}
// if there are items selected, this will deselect them, otherwise it will just pass the click to DragItem
QGraphicsScene::mousePressEvent( event );
}
104 void DragScene::mouseMoveEvent( QGraphicsSceneMouseEvent *event ){
QGraphicsScene::mouseMoveEvent( event );
}
108 void DragScene::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ){
DragItem* lastItem;
for( int i = 0; i < scene_items.size( ); i++ ){
if( scene_items.at( i )->getState( ) == 2 ){
scene_items.at( i )->setState( 1 );
lastItem = scene_items.at( i );
} else{
scene_items.at( i )->setState( 0 );
}
}
if( this->itemAt( event->scenePos( ) ) ){
int maxZ = 0;
for( int i = 0; i < scene_items.size( ); i++ ){
if( ( int )event->scenePos( ).x( ) >= ( int )scene_items.at( i )->x( ) &&
( int )event->scenePos( ).x( ) <= ( ( int )( scene_items.at( i )->x( )+( int )scene_items.at( i )->getWidth( ) ) ) &&
( int )event->scenePos( ).y( ) >= ( int )scene_items.at( i )->y( ) &&
( int )event->scenePos( ).y( ) <= ( ( int )( scene_items.at( i )->y( )+( int )scene_items.at( i )->getHeight( ) ) ) ){
if( scene_items.at( i )->zValue( ) > maxZ ){
maxZ = scene_items.at( i )->zValue( );
}
}
}
lastItem->setZValue( maxZ+1 );
}
update( );
QGraphicsScene::mouseReleaseEvent( event );
}
137 void DragScene::mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event ){
QGraphicsScene::mouseDoubleClickEvent( event );
}
141 void DragScene::drawBackground( QPainter *painter, const QRectF &rect ){
// if the grid is on, draw the background
if( grid ){
int gridInterval = gridSize; //interval to draw grid lines at
painter->setWorldMatrixEnabled( true );
qreal left = int( rect.left( ) ) - ( int( rect.left( ) ) % gridInterval );
qreal top = int( rect.top( ) ) - ( int( rect.top( ) ) % gridInterval );
QVarLengthArray<QLineF, 100> linesX;
for ( qreal x = left; x < rect.right( ); x += gridInterval ){
linesX.append( QLineF( x, rect.top( ), x, rect.bottom( ) ) );
}
QVarLengthArray<QLineF, 100> linesY;
for ( qreal y = top; y < rect.bottom( ); y += gridInterval ){
linesY.append( QLineF( rect.left( ), y, rect.right( ), y ) );
}
painter->setOpacity( 0.2 );
painter->drawLines( linesX.data( ), linesX.size( ) );
painter->drawLines( linesY.data( ), linesY.size( ) );
}
/*
void DragScene::writeXML( QString *filename )
{
int i;
QFile *file = new QFile( filename );
QXmlStreamWriter *writer = new QXmlStreamWriter( file );
writer->writeStartDocument( );
writer->writeEndDocument( );
file.close( );
delete file;
delete writer;
}
*/
}
1 #include "dragview.h"
3 DragView::DragView( QWidget *parent ) : QGraphicsView( parent ){
setRenderHints( QPainter::Antialiasing );
}
1 #include <QBoxLayout>
#include "drawarea.h"
#include "dragscene.h"
#include "dragview.h"
#include "dragitem.h"
7 DrawArea::DrawArea( QWidget *parent, int newHeight, int newWidth ){
scene = new DragScene( 0, newHeight, newWidth );
view = new DragView( );
layout = new QHBoxLayout( );
view->setAcceptDrops( true );
view->setScene( scene );
layout->addWidget( view );
this->setLayout( layout );
}
17 void DrawArea::setSceneCreateMode( ShapeType newType ){
scene->setCreateMode( newType );
}
21 ShapeType DrawArea::getSceneCreateMode( ){
return scene->getCreateMode( );
}
25 void DrawArea::setSceneCreate( bool a ){
scene->setSceneCreate( a );
}
29 bool DrawArea::getSceneCreate( ){
return scene->getSceneCreate( );
}
33 bool DrawArea::getSceneGrid( ){
return scene->getGrid( );
}
37 int DrawArea::getSceneGridSize( ){
return scene->getGridSize( );
}
41 void DrawArea::setSceneGrid( bool a ){
scene->setGrid( a );
}
45 void DrawArea::setSceneGridSize( int newSize ){
scene->setGridSize( newSize );
}
1 #include "ellipse.h"
#include "markerbox.h"
6 ellipse::ellipse( QGraphicsItem *parent ) : icon( parent )
{
setFlag( QGraphicsItem::ItemIsMovable );
setFlag( QGraphicsItem::ItemIsSelectable );
// allows setting of the base rectangle of dragitem
//base = QRectF( 0, 0, 0, 0 );
m_xsize = 1;
m_ysize = 1;
m_shapetype = "Ellipse";
m_iD = m_next_id;
m_next_id++;
// selection boxes
markers[0] = new MarkerBox( );
markers[1] = new MarkerBox( );
markers[2] = new MarkerBox( );
markers[3] = new MarkerBox( );
markers[0]->setParentItem( this );
markers[1]->setParentItem( this );
markers[2]->setParentItem( this );
markers[3]->setParentItem( this );
markers[0]->setVisible( false );
markers[1]->setVisible( false );
markers[2]->setVisible( false );
markers[3]->setVisible( false );
}
37 ellipse::ellipse( QGraphicsItem *parent, int xsize, int ysize, int xpos, int ypos ) : icon( parent )
{
setFlag( QGraphicsItem::ItemIsMovable );
setFlag( QGraphicsItem::ItemIsSelectable );
// allows setting of the base rectangle of dragitem
//base = QRectF( 0, 0, 0, 0 );
m_xsize = xsize;
m_ysize = ysize;
m_xpos = xpos;
m_ypos = ypos;
m_shapetype = "Ellipse";
m_iD = m_next_id;
m_next_id++;
// selection boxes
markers[0] = new MarkerBox( );
markers[1] = new MarkerBox( );
markers[2] = new MarkerBox( );
markers[3] = new MarkerBox( );
markers[0]->setParentItem( this );
markers[1]->setParentItem( this );
markers[2]->setParentItem( this );
markers[3]->setParentItem( this );
markers[0]->setVisible( false );
markers[1]->setVisible( false );
markers[2]->setVisible( false );
markers[3]->setVisible( false );
}
68 QRectF ellipse::boundingRect( ) const{
return QRectF( 0, 0, m_xsize, m_ysize );
}
72 void ellipse::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ){
if( painter == 0 ){
// make a painter if none exists
painter = new QPainter( );
}
painter->setPen( Qt::NoPen );
if( this->isSelected( ) ){
// properly sets the marker boxes around selected objects
painter->setBrush( Qt::red );
markers[0]->setVisible( true );
markers[1]->setVisible( true );
markers[2]->setVisible( true );
markers[3]->setVisible( true );
QPointF pos = this->scenePos( ); // sets position to the upper left pixel
pos.rx( ) = -8;
pos.ry( ) = -8;
markers[0]->setPos( pos );
pos = this->scenePos( );
pos.rx( ) = m_xsize+3;
pos.ry( ) = -8;
markers[1]->setPos( pos );
pos = this->scenePos( );
pos.rx( ) = -8;
pos.ry( ) = m_ysize+3;
markers[2]->setPos( pos );
pos = this->scenePos( );
pos.rx( ) = m_xsize+3;
pos.ry( ) = m_ysize+3;
markers[3]->setPos( pos );
} else{
// if not selected, make the boxes invisible
painter->setBrush( Qt::black );
markers[0]->setVisible( false );
markers[1]->setVisible( false );
markers[2]->setVisible( false );
markers[3]->setVisible( false );
}
painter->drawEllipse( QRectF( 0, 0, m_xsize, m_ysize ) );
}
121 void ellipse::mousePressEvent( QGraphicsSceneMouseEvent *event ){
event->accept( );
QPointF pos = event->scenePos( );
pos.rx( ) -= 0.5 * m_xsize;
pos.ry( ) -= 0.5 * m_ysize;
this->grabMouse( ); // DragItem will take all mouse actions
this->setOpacity( 0.5 ); // Dims the object when dragging to indicate dragging
}
130 void ellipse::mouseMoveEvent( QGraphicsSceneMouseEvent *event ){
// Centers the cursor while dragging, as opposed to dragging by the top-left most pixel
QPointF pos = event->scenePos( );
pos.rx( ) -= 0.5 * m_xsize;
pos.ry( ) -= 0.5 * m_ysize;
this->setPos( pos.rx( ), pos.ry( ) );
}
139 void ellipse::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ){
/*
This resets the object's coordinates to the cursor's coordinates when the
mouse is released, as opposed to creating a new object and then deleting the old one.
Also puts opacity back to normal.
*/
// Centers the cursor while dragging, as opposed to dragging by the top-left most pixel
QPointF pos = event->scenePos( );
pos.rx( ) -= 0.5 * m_xsize;
pos.ry( ) -= 0.5 * m_ysize;
this->setPos( pos.rx( ), pos.ry( ) );
this->setOpacity( 1.0 );
this->ungrabMouse( ); // release mouse back to DragScene
}
1 #include "drawarea.h"
#include "tabmanager.h"
QList<DrawArea*> canvas;
TabManager *tabWidget;
1 /* icon.cpp -contains the functions to store default properties in the shape structs
and contains the creation function for each shape
Made by Theora Rice
*/
#include "icon.h"
#include <QtGui>
int icon::m_next_id = 1;
11 icon::icon( QGraphicsItem *parent ) : QGraphicsItem( parent )
{
}
16 int icon::getXPos( )
{
return m_xpos;
}
21 int icon::getYPos( )
{
return m_ypos;
}
26 void icon::setPos( int newXPos, int newYPos )
{
m_xpos = newXPos;
m_ypos = newYPos;
}
32 int icon::getXSize( )
{
return m_xsize;
}
37 int icon::getYSize( )
{
return m_ysize;
}
42 void icon::setSize( int newXSize, int newYSize )
{
m_xsize = newXSize;
m_ysize = newYSize;
}
49 QString icon::reportShapetype( )
{
return m_shapetype;
}
54 void icon::setShapetype( QString shapename )
{
m_shapetype = shapename;
}
59 int icon::getID( )
{
return m_iD;
}
1 /* main.cpp - file that displays windows.
*/
#include <QtGui/QApplication>
#include "drawarea.h"
#include "mainwindow.h"
#include "toolbar.h"
8 int main( int argc, char *argv[] )
{
QApplication app( argc, argv );
MainWindow window;
window.show( );
return app.exec( );
}
1 /*
Max McKinnon
UIdaho 2011
Specs: see UI concept on skydrive
The menu is non funcional at this point
*/
#include <QtGui>
#include "mainwindow.h"
#include "borderlayout.h"
#include "drawarea.h"
#include "toolbar.h"
#include<iostream>
using namespace std;
20 MainWindow::MainWindow( )
{
widget = new QWidget;
setCentralWidget( widget );
toolbar = new Toolbar;
/* need some way to get
* multiple canvas's
* for different tabs*/
layout = new BorderLayout;
/*Create tab objects*/
tabWidget = new TabManager;
next_tab_num = 1;
/*end*/
layout->setMargin( 5 );
layout->addWidget( toolbar, BorderLayout::West );
/*Add tab objects to mainwindow*/
layout->addWidget( tabWidget, BorderLayout::Center );
/*end*/
widget->setLayout( layout );
createActions( );
createMenus( );
QString message = tr( "A context menu is available by right-clicking" );
statusBar( )->showMessage( message );
setWindowTitle( tr( "pUML" ) );
setMinimumSize( 160, 160 );
resize( 480, 320 );
this->newTab( );
}
54 void MainWindow::contextMenuEvent( QContextMenuEvent *event )
{
QMenu menu( this );
menu.addAction( cutAct );
menu.addAction( copyAct );
menu.addAction( pasteAct );
menu.exec( event->globalPos( ) );
}
63 void MainWindow::newFile( )
{
/* for some reason, this next line prevented the
* project from working correctly ( ie, it would
* crash as soon as newFile( ) was called, even if
* newTab( ) was commented out )*/
//infoLabel->setText( tr( "Invoked <b>File|New</b>" ) );
newTab( );
}
73 void MainWindow::open( )
{
infoLabel->setText( tr( "Invoked <b>File|Open</b>" ) );
}
78 void MainWindow::save( )
{
infoLabel->setText( tr( "Invoked <b>File|Save</b>" ) );
}
83 void MainWindow::print( )
{
infoLabel->setText( tr( "Invoked <b>File|Print</b>" ) );
}
88 void MainWindow::undo( )
{
infoLabel->setText( tr( "Invoked <b>Edit|Undo</b>" ) );
}
93 void MainWindow::redo( )
{
infoLabel->setText( tr( "Invoked <b>Edit|Redo</b>" ) );
}
98 void MainWindow::cut( )
{
infoLabel->setText( tr( "Invoked <b>Edit|Cut</b>" ) );
}
103 void MainWindow::copy( )
{
infoLabel->setText( tr( "Invoked <b>Edit|Copy</b>" ) );
}
108 void MainWindow::paste( )
{
infoLabel->setText( tr( "Invoked <b>Edit|Paste</b>" ) );
}
/*
* Function for creating a new tab;
* Should be invoked by new-file and open-file.
*
* For differentiating between unsaved and saved files,
* perhaps a 'filename' argument should be passed in.
*
* 'i' and 'setcurrentindex' are used to create a new
* canvas associated with that tab...somehow? How would
* they be kept track of ( ie, each canvas associated with
* each tab )? .-.
*/
125 void MainWindow::newTab( )
{
int i = tabWidget->count( );
char* s = ( char* )malloc( 10*sizeof( char ) );
sprintf( s, "Tab %d", next_tab_num );
next_tab_num++;
QString q = QString( s );
DrawArea *newCanvas = new DrawArea;
canvas.append( newCanvas );
tabWidget->insertTab( i, newCanvas, s );
tabWidget->setCurrentIndex( i );
tabWidget->widget( i )->setVisible( true );
free( s );
}
/*end*/
141 void MainWindow::saveAsFile( )
{
QString filename = QFileDialog::getSaveFileName( this, "Save file", QDir::homePath( ), "*.xml" );
// strip full path off filename for display
int idx = filename.lastIndexOf( "/" );
filename.remove( 0, idx+1 );
tabWidget->setTabText( tabWidget->currentIndex( ), filename );
/* Insert
* actual
* saving
* function
* stuff
* here
*/
}
161 void MainWindow::openFile( )
{
QString filename = QFileDialog::getOpenFileName( this, "Open file", QDir::homePath( ), "*.xml" );
newTab( );
// strip full path off filename for display
int idx = filename.lastIndexOf( "/" );
filename.remove( 0, idx+1 );
tabWidget->setTabText( tabWidget->currentIndex( ), filename );
/* new tab
* set new tab name to filename
* load in stuff
* profit
* */
}
178 void MainWindow::closeTab( )
{
canvas.removeAt( tabWidget->currentIndex( ) );
tabWidget->removeTab( tabWidget->currentIndex( ) );
}
185 void MainWindow::bold( )
{
infoLabel->setText( tr( "Invoked <b>Edit|Format|Bold</b>" ) );
}
190 void MainWindow::italic( )
{
infoLabel->setText( tr( "Invoked <b>Edit|Format|Italic</b>" ) );
}
195 void MainWindow::leftAlign( )
{
infoLabel->setText( tr( "Invoked <b>Edit|Format|Left Align</b>" ) );
}
200 void MainWindow::rightAlign( )
{
infoLabel->setText( tr( "Invoked <b>Edit|Format|Right Align</b>" ) );
}
205 void MainWindow::justify( )
{
infoLabel->setText( tr( "Invoked <b>Edit|Format|Justify</b>" ) );
}
210 void MainWindow::center( )
{
infoLabel->setText( tr( "Invoked <b>Edit|Format|Center</b>" ) );
}
215 void MainWindow::setLineSpacing( )
{
infoLabel->setText( tr( "Invoked <b>Edit|Format|Set Line Spacing</b>" ) );
}
220 void MainWindow::setParagraphSpacing( )
{
infoLabel->setText( tr( "Invoked <b>Edit|Format|Set Paragraph Spacing</b>" ) );
}
225 void MainWindow::about( )
{
infoLabel->setText( tr( "Invoked <b>Help|About</b>" ) );
QMessageBox::about( this, tr( "About Menu" ),
tr( "The <b>Menu</b> example shows how to create "
"menu-bar menus and context menus." ) );
}
233 void MainWindow::aboutQt( )
{
infoLabel->setText( tr( "Invoked <b>Help|About Qt</b>" ) );
}
238 void MainWindow::createActions( )
{
newAct = new QAction( tr( "New Tab" ), this );
connect( newAct, SIGNAL( triggered( ) ), this, SLOT( newFile( ) ) );
openAct = new QAction( tr( "Close Tab" ), this );
connect( openAct, SIGNAL( triggered( ) ), this, SLOT( closeTab( ) ) );
saveAct = new QAction( tr( "Save as..." ), this );
connect( saveAct, SIGNAL( triggered( ) ), this, SLOT( saveAsFile( ) ) );
printAct = new QAction( tr( "Open" ), this );
connect( printAct, SIGNAL( triggered( ) ), this, SLOT( openFile( ) ) );
exitAct = new QAction( tr( "Activity" ), this );
undoAct = new QAction( tr( "&Undo" ), this );
undoAct->setShortcuts( QKeySequence::Undo );
undoAct->setStatusTip( tr( "Undo the last operation" ) );
connect( undoAct, SIGNAL( triggered( ) ), this, SLOT( undo( ) ) );
redoAct = new QAction( tr( "&Redo" ), this );
redoAct->setShortcuts( QKeySequence::Redo );
redoAct->setStatusTip( tr( "Redo the last operation" ) );
connect( redoAct, SIGNAL( triggered( ) ), this, SLOT( redo( ) ) );
cutAct = new QAction( tr( "Cu&t" ), this );
cutAct->setShortcuts( QKeySequence::Cut );
cutAct->setStatusTip( tr( "Cut the current selection's contents to the "
"clipboard" ) );
connect( cutAct, SIGNAL( triggered( ) ), this, SLOT( cut( ) ) );
copyAct = new QAction( tr( "&Copy" ), this );
copyAct->setShortcuts( QKeySequence::Copy );
copyAct->setStatusTip( tr( "Copy the current selection's contents to the "
"clipboard" ) );
connect( copyAct, SIGNAL( triggered( ) ), this, SLOT( copy( ) ) );
pasteAct = new QAction( tr( "&Paste" ), this );
pasteAct->setShortcuts( QKeySequence::Paste );
pasteAct->setStatusTip( tr( "Paste the clipboard's contents into the current "
"selection" ) );
connect( pasteAct, SIGNAL( triggered( ) ), this, SLOT( paste( ) ) );
boldAct = new QAction( tr( "&Bold" ), this );
boldAct->setCheckable( true );
boldAct->setShortcut( QKeySequence::Bold );
boldAct->setStatusTip( tr( "Make the text bold" ) );
connect( boldAct, SIGNAL( triggered( ) ), this, SLOT( bold( ) ) );
QFont boldFont = boldAct->font( );
boldFont.setBold( true );
boldAct->setFont( boldFont );
italicAct = new QAction( tr( "&Italic" ), this );
italicAct->setCheckable( true );
italicAct->setShortcut( QKeySequence::Italic );
italicAct->setStatusTip( tr( "Make the text italic" ) );
connect( italicAct, SIGNAL( triggered( ) ), this, SLOT( italic( ) ) );
QFont italicFont = italicAct->font( );
italicFont.setItalic( true );
italicAct->setFont( italicFont );
setLineSpacingAct = new QAction( tr( "Set &Line Spacing..." ), this );
setLineSpacingAct->setStatusTip( tr( "Change the gap between the lines of a "
"paragraph" ) );
connect( setLineSpacingAct, SIGNAL( triggered( ) ), this, SLOT( setLineSpacing( ) ) );
setParagraphSpacingAct = new QAction( tr( "Set &Paragraph Spacing..." ), this );
setLineSpacingAct->setStatusTip( tr( "Change the gap between paragraphs" ) );
connect( setParagraphSpacingAct, SIGNAL( triggered( ) ),
this, SLOT( setParagraphSpacing( ) ) );
aboutAct = new QAction( tr( "&About" ), this );
aboutAct->setStatusTip( tr( "Show the application's About box" ) );
connect( aboutAct, SIGNAL( triggered( ) ), this, SLOT( about( ) ) );
aboutQtAct = new QAction( tr( "About &Qt" ), this );
aboutQtAct->setStatusTip( tr( "Show the Qt library's About box" ) );
connect( aboutQtAct, SIGNAL( triggered( ) ), qApp, SLOT( aboutQt( ) ) );
connect( aboutQtAct, SIGNAL( triggered( ) ), this, SLOT( aboutQt( ) ) );
leftAlignAct = new QAction( tr( "&Left Align" ), this );
leftAlignAct->setCheckable( true );
leftAlignAct->setShortcut( tr( "Ctrl+L" ) );
leftAlignAct->setStatusTip( tr( "Left align the selected text" ) );
connect( leftAlignAct, SIGNAL( triggered( ) ), this, SLOT( leftAlign( ) ) );
rightAlignAct = new QAction( tr( "&Right Align" ), this );
rightAlignAct->setCheckable( true );
rightAlignAct->setShortcut( tr( "Ctrl+R" ) );
rightAlignAct->setStatusTip( tr( "Right align the selected text" ) );
connect( rightAlignAct, SIGNAL( triggered( ) ), this, SLOT( rightAlign( ) ) );
justifyAct = new QAction( tr( "&Justify" ), this );
justifyAct->setCheckable( true );
justifyAct->setShortcut( tr( "Ctrl+J" ) );
justifyAct->setStatusTip( tr( "Justify the selected text" ) );
connect( justifyAct, SIGNAL( triggered( ) ), this, SLOT( justify( ) ) );
centerAct = new QAction( tr( "&Center" ), this );
centerAct->setCheckable( true );
centerAct->setShortcut( tr( "Ctrl+E" ) );
centerAct->setStatusTip( tr( "Center the selected text" ) );
connect( centerAct, SIGNAL( triggered( ) ), this, SLOT( center( ) ) );
alignmentGroup = new QActionGroup( this );
alignmentGroup->addAction( leftAlignAct );
alignmentGroup->addAction( rightAlignAct );
alignmentGroup->addAction( justifyAct );
alignmentGroup->addAction( centerAct );
leftAlignAct->setChecked( true );
}
354 void MainWindow::createMenus( )
{
fileMenu = menuBar( )->addMenu( tr( "File" ) );
fileMenu->addAction( newAct );
fileMenu->addAction( openAct );
fileMenu->addAction( saveAct );
fileMenu->addAction( printAct );
fileMenu->addAction( exitAct );
editMenu = menuBar( )->addMenu( tr( "&Edit" ) );
editMenu->addAction( undoAct );
editMenu->addAction( redoAct );
editMenu->addSeparator( );
editMenu->addAction( cutAct );
editMenu->addAction( copyAct );
editMenu->addAction( pasteAct );
editMenu->addSeparator( );
helpMenu = menuBar( )->addMenu( tr( "&Help" ) );
helpMenu->addAction( aboutAct );
helpMenu->addAction( aboutQtAct );
formatMenu = editMenu->addMenu( tr( "&Format" ) );
formatMenu->addAction( boldAct );
formatMenu->addAction( italicAct );
formatMenu->addSeparator( )->setText( tr( "Alignment" ) );
formatMenu->addAction( leftAlignAct );
formatMenu->addAction( rightAlignAct );
formatMenu->addAction( justifyAct );
formatMenu->addAction( centerAct );
formatMenu->addSeparator( );
formatMenu->addAction( setLineSpacingAct );
formatMenu->addAction( setParagraphSpacingAct );
}
1 #include "markerbox.h"
3 MarkerBox::MarkerBox( QGraphicsItem *parent ) : QGraphicsItem( parent ){
width = 5;
height = 5;
setOpacity( 1.0 );
}
9 QRectF MarkerBox::boundingRect( ) const{
return QRectF( 0, 0, width, height );
}
13 void MarkerBox::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ){
if( painter == 0 ){
// make a painter if none exists
painter = new QPainter( );
}
painter->setBrush( Qt::black );
painter->drawRect( QRectF( 0, 0, width, height ) );
}
1 /*optionsdialog.cpp - includes the functions for the prototypes
defined in optionsdialog.h
Made by Coleman Beasley - 12/16/2011
*/
#include "optionsdialog.h"
7 OptionsDialog::OptionsDialog( QWidget *parent ) :
QWidget( parent )
{
this->setWindowModality( Qt::ApplicationModal );
//initialize values
initValues( );
//set up buttons
buttonSetup( );
//set up tabs
tabWidget = new QTabWidget;
shapeTab = new QWidget;
shapeTabSetup( );
lineTab = new QWidget;
lineTabSetup( );
textTab = new QWidget;
textTabSetup( );
tabWidget->addTab( shapeTab, tr( "Shape" ) );
tabWidget->addTab( lineTab, tr( "Line" ) );
tabWidget->addTab( textTab, tr( "Text" ) );
QGridLayout * mainLayout = new QGridLayout;
mainLayout->addWidget( tabWidget );
mainLayout->addWidget( okButton );
mainLayout->addWidget( cancelButton );
setLayout( mainLayout );
}
37 void OptionsDialog::initValues( )
{
//init shape variables
shapeFillColor = "white";
shapeWeight = 1;
//init line variables
lineColor = "black";
lineWeight = 1;
//init text variables
textColor = "black";
textSize = 1;
textFont = "Arial";
}
//create buttons for closing dialog
54 void OptionsDialog::buttonSetup( )
{
okButton = new QPushButton( tr( "OK" ) );
connect( okButton, SIGNAL( clicked( ) ), this, SLOT( acknowledge( ) ) );
cancelButton = new QPushButton( tr( "Cancel" ) );
connect( cancelButton, SIGNAL( clicked( ) ), this, SLOT( quit( ) ) );
}
// add fields to the shapeTab Widget
63 void OptionsDialog::shapeTabSetup( )
{
//initalize fields and labels
shapeFillField = new QTextEdit;
shapeFillField->setFixedHeight( 25 );
QLabel *fillLabel = new QLabel;
fillLabel->setText( "Shape Fill Color" );
// shapeWeightField = new QTextEdit;
// shapeWeightField->setFixedHeight( 25 );
QLabel *weightLabel = new QLabel;
weightLabel->setText( "Shape Weight" );
shapeWeightBox = new QSpinBox;
shapeWeightBox->setSingleStep( 1 );
shapeWeightBox->setValue( shapeWeight );
/* create the widget's layout
* labels on left, fields on right
*/
QGridLayout * layout = new QGridLayout;
layout->addWidget( shapeFillField, 0, 1 );
layout->addWidget( fillLabel, 0, 0 );
// layout->addWidget( shapeWeightField, 1, 1 );
layout->addWidget( weightLabel, 1, 0 );
layout->addWidget( shapeWeightBox, 1, 1 );
shapeTab->setLayout( layout );
}
// add fields to the lineTab Widget
92 void OptionsDialog::lineTabSetup( )
{
//initalize fields and labels
lineColorField = new QTextEdit;
lineColorField->setFixedHeight( 25 );
QLabel *colorLabel = new QLabel;
colorLabel->setText( "Line Color" );
lineWeightBox = new QSpinBox;
lineWeightBox->setSingleStep( 1 );
lineWeightBox->setValue( lineWeight );
QLabel *weightLabel = new QLabel;
weightLabel->setText( "Line Weight" );
/* create the widget's layout
* labels on left, fields on right
*/
QGridLayout *layout = new QGridLayout;
layout->setRowStretch( 0, 1 );
layout->addWidget( colorLabel, 0, 0 );
layout->addWidget( lineColorField, 0, 1 );
layout->addWidget( weightLabel, 1, 0 );
layout->addWidget( lineWeightBox, 1, 1 );
lineTab->setLayout( layout );
}
//add fields to the textTab Widget
119 void OptionsDialog::textTabSetup( )
{
//initalize fields and labels
textFontField = new QTextEdit;
textFontField->setFixedHeight( 25 );
QLabel *fontLabel = new QLabel;
fontLabel->setText( "Font" );
textColorField = new QTextEdit;
textColorField->setFixedHeight( 25 );
QLabel *colorLabel = new QLabel;
colorLabel->setText( "Text Color" );
textSizeBox = new QSpinBox;
textSizeBox->setSingleStep( 1 );
textSizeBox->setValue( textSize );
QLabel *sizeLabel = new QLabel;
sizeLabel->setText( "Font Size" );
/* create the widget's layout
* labels on left, fields on right
*/
QGridLayout *layout = new QGridLayout;
// layout->setRowStretch( 0, 1 );
layout->addWidget( fontLabel, 0, 0 );
layout->addWidget( textFontField, 0, 1 );
layout->addWidget( colorLabel, 1, 0 );
layout->addWidget( textColorField, 1, 1 );
layout->addWidget( sizeLabel, 2, 0 );
layout->addWidget( textSizeBox, 2, 1 );
textTab->setLayout( layout );
}
/* take the values from the fields of the dialog
* and plug them into the data members
*/
155 void OptionsDialog::acknowledge( )
{
//copy data here
//shape
shapeFillColor = shapeFillField->toPlainText( );
shapeWeight = shapeWeightBox->value( );
//line
lineColor = lineColorField->toPlainText( );
lineWeight = lineWeightBox->value( );
//text
textColor = textColorField->toPlainText( );
textFont = textFontField->toPlainText( );
textSize = textSizeBox->value( );
quit( );
}
/* close the dialog box
*/
174 void OptionsDialog::quit( )
{
this->close( );
}
1 /* shapes.cpp -contains the functions to store default properties in the shape structs
and contains the creation function for each shape
Made by Theora Rice
*/
#include "shapes.h"
#include <QtGui>
9 shapes::shapes( )
{
}
//Creating a default ellipse
13 void shapes::createEllipse( )
{
ObStruct shapename;
shapename.iD = count++;
shapename.size = 5;
shapename.posx = 0;
shapename.posy = 0;
shapename.linewidth = 1;
shapename.shapetype = "shapename";
shapename.color = "black";
QPainter circle;
circle.setPen( "black" );
QRectF rectangle( 20, 20, 100, 50 );
circle.drawEllipse( rectangle );
}
//creating default arrow
31 void shapes::createArrow( )
{
Arrows shapename;
shapename.iD = count++;
shapename.posx = 0;
shapename.posy = 0;
shapename.posxend = 5;
shapename.posyend = 5;
shapename.linewidth = 1;
shapename.shapetype = "shapename";
shapename.color = "black";
}
//creating default dashed arrow
45 void shapes::createDashedArrow( )
{
Arrows shapename;
shapename.iD = count++;
shapename.posx = 0;
shapename.posy = 0;
shapename.posxend = 5;
shapename.posyend = 5;
shapename.linewidth = 1;
shapename.shapetype = "dashed-arrow";
shapename.color = "black";
}
//creating default line
59 void shapes::createLine( )
{
Arrows shapename;
shapename.iD = count++;
shapename.posx = 0;
shapename.posy = 0;
shapename.posxend = 5;
shapename.posyend = 5;
shapename.linewidth = 1;
shapename.shapetype = "line";
shapename.color = "black";
QLineF line( 105, 70, 140, 100 );
QPainter painter;
painter.drawLine( line );
}
//creating default field ( box )
76 void shapes::createField( )
{
ObStruct field;
field.iD = count++;
field.size = 5;
field.posx = 0;
field.posy = 0;
field.linewidth = 1;
field.shapetype = "field";
field.color = "black";
}
//creating default actor
89 void shapes::createActor( )
{
ObStruct actor;
actor.iD = count++;
actor.size = 5;
actor.posx = 0;
actor.posy = 0;
actor.linewidth = 1;
actor.shapetype = "actor";
actor.color = "black";
}
1 #include "tabmanager.h"
#include "global.h"
#include "mainwindow.h"
extern MainWindow window;
6 TabManager::TabManager( QWidget *parent ) : QTabWidget( parent ){
connect( this , SIGNAL( currentChanged( int ) ), this, SLOT( currentChangedSlot( int ) ) );
}
10 void TabManager::currentChangedSlot( int index ){
ShapeType indexCreateMode;
bool indexGrid;
indexCreateMode = canvas.at( index )->getSceneCreateMode( );
indexGrid = canvas.at( index )->getSceneGrid( );
}
1 /*toolbar.cpp - includes the functions for the prototypes
presented in toolbar.h
Made by Coleman Beasley - 12/16/2011
*/
#include "toolbar.h"
#include "optionsdialog.h"
#include "drawarea.h"
#include "icon.h"
#include "global.h"
11 Toolbar::Toolbar( QWidget *parent ) :
//QDialog( parent )
QWidget( parent )
{
this->setWindowModality( Qt::NonModal );
options = new OptionsDialog;
/* set defaults for Param variables
*/
shape.fillColor = "black";
shape.name = "pill";
shape.weight = 1;
text.color = "black";
text.font = "Times New Roman";
text.size = 1;
line.color = "black";
line.weight = 1;
createActions( );
createMenus( );
QGridLayout *layout;
layout = initButtons( );
setLayout( layout );
shapeButton->setMenu( shapeMenu );
gridButton->setMenu( gridMenu );
}
//create buttons and add to layout
41 QGridLayout * Toolbar::initButtons( )
{
//create buttons
//shapeButton = new QPushButton( tr( "Shape" ), this );
shapeButton = new QPushButton( tr( "Shape" ) );
textButton = new QPushButton( tr( "Text" ) );
lineButton = new QPushButton( tr( "Line" ) );
optionsButton = new QPushButton( tr( "Options" ) );
gridButton = new QPushButton( tr( "Grid" ) );
// connect buttons to slots
connect( shapeButton, SIGNAL( clicked( ) ), this, SLOT( insertShape( ) ) );
connect( textButton, SIGNAL( clicked( ) ), this, SLOT( insertText( ) ) );
connect( lineButton, SIGNAL( clicked( ) ), this, SLOT( insertLine( ) ) );
connect( optionsButton, SIGNAL( clicked( ) ), this, SLOT( showOptions( ) ) );
/* add created buttons to a grid layout
* buttons are arranged in a single column
*/
QGridLayout *layout = new QGridLayout;
layout->setColumnStretch( 1, 0 );
layout->addWidget( shapeButton, 0, 0 );
layout->addWidget( lineButton, 1, 0 );
layout->addWidget( textButton, 2, 0 );
layout->addWidget( optionsButton, 3, 0 );
layout->addWidget( gridButton, 4, 0 );
return layout;
}
71 void Toolbar::createActions( ){
addRectAct = new QAction( tr( "Rectangle" ), this );
addRectAct->setCheckable( true );
connect( addRectAct, SIGNAL( triggered( ) ), this, SLOT( addRect( ) ) );
addEllipseAct = new QAction( tr( "Ellipse" ), this );
addEllipseAct->setCheckable( true );
connect( addEllipseAct, SIGNAL( triggered( ) ), this, SLOT( addEllipse( ) ) );
addSquareAct = new QAction( tr( "Square" ), this );
addSquareAct->setCheckable( true );
connect( addSquareAct, SIGNAL( triggered( ) ), this, SLOT( addSquare( ) ) );
addCircleAct = new QAction( tr( "Circle" ), this );
addCircleAct->setCheckable( true );
connect( addCircleAct, SIGNAL( triggered( ) ), this, SLOT( addCircle( ) ) );
addNoneAct = new QAction( tr( "None" ), this );
addNoneAct->setCheckable( true );
addNoneAct->setChecked( true );
connect( addNoneAct, SIGNAL( triggered( ) ), this, SLOT( addNone( ) ) );
shapesGroup = new QActionGroup( this );
shapesGroup->addAction( addNoneAct );
shapesGroup->addAction( addRectAct );
shapesGroup->addAction( addSquareAct );
shapesGroup->addAction( addCircleAct );
shapesGroup->addAction( addEllipseAct );
gridOnAct = new QAction( tr( "On" ), this );
gridOnAct->setCheckable( true );
gridOnAct->setChecked( true );
connect( gridOnAct, SIGNAL( triggered( ) ), this, SLOT( gridOn( ) ) );
gridOffAct = new QAction( tr( "Off" ), this );
gridOffAct->setCheckable( true );
connect( gridOffAct, SIGNAL( triggered( ) ), this, SLOT( gridOff( ) ) );
gridOnOffToggleGroup = new QActionGroup( this );
gridOnOffToggleGroup->addAction( gridOnAct );
gridOnOffToggleGroup->addAction( gridOffAct );
}
114 void Toolbar::createMenus( ){
shapeMenu = new QMenu( this );
shapeMenu->addAction( addNoneAct );
shapeMenu->addAction( addSquareAct );
shapeMenu->addAction( addCircleAct );
shapeMenu->addAction( addRectAct );
shapeMenu->addAction( addEllipseAct );
gridMenu = new QMenu( this );
gridMenu->addAction( gridOnAct );
gridMenu->addAction( gridOffAct );
}
127 void Toolbar::showOptions( )
{
// options->exec( );
options->show( );
shape.fillColor = options->shapeFillColor;
shape.weight = options->shapeWeight;
text.color = options->textColor;
text.font = options->textFont;
text.size = options->textSize;
line.color = options->lineColor;
line.weight = options->lineWeight;
}
/* add a shape into the drawing area. Use the parent's
* DrawArea object. Use drawArea.insertShape, and pass in
* the shape struct
*/
145 void Toolbar::insertShape( ){
shapeButton->showMenu( );
}
/* add text into the drawing area. Use the parent's
* DrawArea object. Use drawArea.insertText, and pass in
* the text struct
*/
153 void Toolbar::insertText( )
{
}
/* add a line into the drawing area. Use the parent's
* DrawArea object. Use drawArea.insertLine, and pass in
* the line struct. Then call drawArea.lineConnect( )?
*/
162 void Toolbar::insertLine( )
{
}
167 void Toolbar::addRect( ){
canvas.at( tabWidget->currentIndex( ) )->setSceneCreate( true );
canvas.at( tabWidget->currentIndex( ) )->setSceneCreateMode( Rectangle );
}
172 void Toolbar::addSquare( ){
canvas.at( tabWidget->currentIndex( ) )->setSceneCreate( true );
canvas.at( tabWidget->currentIndex( ) )->setSceneCreateMode( Square );
}
177 void Toolbar::addCircle( ){
canvas.at( tabWidget->currentIndex( ) )->setSceneCreate( true );
canvas.at( tabWidget->currentIndex( ) )->setSceneCreateMode( Circle );
}
182 void Toolbar::addEllipse( ){
canvas.at( tabWidget->currentIndex( ) )->setSceneCreate( true );
canvas.at( tabWidget->currentIndex( ) )->setSceneCreateMode( Ellipse );
}
187 void Toolbar::addNone( ){
canvas.at( tabWidget->currentIndex( ) )->setSceneCreate( false );
}
191 void Toolbar::gridOn( ){
canvas.at( tabWidget->currentIndex( ) )->setSceneGrid( true );
}
195 void Toolbar::gridOff( ){
canvas.at( tabWidget->currentIndex( ) )->setSceneGrid( false );
}