QtBase: examples/widgets/graphicsview/ codestyle
Change-Id: I501066b5eb5a1557d510e0ec20b5270e8c12704a Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
parent
cbf3771e86
commit
dae8d2505d
@ -38,15 +38,12 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QGraphicsWidget>
|
|
||||||
#include <QGraphicsProxyWidget>
|
|
||||||
#include <QGraphicsAnchorLayout>
|
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
|
|
||||||
static QGraphicsProxyWidget *createItem(const QSizeF &minimum = QSizeF(100.0, 100.0),
|
static QGraphicsProxyWidget *createItem(const QSizeF &minimum = QSizeF(100.0, 100.0),
|
||||||
const QSizeF &preferred = QSize(150.0, 100.0),
|
const QSizeF &preferred = QSize(150.0, 100.0),
|
||||||
const QSizeF &maximum = QSizeF(200.0, 100.0),
|
const QSizeF &maximum = QSizeF(200.0, 100.0),
|
||||||
const QString &name = "0")
|
const QString &name = "0")
|
||||||
{
|
{
|
||||||
QGraphicsProxyWidget *w = new QGraphicsProxyWidget;
|
QGraphicsProxyWidget *w = new QGraphicsProxyWidget;
|
||||||
w->setWidget(new QPushButton(name));
|
w->setWidget(new QPushButton(name));
|
||||||
|
@ -40,6 +40,10 @@
|
|||||||
|
|
||||||
#include "layoutitem.h"
|
#include "layoutitem.h"
|
||||||
|
|
||||||
|
#include <QGradient>
|
||||||
|
#include <QGraphicsLinearLayout>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
LayoutItem::LayoutItem(QGraphicsItem *parent/* = 0*/)
|
LayoutItem::LayoutItem(QGraphicsItem *parent/* = 0*/)
|
||||||
: QGraphicsLayoutItem(), QGraphicsItem(parent)
|
: QGraphicsLayoutItem(), QGraphicsItem(parent)
|
||||||
@ -71,7 +75,7 @@ void LayoutItem::paint(QPainter *painter,
|
|||||||
// paint a background rect (with gradient)
|
// paint a background rect (with gradient)
|
||||||
QLinearGradient gradient(frame.topLeft(), frame.topLeft() + QPointF(200,200));
|
QLinearGradient gradient(frame.topLeft(), frame.topLeft() + QPointF(200,200));
|
||||||
stops << QGradientStop(0.0, QColor(60, 60, 60));
|
stops << QGradientStop(0.0, QColor(60, 60, 60));
|
||||||
stops << QGradientStop(frame.height()/2/frame.height(), QColor(102, 176, 54));
|
stops << QGradientStop(frame.height() / 2 / frame.height(), QColor(102, 176, 54));
|
||||||
|
|
||||||
//stops << QGradientStop(((frame.height() + h)/2 )/frame.height(), QColor(157, 195, 55));
|
//stops << QGradientStop(((frame.height() + h)/2 )/frame.height(), QColor(157, 195, 55));
|
||||||
stops << QGradientStop(1.0, QColor(215, 215, 215));
|
stops << QGradientStop(1.0, QColor(215, 215, 215));
|
||||||
@ -80,9 +84,9 @@ void LayoutItem::paint(QPainter *painter,
|
|||||||
painter->drawRoundedRect(frame, 10.0, 10.0);
|
painter->drawRoundedRect(frame, 10.0, 10.0);
|
||||||
|
|
||||||
// paint a rect around the pixmap (with gradient)
|
// paint a rect around the pixmap (with gradient)
|
||||||
QPointF pixpos = frame.center() - (QPointF(w, h)/2);
|
QPointF pixpos = frame.center() - (QPointF(w, h) / 2);
|
||||||
QRectF innerFrame(pixpos, QSizeF(w, h));
|
QRectF innerFrame(pixpos, QSizeF(w, h));
|
||||||
innerFrame.adjust(-4, -4, +4, +4);
|
innerFrame.adjust(-4, -4, 4, 4);
|
||||||
gradient.setStart(innerFrame.topLeft());
|
gradient.setStart(innerFrame.topLeft());
|
||||||
gradient.setFinalStop(innerFrame.bottomRight());
|
gradient.setFinalStop(innerFrame.bottomRight());
|
||||||
stops.clear();
|
stops.clear();
|
||||||
|
@ -40,7 +40,9 @@
|
|||||||
|
|
||||||
#ifndef LAYOUTITEM_H
|
#ifndef LAYOUTITEM_H
|
||||||
#define LAYOUTITEM_H
|
#define LAYOUTITEM_H
|
||||||
#include <QtWidgets>
|
|
||||||
|
#include <QGraphicsLayoutItem>
|
||||||
|
#include <QGraphicsItem>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
class LayoutItem : public QGraphicsLayoutItem, public QGraphicsItem
|
class LayoutItem : public QGraphicsLayoutItem, public QGraphicsItem
|
||||||
@ -54,12 +56,11 @@ public:
|
|||||||
|
|
||||||
// Inherited from QGraphicsItem
|
// Inherited from QGraphicsItem
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||||
QWidget *widget = 0);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPixmap *m_pix;
|
QPixmap *m_pix;
|
||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
#endif
|
#endif // LAYOUTITEM_H
|
||||||
|
@ -38,11 +38,12 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
#include <QApplication>
|
||||||
|
#include <QGraphicsView>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
@ -41,6 +41,9 @@
|
|||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "layoutitem.h"
|
#include "layoutitem.h"
|
||||||
|
|
||||||
|
#include <QGraphicsLinearLayout>
|
||||||
|
#include <QGraphicsGridLayout>
|
||||||
|
|
||||||
Window::Window(QGraphicsWidget *parent) : QGraphicsWidget(parent, Qt::Window)
|
Window::Window(QGraphicsWidget *parent) : QGraphicsWidget(parent, Qt::Window)
|
||||||
{
|
{
|
||||||
//! [0]
|
//! [0]
|
||||||
@ -85,6 +88,3 @@ Window::Window(QGraphicsWidget *parent) : QGraphicsWidget(parent, Qt::Window)
|
|||||||
//! [3]
|
//! [3]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
#ifndef WINDOW_H
|
#ifndef WINDOW_H
|
||||||
#define WINDOW_H
|
#define WINDOW_H
|
||||||
|
|
||||||
#include <QtWidgets/QGraphicsWidget>
|
#include <QGraphicsWidget>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
class Window : public QGraphicsWidget {
|
class Window : public QGraphicsWidget {
|
||||||
|
@ -42,8 +42,8 @@
|
|||||||
#ifndef CHIP_H
|
#ifndef CHIP_H
|
||||||
#define CHIP_H
|
#define CHIP_H
|
||||||
|
|
||||||
#include <QtGui/QColor>
|
#include <QColor>
|
||||||
#include <QtWidgets/QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
|
|
||||||
class Chip : public QGraphicsItem
|
class Chip : public QGraphicsItem
|
||||||
{
|
{
|
||||||
@ -60,9 +60,10 @@ protected:
|
|||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int x, y;
|
int x;
|
||||||
|
int y;
|
||||||
QColor color;
|
QColor color;
|
||||||
QVector<QPointF> stuff;
|
QVector<QPointF> stuff;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // CHIP_H
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
Q_INIT_RESOURCE(images);
|
Q_INIT_RESOURCE(images);
|
||||||
|
|
||||||
|
@ -39,11 +39,12 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "chip.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "view.h"
|
#include "view.h"
|
||||||
#include "chip.h"
|
|
||||||
|
|
||||||
#include <QtWidgets>
|
#include <QHBoxLayout>
|
||||||
|
#include <QSplitter>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
@ -42,13 +42,12 @@
|
|||||||
#ifndef MAINWINDOW_H
|
#ifndef MAINWINDOW_H
|
||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <QtWidgets/qwidget.h>
|
#include <QWidget>
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QGraphicsScene)
|
QT_BEGIN_NAMESPACE
|
||||||
QT_FORWARD_DECLARE_CLASS(QGraphicsView)
|
class QGraphicsScene;
|
||||||
QT_FORWARD_DECLARE_CLASS(QLabel)
|
class QSplitter;
|
||||||
QT_FORWARD_DECLARE_CLASS(QSlider)
|
QT_END_NAMESPACE
|
||||||
QT_FORWARD_DECLARE_CLASS(QSplitter)
|
|
||||||
|
|
||||||
class MainWindow : public QWidget
|
class MainWindow : public QWidget
|
||||||
{
|
{
|
||||||
@ -65,4 +64,4 @@ private:
|
|||||||
QSplitter *h2Splitter;
|
QSplitter *h2Splitter;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // MAINWINDOW_H
|
||||||
|
@ -41,7 +41,6 @@
|
|||||||
|
|
||||||
#include "view.h"
|
#include "view.h"
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
#ifndef QT_NO_PRINTER
|
#ifndef QT_NO_PRINTER
|
||||||
#include <QPrinter>
|
#include <QPrinter>
|
||||||
#include <QPrintDialog>
|
#include <QPrintDialog>
|
||||||
@ -178,8 +177,10 @@ View::View(const QString &name, QWidget *parent)
|
|||||||
connect(resetButton, SIGNAL(clicked()), this, SLOT(resetView()));
|
connect(resetButton, SIGNAL(clicked()), this, SLOT(resetView()));
|
||||||
connect(zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix()));
|
connect(zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix()));
|
||||||
connect(rotateSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix()));
|
connect(rotateSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix()));
|
||||||
connect(graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setResetButtonEnabled()));
|
connect(graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)),
|
||||||
connect(graphicsView->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setResetButtonEnabled()));
|
this, SLOT(setResetButtonEnabled()));
|
||||||
|
connect(graphicsView->horizontalScrollBar(), SIGNAL(valueChanged(int)),
|
||||||
|
this, SLOT(setResetButtonEnabled()));
|
||||||
connect(selectModeButton, SIGNAL(toggled(bool)), this, SLOT(togglePointerMode()));
|
connect(selectModeButton, SIGNAL(toggled(bool)), this, SLOT(togglePointerMode()));
|
||||||
connect(dragModeButton, SIGNAL(toggled(bool)), this, SLOT(togglePointerMode()));
|
connect(dragModeButton, SIGNAL(toggled(bool)), this, SLOT(togglePointerMode()));
|
||||||
connect(antialiasButton, SIGNAL(toggled(bool)), this, SLOT(toggleAntialiasing()));
|
connect(antialiasButton, SIGNAL(toggled(bool)), this, SLOT(toggleAntialiasing()));
|
||||||
@ -276,4 +277,3 @@ void View::rotateRight()
|
|||||||
{
|
{
|
||||||
rotateSlider->setValue(rotateSlider->value() + 10);
|
rotateSlider->setValue(rotateSlider->value() + 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,9 +45,11 @@
|
|||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QLabel)
|
QT_BEGIN_NAMESPACE
|
||||||
QT_FORWARD_DECLARE_CLASS(QSlider)
|
class QLabel;
|
||||||
QT_FORWARD_DECLARE_CLASS(QToolButton)
|
class QSlider;
|
||||||
|
class QToolButton;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
class View;
|
class View;
|
||||||
|
|
||||||
@ -101,4 +103,4 @@ private:
|
|||||||
QSlider *rotateSlider;
|
QSlider *rotateSlider;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // VIEW_H
|
||||||
|
@ -38,19 +38,19 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "mouse.h"
|
|
||||||
|
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "mouse.h"
|
||||||
|
|
||||||
static const int MouseCount = 7;
|
static const int MouseCount = 7;
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
|
qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
//! [1]
|
//! [1]
|
||||||
|
@ -38,11 +38,14 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
|
|
||||||
#include "arrow.h"
|
#include "arrow.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#include <QPen>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
const qreal Pi = 3.14;
|
const qreal Pi = 3.14;
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
|
@ -63,22 +63,17 @@ public:
|
|||||||
Arrow(DiagramItem *startItem, DiagramItem *endItem,
|
Arrow(DiagramItem *startItem, DiagramItem *endItem,
|
||||||
QGraphicsItem *parent = 0);
|
QGraphicsItem *parent = 0);
|
||||||
|
|
||||||
int type() const
|
int type() const { return Type; }
|
||||||
{ return Type; }
|
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
QPainterPath shape() const;
|
QPainterPath shape() const;
|
||||||
void setColor(const QColor &color)
|
void setColor(const QColor &color) { myColor = color; }
|
||||||
{ myColor = color; }
|
DiagramItem *startItem() const { return myStartItem; }
|
||||||
DiagramItem *startItem() const
|
DiagramItem *endItem() const { return myEndItem; }
|
||||||
{ return myStartItem; }
|
|
||||||
DiagramItem *endItem() const
|
|
||||||
{ return myEndItem; }
|
|
||||||
|
|
||||||
void updatePosition();
|
void updatePosition();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||||
QWidget *widget = 0);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DiagramItem *myStartItem;
|
DiagramItem *myStartItem;
|
||||||
@ -88,4 +83,4 @@ private:
|
|||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
#endif
|
#endif // ARROW_H
|
||||||
|
@ -38,11 +38,14 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
|
|
||||||
#include "diagramitem.h"
|
#include "diagramitem.h"
|
||||||
#include "arrow.h"
|
#include "arrow.h"
|
||||||
|
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsSceneContextMenuEvent>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
|
DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
|
||||||
QGraphicsItem *parent)
|
QGraphicsItem *parent)
|
||||||
@ -138,8 +141,7 @@ void DiagramItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|||||||
//! [5]
|
//! [5]
|
||||||
|
|
||||||
//! [6]
|
//! [6]
|
||||||
QVariant DiagramItem::itemChange(GraphicsItemChange change,
|
QVariant DiagramItem::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||||
const QVariant &value)
|
|
||||||
{
|
{
|
||||||
if (change == QGraphicsItem::ItemPositionChange) {
|
if (change == QGraphicsItem::ItemPositionChange) {
|
||||||
foreach (Arrow *arrow, arrows) {
|
foreach (Arrow *arrow, arrows) {
|
||||||
|
@ -67,19 +67,15 @@ public:
|
|||||||
enum { Type = UserType + 15 };
|
enum { Type = UserType + 15 };
|
||||||
enum DiagramType { Step, Conditional, StartEnd, Io };
|
enum DiagramType { Step, Conditional, StartEnd, Io };
|
||||||
|
|
||||||
DiagramItem(DiagramType diagramType, QMenu *contextMenu,
|
DiagramItem(DiagramType diagramType, QMenu *contextMenu, QGraphicsItem *parent = 0);
|
||||||
QGraphicsItem *parent = 0);
|
|
||||||
|
|
||||||
void removeArrow(Arrow *arrow);
|
void removeArrow(Arrow *arrow);
|
||||||
void removeArrows();
|
void removeArrows();
|
||||||
DiagramType diagramType() const
|
DiagramType diagramType() const { return myDiagramType; }
|
||||||
{ return myDiagramType; }
|
QPolygonF polygon() const { return myPolygon; }
|
||||||
QPolygonF polygon() const
|
|
||||||
{ return myPolygon; }
|
|
||||||
void addArrow(Arrow *arrow);
|
void addArrow(Arrow *arrow);
|
||||||
QPixmap image() const;
|
QPixmap image() const;
|
||||||
int type() const
|
int type() const { return Type;}
|
||||||
{ return Type;}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
|
||||||
@ -93,4 +89,4 @@ private:
|
|||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
#endif
|
#endif // DIAGRAMITEM_H
|
||||||
|
@ -38,11 +38,12 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
|
|
||||||
#include "diagramscene.h"
|
#include "diagramscene.h"
|
||||||
#include "arrow.h"
|
#include "arrow.h"
|
||||||
|
|
||||||
|
#include <QTextCursor>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent)
|
DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent)
|
||||||
: QGraphicsScene(parent)
|
: QGraphicsScene(parent)
|
||||||
@ -63,8 +64,7 @@ void DiagramScene::setLineColor(const QColor &color)
|
|||||||
{
|
{
|
||||||
myLineColor = color;
|
myLineColor = color;
|
||||||
if (isItemChange(Arrow::Type)) {
|
if (isItemChange(Arrow::Type)) {
|
||||||
Arrow *item =
|
Arrow *item = qgraphicsitem_cast<Arrow *>(selectedItems().first());
|
||||||
qgraphicsitem_cast<Arrow *>(selectedItems().first());
|
|
||||||
item->setColor(myLineColor);
|
item->setColor(myLineColor);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@ -76,8 +76,7 @@ void DiagramScene::setTextColor(const QColor &color)
|
|||||||
{
|
{
|
||||||
myTextColor = color;
|
myTextColor = color;
|
||||||
if (isItemChange(DiagramTextItem::Type)) {
|
if (isItemChange(DiagramTextItem::Type)) {
|
||||||
DiagramTextItem *item =
|
DiagramTextItem *item = qgraphicsitem_cast<DiagramTextItem *>(selectedItems().first());
|
||||||
qgraphicsitem_cast<DiagramTextItem *>(selectedItems().first());
|
|
||||||
item->setDefaultTextColor(myTextColor);
|
item->setDefaultTextColor(myTextColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,8 +87,7 @@ void DiagramScene::setItemColor(const QColor &color)
|
|||||||
{
|
{
|
||||||
myItemColor = color;
|
myItemColor = color;
|
||||||
if (isItemChange(DiagramItem::Type)) {
|
if (isItemChange(DiagramItem::Type)) {
|
||||||
DiagramItem *item =
|
DiagramItem *item = qgraphicsitem_cast<DiagramItem *>(selectedItems().first());
|
||||||
qgraphicsitem_cast<DiagramItem *>(selectedItems().first());
|
|
||||||
item->setBrush(myItemColor);
|
item->setBrush(myItemColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,8 +99,7 @@ void DiagramScene::setFont(const QFont &font)
|
|||||||
myFont = font;
|
myFont = font;
|
||||||
|
|
||||||
if (isItemChange(DiagramTextItem::Type)) {
|
if (isItemChange(DiagramTextItem::Type)) {
|
||||||
QGraphicsTextItem *item =
|
QGraphicsTextItem *item = qgraphicsitem_cast<DiagramTextItem *>(selectedItems().first());
|
||||||
qgraphicsitem_cast<DiagramTextItem *>(selectedItems().first());
|
|
||||||
//At this point the selection can change so the first selected item might not be a DiagramTextItem
|
//At this point the selection can change so the first selected item might not be a DiagramTextItem
|
||||||
if (item)
|
if (item)
|
||||||
item->setFont(myFont);
|
item->setFont(myFont);
|
||||||
@ -209,10 +206,8 @@ void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
|||||||
startItems.first()->type() == DiagramItem::Type &&
|
startItems.first()->type() == DiagramItem::Type &&
|
||||||
endItems.first()->type() == DiagramItem::Type &&
|
endItems.first()->type() == DiagramItem::Type &&
|
||||||
startItems.first() != endItems.first()) {
|
startItems.first() != endItems.first()) {
|
||||||
DiagramItem *startItem =
|
DiagramItem *startItem = qgraphicsitem_cast<DiagramItem *>(startItems.first());
|
||||||
qgraphicsitem_cast<DiagramItem *>(startItems.first());
|
DiagramItem *endItem = qgraphicsitem_cast<DiagramItem *>(endItems.first());
|
||||||
DiagramItem *endItem =
|
|
||||||
qgraphicsitem_cast<DiagramItem *>(endItems.first());
|
|
||||||
Arrow *arrow = new Arrow(startItem, endItem);
|
Arrow *arrow = new Arrow(startItem, endItem);
|
||||||
arrow->setColor(myLineColor);
|
arrow->setColor(myLineColor);
|
||||||
startItem->addArrow(arrow);
|
startItem->addArrow(arrow);
|
||||||
|
@ -41,10 +41,11 @@
|
|||||||
#ifndef DIAGRAMSCENE_H
|
#ifndef DIAGRAMSCENE_H
|
||||||
#define DIAGRAMSCENE_H
|
#define DIAGRAMSCENE_H
|
||||||
|
|
||||||
#include <QGraphicsScene>
|
|
||||||
#include "diagramitem.h"
|
#include "diagramitem.h"
|
||||||
#include "diagramtextitem.h"
|
#include "diagramtextitem.h"
|
||||||
|
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QGraphicsSceneMouseEvent;
|
class QGraphicsSceneMouseEvent;
|
||||||
class QMenu;
|
class QMenu;
|
||||||
@ -64,14 +65,10 @@ public:
|
|||||||
enum Mode { InsertItem, InsertLine, InsertText, MoveItem };
|
enum Mode { InsertItem, InsertLine, InsertText, MoveItem };
|
||||||
|
|
||||||
explicit DiagramScene(QMenu *itemMenu, QObject *parent = 0);
|
explicit DiagramScene(QMenu *itemMenu, QObject *parent = 0);
|
||||||
QFont font() const
|
QFont font() const { return myFont; }
|
||||||
{ return myFont; }
|
QColor textColor() const { return myTextColor; }
|
||||||
QColor textColor() const
|
QColor itemColor() const { return myItemColor; }
|
||||||
{ return myTextColor; }
|
QColor lineColor() const { return myLineColor; }
|
||||||
QColor itemColor() const
|
|
||||||
{ return myItemColor; }
|
|
||||||
QColor lineColor() const
|
|
||||||
{ return myLineColor; }
|
|
||||||
void setLineColor(const QColor &color);
|
void setLineColor(const QColor &color);
|
||||||
void setTextColor(const QColor &color);
|
void setTextColor(const QColor &color);
|
||||||
void setItemColor(const QColor &color);
|
void setItemColor(const QColor &color);
|
||||||
@ -109,4 +106,4 @@ private:
|
|||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
#endif
|
#endif // DIAGRAMSCENE_H
|
||||||
|
@ -38,8 +38,6 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
|
|
||||||
#include "diagramtextitem.h"
|
#include "diagramtextitem.h"
|
||||||
#include "diagramscene.h"
|
#include "diagramscene.h"
|
||||||
|
|
||||||
|
@ -61,8 +61,7 @@ public:
|
|||||||
|
|
||||||
DiagramTextItem(QGraphicsItem *parent = 0);
|
DiagramTextItem(QGraphicsItem *parent = 0);
|
||||||
|
|
||||||
int type() const
|
int type() const { return Type; }
|
||||||
{ return Type; }
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void lostFocus(DiagramTextItem *item);
|
void lostFocus(DiagramTextItem *item);
|
||||||
@ -75,4 +74,4 @@ protected:
|
|||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
#endif
|
#endif // DIAGRAMTEXTITEM_H
|
||||||
|
@ -38,10 +38,10 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
int main(int argv, char *args[])
|
int main(int argv, char *args[])
|
||||||
{
|
{
|
||||||
Q_INIT_RESOURCE(diagramscene);
|
Q_INIT_RESOURCE(diagramscene);
|
||||||
|
@ -38,14 +38,13 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets>
|
#include "arrow.h"
|
||||||
#include <QLabel>
|
|
||||||
|
|
||||||
#include "mainwindow.h"
|
|
||||||
#include "diagramitem.h"
|
#include "diagramitem.h"
|
||||||
#include "diagramscene.h"
|
#include "diagramscene.h"
|
||||||
#include "diagramtextitem.h"
|
#include "diagramtextitem.h"
|
||||||
#include "arrow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
#include <QtWidgets>
|
||||||
|
|
||||||
const int InsertTextButton = 10;
|
const int InsertTextButton = 10;
|
||||||
|
|
||||||
@ -61,9 +60,9 @@ MainWindow::MainWindow()
|
|||||||
connect(scene, SIGNAL(itemInserted(DiagramItem*)),
|
connect(scene, SIGNAL(itemInserted(DiagramItem*)),
|
||||||
this, SLOT(itemInserted(DiagramItem*)));
|
this, SLOT(itemInserted(DiagramItem*)));
|
||||||
connect(scene, SIGNAL(textInserted(QGraphicsTextItem*)),
|
connect(scene, SIGNAL(textInserted(QGraphicsTextItem*)),
|
||||||
this, SLOT(textInserted(QGraphicsTextItem*)));
|
this, SLOT(textInserted(QGraphicsTextItem*)));
|
||||||
connect(scene, SIGNAL(itemSelected(QGraphicsItem*)),
|
connect(scene, SIGNAL(itemSelected(QGraphicsItem*)),
|
||||||
this, SLOT(itemSelected(QGraphicsItem*)));
|
this, SLOT(itemSelected(QGraphicsItem*)));
|
||||||
createToolbars();
|
createToolbars();
|
||||||
|
|
||||||
QHBoxLayout *layout = new QHBoxLayout;
|
QHBoxLayout *layout = new QHBoxLayout;
|
||||||
@ -85,8 +84,8 @@ void MainWindow::backgroundButtonGroupClicked(QAbstractButton *button)
|
|||||||
{
|
{
|
||||||
QList<QAbstractButton *> buttons = backgroundButtonGroup->buttons();
|
QList<QAbstractButton *> buttons = backgroundButtonGroup->buttons();
|
||||||
foreach (QAbstractButton *myButton, buttons) {
|
foreach (QAbstractButton *myButton, buttons) {
|
||||||
if (myButton != button)
|
if (myButton != button)
|
||||||
button->setChecked(false);
|
button->setChecked(false);
|
||||||
}
|
}
|
||||||
QString text = button->text();
|
QString text = button->text();
|
||||||
if (text == tr("Blue Grid"))
|
if (text == tr("Blue Grid"))
|
||||||
@ -108,8 +107,8 @@ void MainWindow::buttonGroupClicked(int id)
|
|||||||
{
|
{
|
||||||
QList<QAbstractButton *> buttons = buttonGroup->buttons();
|
QList<QAbstractButton *> buttons = buttonGroup->buttons();
|
||||||
foreach (QAbstractButton *button, buttons) {
|
foreach (QAbstractButton *button, buttons) {
|
||||||
if (buttonGroup->button(id) != button)
|
if (buttonGroup->button(id) != button)
|
||||||
button->setChecked(false);
|
button->setChecked(false);
|
||||||
}
|
}
|
||||||
if (id == InsertTextButton) {
|
if (id == InsertTextButton) {
|
||||||
scene->setMode(DiagramScene::InsertText);
|
scene->setMode(DiagramScene::InsertText);
|
||||||
@ -134,9 +133,8 @@ void MainWindow::deleteItem()
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (QGraphicsItem *item, scene->selectedItems()) {
|
foreach (QGraphicsItem *item, scene->selectedItems()) {
|
||||||
if (item->type() == DiagramItem::Type) {
|
if (item->type() == DiagramItem::Type)
|
||||||
qgraphicsitem_cast<DiagramItem *>(item)->removeArrows();
|
qgraphicsitem_cast<DiagramItem *>(item)->removeArrows();
|
||||||
}
|
|
||||||
scene->removeItem(item);
|
scene->removeItem(item);
|
||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
@ -161,8 +159,7 @@ void MainWindow::bringToFront()
|
|||||||
|
|
||||||
qreal zValue = 0;
|
qreal zValue = 0;
|
||||||
foreach (QGraphicsItem *item, overlapItems) {
|
foreach (QGraphicsItem *item, overlapItems) {
|
||||||
if (item->zValue() >= zValue &&
|
if (item->zValue() >= zValue && item->type() == DiagramItem::Type)
|
||||||
item->type() == DiagramItem::Type)
|
|
||||||
zValue = item->zValue() + 0.1;
|
zValue = item->zValue() + 0.1;
|
||||||
}
|
}
|
||||||
selectedItem->setZValue(zValue);
|
selectedItem->setZValue(zValue);
|
||||||
@ -180,8 +177,7 @@ void MainWindow::sendToBack()
|
|||||||
|
|
||||||
qreal zValue = 0;
|
qreal zValue = 0;
|
||||||
foreach (QGraphicsItem *item, overlapItems) {
|
foreach (QGraphicsItem *item, overlapItems) {
|
||||||
if (item->zValue() <= zValue &&
|
if (item->zValue() <= zValue && item->type() == DiagramItem::Type)
|
||||||
item->type() == DiagramItem::Type)
|
|
||||||
zValue = item->zValue() - 0.1;
|
zValue = item->zValue() - 0.1;
|
||||||
}
|
}
|
||||||
selectedItem->setZValue(zValue);
|
selectedItem->setZValue(zValue);
|
||||||
@ -235,8 +231,8 @@ void MainWindow::textColorChanged()
|
|||||||
{
|
{
|
||||||
textAction = qobject_cast<QAction *>(sender());
|
textAction = qobject_cast<QAction *>(sender());
|
||||||
fontColorToolButton->setIcon(createColorToolButtonIcon(
|
fontColorToolButton->setIcon(createColorToolButtonIcon(
|
||||||
":/images/textpointer.png",
|
":/images/textpointer.png",
|
||||||
qvariant_cast<QColor>(textAction->data())));
|
qvariant_cast<QColor>(textAction->data())));
|
||||||
textButtonTriggered();
|
textButtonTriggered();
|
||||||
}
|
}
|
||||||
//! [12]
|
//! [12]
|
||||||
@ -246,8 +242,8 @@ void MainWindow::itemColorChanged()
|
|||||||
{
|
{
|
||||||
fillAction = qobject_cast<QAction *>(sender());
|
fillAction = qobject_cast<QAction *>(sender());
|
||||||
fillColorToolButton->setIcon(createColorToolButtonIcon(
|
fillColorToolButton->setIcon(createColorToolButtonIcon(
|
||||||
":/images/floodfill.png",
|
":/images/floodfill.png",
|
||||||
qvariant_cast<QColor>(fillAction->data())));
|
qvariant_cast<QColor>(fillAction->data())));
|
||||||
fillButtonTriggered();
|
fillButtonTriggered();
|
||||||
}
|
}
|
||||||
//! [13]
|
//! [13]
|
||||||
@ -257,8 +253,8 @@ void MainWindow::lineColorChanged()
|
|||||||
{
|
{
|
||||||
lineAction = qobject_cast<QAction *>(sender());
|
lineAction = qobject_cast<QAction *>(sender());
|
||||||
lineColorToolButton->setIcon(createColorToolButtonIcon(
|
lineColorToolButton->setIcon(createColorToolButtonIcon(
|
||||||
":/images/linecolor.png",
|
":/images/linecolor.png",
|
||||||
qvariant_cast<QColor>(lineAction->data())));
|
qvariant_cast<QColor>(lineAction->data())));
|
||||||
lineButtonTriggered();
|
lineButtonTriggered();
|
||||||
}
|
}
|
||||||
//! [14]
|
//! [14]
|
||||||
@ -329,12 +325,9 @@ void MainWindow::createToolBox()
|
|||||||
connect(buttonGroup, SIGNAL(buttonClicked(int)),
|
connect(buttonGroup, SIGNAL(buttonClicked(int)),
|
||||||
this, SLOT(buttonGroupClicked(int)));
|
this, SLOT(buttonGroupClicked(int)));
|
||||||
QGridLayout *layout = new QGridLayout;
|
QGridLayout *layout = new QGridLayout;
|
||||||
layout->addWidget(createCellWidget(tr("Conditional"),
|
layout->addWidget(createCellWidget(tr("Conditional"), DiagramItem::Conditional), 0, 0);
|
||||||
DiagramItem::Conditional), 0, 0);
|
layout->addWidget(createCellWidget(tr("Process"), DiagramItem::Step),0, 1);
|
||||||
layout->addWidget(createCellWidget(tr("Process"),
|
layout->addWidget(createCellWidget(tr("Input/Output"), DiagramItem::Io), 1, 0);
|
||||||
DiagramItem::Step),0, 1);
|
|
||||||
layout->addWidget(createCellWidget(tr("Input/Output"),
|
|
||||||
DiagramItem::Io), 1, 0);
|
|
||||||
//! [21]
|
//! [21]
|
||||||
|
|
||||||
QToolButton *textButton = new QToolButton;
|
QToolButton *textButton = new QToolButton;
|
||||||
@ -361,13 +354,13 @@ void MainWindow::createToolBox()
|
|||||||
|
|
||||||
QGridLayout *backgroundLayout = new QGridLayout;
|
QGridLayout *backgroundLayout = new QGridLayout;
|
||||||
backgroundLayout->addWidget(createBackgroundCellWidget(tr("Blue Grid"),
|
backgroundLayout->addWidget(createBackgroundCellWidget(tr("Blue Grid"),
|
||||||
":/images/background1.png"), 0, 0);
|
":/images/background1.png"), 0, 0);
|
||||||
backgroundLayout->addWidget(createBackgroundCellWidget(tr("White Grid"),
|
backgroundLayout->addWidget(createBackgroundCellWidget(tr("White Grid"),
|
||||||
":/images/background2.png"), 0, 1);
|
":/images/background2.png"), 0, 1);
|
||||||
backgroundLayout->addWidget(createBackgroundCellWidget(tr("Gray Grid"),
|
backgroundLayout->addWidget(createBackgroundCellWidget(tr("Gray Grid"),
|
||||||
":/images/background3.png"), 1, 0);
|
":/images/background3.png"), 1, 0);
|
||||||
backgroundLayout->addWidget(createBackgroundCellWidget(tr("No Grid"),
|
backgroundLayout->addWidget(createBackgroundCellWidget(tr("No Grid"),
|
||||||
":/images/background4.png"), 1, 1);
|
":/images/background4.png"), 1, 1);
|
||||||
|
|
||||||
backgroundLayout->setRowStretch(2, 10);
|
backgroundLayout->setRowStretch(2, 10);
|
||||||
backgroundLayout->setColumnStretch(2, 10);
|
backgroundLayout->setColumnStretch(2, 10);
|
||||||
@ -392,23 +385,18 @@ void MainWindow::createActions()
|
|||||||
tr("Bring to &Front"), this);
|
tr("Bring to &Front"), this);
|
||||||
toFrontAction->setShortcut(tr("Ctrl+F"));
|
toFrontAction->setShortcut(tr("Ctrl+F"));
|
||||||
toFrontAction->setStatusTip(tr("Bring item to front"));
|
toFrontAction->setStatusTip(tr("Bring item to front"));
|
||||||
connect(toFrontAction, SIGNAL(triggered()),
|
connect(toFrontAction, SIGNAL(triggered()), this, SLOT(bringToFront()));
|
||||||
this, SLOT(bringToFront()));
|
|
||||||
//! [23]
|
//! [23]
|
||||||
|
|
||||||
sendBackAction = new QAction(QIcon(":/images/sendtoback.png"),
|
sendBackAction = new QAction(QIcon(":/images/sendtoback.png"), tr("Send to &Back"), this);
|
||||||
tr("Send to &Back"), this);
|
|
||||||
sendBackAction->setShortcut(tr("Ctrl+B"));
|
sendBackAction->setShortcut(tr("Ctrl+B"));
|
||||||
sendBackAction->setStatusTip(tr("Send item to back"));
|
sendBackAction->setStatusTip(tr("Send item to back"));
|
||||||
connect(sendBackAction, SIGNAL(triggered()),
|
connect(sendBackAction, SIGNAL(triggered()), this, SLOT(sendToBack()));
|
||||||
this, SLOT(sendToBack()));
|
|
||||||
|
|
||||||
deleteAction = new QAction(QIcon(":/images/delete.png"),
|
deleteAction = new QAction(QIcon(":/images/delete.png"), tr("&Delete"), this);
|
||||||
tr("&Delete"), this);
|
|
||||||
deleteAction->setShortcut(tr("Delete"));
|
deleteAction->setShortcut(tr("Delete"));
|
||||||
deleteAction->setStatusTip(tr("Delete item from diagram"));
|
deleteAction->setStatusTip(tr("Delete item from diagram"));
|
||||||
connect(deleteAction, SIGNAL(triggered()),
|
connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem()));
|
||||||
this, SLOT(deleteItem()));
|
|
||||||
|
|
||||||
exitAction = new QAction(tr("E&xit"), this);
|
exitAction = new QAction(tr("E&xit"), this);
|
||||||
exitAction->setShortcuts(QKeySequence::Quit);
|
exitAction->setShortcuts(QKeySequence::Quit);
|
||||||
@ -420,27 +408,21 @@ void MainWindow::createActions()
|
|||||||
QPixmap pixmap(":/images/bold.png");
|
QPixmap pixmap(":/images/bold.png");
|
||||||
boldAction->setIcon(QIcon(pixmap));
|
boldAction->setIcon(QIcon(pixmap));
|
||||||
boldAction->setShortcut(tr("Ctrl+B"));
|
boldAction->setShortcut(tr("Ctrl+B"));
|
||||||
connect(boldAction, SIGNAL(triggered()),
|
connect(boldAction, SIGNAL(triggered()), this, SLOT(handleFontChange()));
|
||||||
this, SLOT(handleFontChange()));
|
|
||||||
|
|
||||||
italicAction = new QAction(QIcon(":/images/italic.png"),
|
italicAction = new QAction(QIcon(":/images/italic.png"), tr("Italic"), this);
|
||||||
tr("Italic"), this);
|
|
||||||
italicAction->setCheckable(true);
|
italicAction->setCheckable(true);
|
||||||
italicAction->setShortcut(tr("Ctrl+I"));
|
italicAction->setShortcut(tr("Ctrl+I"));
|
||||||
connect(italicAction, SIGNAL(triggered()),
|
connect(italicAction, SIGNAL(triggered()), this, SLOT(handleFontChange()));
|
||||||
this, SLOT(handleFontChange()));
|
|
||||||
|
|
||||||
underlineAction = new QAction(QIcon(":/images/underline.png"),
|
underlineAction = new QAction(QIcon(":/images/underline.png"), tr("Underline"), this);
|
||||||
tr("Underline"), this);
|
|
||||||
underlineAction->setCheckable(true);
|
underlineAction->setCheckable(true);
|
||||||
underlineAction->setShortcut(tr("Ctrl+U"));
|
underlineAction->setShortcut(tr("Ctrl+U"));
|
||||||
connect(underlineAction, SIGNAL(triggered()),
|
connect(underlineAction, SIGNAL(triggered()), this, SLOT(handleFontChange()));
|
||||||
this, SLOT(handleFontChange()));
|
|
||||||
|
|
||||||
aboutAction = new QAction(tr("A&bout"), this);
|
aboutAction = new QAction(tr("A&bout"), this);
|
||||||
aboutAction->setShortcut(tr("Ctrl+B"));
|
aboutAction->setShortcut(tr("Ctrl+B"));
|
||||||
connect(aboutAction, SIGNAL(triggered()),
|
connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
|
||||||
this, SLOT(about()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [24]
|
//! [24]
|
||||||
@ -484,11 +466,9 @@ void MainWindow::createToolbars()
|
|||||||
|
|
||||||
fontColorToolButton = new QToolButton;
|
fontColorToolButton = new QToolButton;
|
||||||
fontColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
|
fontColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
|
||||||
fontColorToolButton->setMenu(createColorMenu(SLOT(textColorChanged()),
|
fontColorToolButton->setMenu(createColorMenu(SLOT(textColorChanged()), Qt::black));
|
||||||
Qt::black));
|
|
||||||
textAction = fontColorToolButton->menu()->defaultAction();
|
textAction = fontColorToolButton->menu()->defaultAction();
|
||||||
fontColorToolButton->setIcon(createColorToolButtonIcon(
|
fontColorToolButton->setIcon(createColorToolButtonIcon(":/images/textpointer.png", Qt::black));
|
||||||
":/images/textpointer.png", Qt::black));
|
|
||||||
fontColorToolButton->setAutoFillBackground(true);
|
fontColorToolButton->setAutoFillBackground(true);
|
||||||
connect(fontColorToolButton, SIGNAL(clicked()),
|
connect(fontColorToolButton, SIGNAL(clicked()),
|
||||||
this, SLOT(textButtonTriggered()));
|
this, SLOT(textButtonTriggered()));
|
||||||
@ -496,22 +476,20 @@ void MainWindow::createToolbars()
|
|||||||
//! [26]
|
//! [26]
|
||||||
fillColorToolButton = new QToolButton;
|
fillColorToolButton = new QToolButton;
|
||||||
fillColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
|
fillColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
|
||||||
fillColorToolButton->setMenu(createColorMenu(SLOT(itemColorChanged()),
|
fillColorToolButton->setMenu(createColorMenu(SLOT(itemColorChanged()), Qt::white));
|
||||||
Qt::white));
|
|
||||||
fillAction = fillColorToolButton->menu()->defaultAction();
|
fillAction = fillColorToolButton->menu()->defaultAction();
|
||||||
fillColorToolButton->setIcon(createColorToolButtonIcon(
|
fillColorToolButton->setIcon(createColorToolButtonIcon(
|
||||||
":/images/floodfill.png", Qt::white));
|
":/images/floodfill.png", Qt::white));
|
||||||
connect(fillColorToolButton, SIGNAL(clicked()),
|
connect(fillColorToolButton, SIGNAL(clicked()),
|
||||||
this, SLOT(fillButtonTriggered()));
|
this, SLOT(fillButtonTriggered()));
|
||||||
//! [26]
|
//! [26]
|
||||||
|
|
||||||
lineColorToolButton = new QToolButton;
|
lineColorToolButton = new QToolButton;
|
||||||
lineColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
|
lineColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
|
||||||
lineColorToolButton->setMenu(createColorMenu(SLOT(lineColorChanged()),
|
lineColorToolButton->setMenu(createColorMenu(SLOT(lineColorChanged()), Qt::black));
|
||||||
Qt::black));
|
|
||||||
lineAction = lineColorToolButton->menu()->defaultAction();
|
lineAction = lineColorToolButton->menu()->defaultAction();
|
||||||
lineColorToolButton->setIcon(createColorToolButtonIcon(
|
lineColorToolButton->setIcon(createColorToolButtonIcon(
|
||||||
":/images/linecolor.png", Qt::black));
|
":/images/linecolor.png", Qt::black));
|
||||||
connect(lineColorToolButton, SIGNAL(clicked()),
|
connect(lineColorToolButton, SIGNAL(clicked()),
|
||||||
this, SLOT(lineButtonTriggered()));
|
this, SLOT(lineButtonTriggered()));
|
||||||
|
|
||||||
@ -537,8 +515,7 @@ void MainWindow::createToolbars()
|
|||||||
|
|
||||||
pointerTypeGroup = new QButtonGroup(this);
|
pointerTypeGroup = new QButtonGroup(this);
|
||||||
pointerTypeGroup->addButton(pointerButton, int(DiagramScene::MoveItem));
|
pointerTypeGroup->addButton(pointerButton, int(DiagramScene::MoveItem));
|
||||||
pointerTypeGroup->addButton(linePointerButton,
|
pointerTypeGroup->addButton(linePointerButton, int(DiagramScene::InsertLine));
|
||||||
int(DiagramScene::InsertLine));
|
|
||||||
connect(pointerTypeGroup, SIGNAL(buttonClicked(int)),
|
connect(pointerTypeGroup, SIGNAL(buttonClicked(int)),
|
||||||
this, SLOT(pointerGroupClicked(int)));
|
this, SLOT(pointerGroupClicked(int)));
|
||||||
|
|
||||||
@ -559,8 +536,7 @@ void MainWindow::createToolbars()
|
|||||||
//! [27]
|
//! [27]
|
||||||
|
|
||||||
//! [28]
|
//! [28]
|
||||||
QWidget *MainWindow::createBackgroundCellWidget(const QString &text,
|
QWidget *MainWindow::createBackgroundCellWidget(const QString &text, const QString &image)
|
||||||
const QString &image)
|
|
||||||
{
|
{
|
||||||
QToolButton *button = new QToolButton;
|
QToolButton *button = new QToolButton;
|
||||||
button->setText(text);
|
button->setText(text);
|
||||||
@ -581,8 +557,7 @@ QWidget *MainWindow::createBackgroundCellWidget(const QString &text,
|
|||||||
//! [28]
|
//! [28]
|
||||||
|
|
||||||
//! [29]
|
//! [29]
|
||||||
QWidget *MainWindow::createCellWidget(const QString &text,
|
QWidget *MainWindow::createCellWidget(const QString &text, DiagramItem::DiagramType type)
|
||||||
DiagramItem::DiagramType type)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
DiagramItem item(type, itemMenu);
|
DiagramItem item(type, itemMenu);
|
||||||
@ -619,20 +594,17 @@ QMenu *MainWindow::createColorMenu(const char *slot, QColor defaultColor)
|
|||||||
QAction *action = new QAction(names.at(i), this);
|
QAction *action = new QAction(names.at(i), this);
|
||||||
action->setData(colors.at(i));
|
action->setData(colors.at(i));
|
||||||
action->setIcon(createColorIcon(colors.at(i)));
|
action->setIcon(createColorIcon(colors.at(i)));
|
||||||
connect(action, SIGNAL(triggered()),
|
connect(action, SIGNAL(triggered()), this, slot);
|
||||||
this, slot);
|
|
||||||
colorMenu->addAction(action);
|
colorMenu->addAction(action);
|
||||||
if (colors.at(i) == defaultColor) {
|
if (colors.at(i) == defaultColor)
|
||||||
colorMenu->setDefaultAction(action);
|
colorMenu->setDefaultAction(action);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return colorMenu;
|
return colorMenu;
|
||||||
}
|
}
|
||||||
//! [30]
|
//! [30]
|
||||||
|
|
||||||
//! [31]
|
//! [31]
|
||||||
QIcon MainWindow::createColorToolButtonIcon(const QString &imageFile,
|
QIcon MainWindow::createColorToolButtonIcon(const QString &imageFile, QColor color)
|
||||||
QColor color)
|
|
||||||
{
|
{
|
||||||
QPixmap pixmap(50, 80);
|
QPixmap pixmap(50, 80);
|
||||||
pixmap.fill(Qt::transparent);
|
pixmap.fill(Qt::transparent);
|
||||||
|
@ -41,10 +41,10 @@
|
|||||||
#ifndef MAINWINDOW_H
|
#ifndef MAINWINDOW_H
|
||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
|
||||||
|
|
||||||
#include "diagramitem.h"
|
#include "diagramitem.h"
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
|
||||||
class DiagramScene;
|
class DiagramScene;
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@ -147,4 +147,4 @@ private:
|
|||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
#endif
|
#endif // MAINWINDOW_H
|
||||||
|
@ -38,13 +38,13 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QPainter>
|
|
||||||
|
|
||||||
#include "edge.h"
|
#include "edge.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
static const double Pi = 3.14159265358979323846264338327950288419717;
|
static const double Pi = 3.14159265358979323846264338327950288419717;
|
||||||
static double TwoPi = 2.0 * Pi;
|
static double TwoPi = 2.0 * Pi;
|
||||||
|
|
||||||
|
@ -72,4 +72,4 @@ private:
|
|||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
#endif
|
#endif // EDGE_H
|
||||||
|
@ -42,10 +42,10 @@
|
|||||||
#include "edge.h"
|
#include "edge.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#include <QKeyEvent>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
GraphWidget::GraphWidget(QWidget *parent)
|
GraphWidget::GraphWidget(QWidget *parent)
|
||||||
: QGraphicsView(parent), timerId(0)
|
: QGraphicsView(parent), timerId(0)
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
#ifndef GRAPHWIDGET_H
|
#ifndef GRAPHWIDGET_H
|
||||||
#define GRAPHWIDGET_H
|
#define GRAPHWIDGET_H
|
||||||
|
|
||||||
#include <QtWidgets/QGraphicsView>
|
#include <QGraphicsView>
|
||||||
|
|
||||||
class Node;
|
class Node;
|
||||||
|
|
||||||
@ -74,4 +74,4 @@ private:
|
|||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
#endif
|
#endif // GRAPHWIDGET_H
|
||||||
|
@ -38,10 +38,12 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
|
|
||||||
#include "graphwidget.h"
|
#include "graphwidget.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QTime>
|
||||||
|
#include <QMainWindow>
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
@ -38,15 +38,15 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "edge.h"
|
||||||
|
#include "node.h"
|
||||||
|
#include "graphwidget.h"
|
||||||
|
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QStyleOption>
|
#include <QStyleOption>
|
||||||
|
|
||||||
#include "edge.h"
|
|
||||||
#include "node.h"
|
|
||||||
#include "graphwidget.h"
|
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
Node::Node(GraphWidget *graphWidget)
|
Node::Node(GraphWidget *graphWidget)
|
||||||
: graph(graphWidget)
|
: graph(graphWidget)
|
||||||
@ -142,8 +142,7 @@ bool Node::advance()
|
|||||||
QRectF Node::boundingRect() const
|
QRectF Node::boundingRect() const
|
||||||
{
|
{
|
||||||
qreal adjust = 2;
|
qreal adjust = 2;
|
||||||
return QRectF( -10 - adjust, -10 - adjust,
|
return QRectF( -10 - adjust, -10 - adjust, 23 + adjust, 23 + adjust);
|
||||||
23 + adjust, 23 + adjust);
|
|
||||||
}
|
}
|
||||||
//! [8]
|
//! [8]
|
||||||
|
|
||||||
|
@ -82,4 +82,4 @@ private:
|
|||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
#endif
|
#endif // NODE_H
|
||||||
|
@ -41,7 +41,9 @@
|
|||||||
|
|
||||||
#include "customproxy.h"
|
#include "customproxy.h"
|
||||||
|
|
||||||
#include <QtWidgets>
|
#include <QStyleOptionGraphicsItem>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
|
||||||
CustomProxy::CustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags)
|
CustomProxy::CustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags)
|
||||||
: QGraphicsProxyWidget(parent, wFlags), popupShown(false), currentPopup(0)
|
: QGraphicsProxyWidget(parent, wFlags), popupShown(false), currentPopup(0)
|
||||||
@ -95,13 +97,16 @@ void CustomProxy::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|||||||
void CustomProxy::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
void CustomProxy::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
QGraphicsProxyWidget::hoverLeaveEvent(event);
|
QGraphicsProxyWidget::hoverLeaveEvent(event);
|
||||||
if (!popupShown && (timeLine->direction() != QTimeLine::Backward || timeLine->currentValue() != 0))
|
if (!popupShown
|
||||||
|
&& (timeLine->direction() != QTimeLine::Backward || timeLine->currentValue() != 0)) {
|
||||||
zoomOut();
|
zoomOut();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CustomProxy::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
bool CustomProxy::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
||||||
{
|
{
|
||||||
if (watched->isWindow() && (event->type() == QEvent::UngrabMouse || event->type() == QEvent::GrabMouse)) {
|
if (watched->isWindow()
|
||||||
|
&& (event->type() == QEvent::UngrabMouse || event->type() == QEvent::GrabMouse)) {
|
||||||
popupShown = watched->isVisible();
|
popupShown = watched->isVisible();
|
||||||
if (!popupShown && !isUnderMouse())
|
if (!popupShown && !isUnderMouse())
|
||||||
zoomOut();
|
zoomOut();
|
||||||
@ -142,10 +147,10 @@ void CustomProxy::updateStep(qreal step)
|
|||||||
void CustomProxy::stateChanged(QTimeLine::State state)
|
void CustomProxy::stateChanged(QTimeLine::State state)
|
||||||
{
|
{
|
||||||
if (state == QTimeLine::Running) {
|
if (state == QTimeLine::Running) {
|
||||||
if (timeLine->direction() == QTimeLine::Forward)
|
if (timeLine->direction() == QTimeLine::Forward)
|
||||||
setCacheMode(ItemCoordinateCache);
|
setCacheMode(ItemCoordinateCache);
|
||||||
} else if (state == QTimeLine::NotRunning) {
|
} else if (state == QTimeLine::NotRunning) {
|
||||||
if (timeLine->direction() == QTimeLine::Backward)
|
if (timeLine->direction() == QTimeLine::Backward)
|
||||||
setCacheMode(DeviceCoordinateCache);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,12 +42,13 @@
|
|||||||
#ifndef CUSTOMPROXY_H
|
#ifndef CUSTOMPROXY_H
|
||||||
#define CUSTOMPROXY_H
|
#define CUSTOMPROXY_H
|
||||||
|
|
||||||
#include <QtCore/qtimeline.h>
|
#include <QTimeLine>
|
||||||
#include <QtWidgets/qgraphicsproxywidget.h>
|
#include <QGraphicsProxyWidget>
|
||||||
|
|
||||||
class CustomProxy : public QGraphicsProxyWidget
|
class CustomProxy : public QGraphicsProxyWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
|
explicit CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
|
||||||
|
|
||||||
@ -73,4 +74,4 @@ private:
|
|||||||
QGraphicsItem *currentPopup;
|
QGraphicsItem *currentPopup;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // CUSTOMPROXY_H
|
||||||
|
@ -42,12 +42,12 @@
|
|||||||
#include "embeddeddialog.h"
|
#include "embeddeddialog.h"
|
||||||
#include "ui_embeddeddialog.h"
|
#include "ui_embeddeddialog.h"
|
||||||
|
|
||||||
#include <QtWidgets>
|
#include <QStyleFactory>
|
||||||
|
|
||||||
EmbeddedDialog::EmbeddedDialog(QWidget *parent)
|
EmbeddedDialog::EmbeddedDialog(QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
|
, ui(new Ui::EmbeddedDialog)
|
||||||
{
|
{
|
||||||
ui = new Ui_embeddedDialog;
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->layoutDirection->setCurrentIndex(layoutDirection() != Qt::LeftToRight);
|
ui->layoutDirection->setCurrentIndex(layoutDirection() != Qt::LeftToRight);
|
||||||
|
|
||||||
|
@ -42,13 +42,18 @@
|
|||||||
#ifndef EMBEDDEDDIALOG_H
|
#ifndef EMBEDDEDDIALOG_H
|
||||||
#define EMBEDDEDDIALOG_H
|
#define EMBEDDEDDIALOG_H
|
||||||
|
|
||||||
#include <QtWidgets/qdialog.h>
|
#include <QDialog>
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(Ui_embeddedDialog);
|
QT_BEGIN_NAMESPACE
|
||||||
|
namespace Ui {
|
||||||
|
class EmbeddedDialog;
|
||||||
|
}
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
class EmbeddedDialog : public QDialog
|
class EmbeddedDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EmbeddedDialog(QWidget *parent = 0);
|
EmbeddedDialog(QWidget *parent = 0);
|
||||||
~EmbeddedDialog();
|
~EmbeddedDialog();
|
||||||
@ -60,7 +65,7 @@ private slots:
|
|||||||
void styleChanged(const QString &styleName);
|
void styleChanged(const QString &styleName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui_embeddedDialog *ui;
|
Ui::EmbeddedDialog *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // EMBEDDEDDIALOG_H
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
<ui version="4.0" >
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<class>embeddedDialog</class>
|
<ui version="4.0">
|
||||||
<widget class="QDialog" name="embeddedDialog" >
|
<class>EmbeddedDialog</class>
|
||||||
<property name="geometry" >
|
<widget class="QDialog" name="EmbeddedDialog">
|
||||||
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
@ -9,73 +10,73 @@
|
|||||||
<height>134</height>
|
<height>134</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle" >
|
<property name="windowTitle">
|
||||||
<string>Embedded Dialog</string>
|
<string>Embedded Dialog</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QFormLayout" name="formLayout" >
|
<layout class="QFormLayout" name="formLayout">
|
||||||
<item row="0" column="0" >
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label" >
|
<widget class="QLabel" name="label">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>Layout Direction:</string>
|
<string>Layout Direction:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="buddy" >
|
<property name="buddy">
|
||||||
<cstring>layoutDirection</cstring>
|
<cstring>layoutDirection</cstring>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1" >
|
<item row="0" column="1">
|
||||||
<widget class="QComboBox" name="layoutDirection" >
|
<widget class="QComboBox" name="layoutDirection">
|
||||||
<item>
|
<item>
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>Left to Right</string>
|
<string>Left to Right</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>Right to Left</string>
|
<string>Right to Left</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0" >
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label_2" >
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>Select Font:</string>
|
<string>Select Font:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="buddy" >
|
<property name="buddy">
|
||||||
<cstring>fontComboBox</cstring>
|
<cstring>fontComboBox</cstring>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1" >
|
<item row="1" column="1">
|
||||||
<widget class="QFontComboBox" name="fontComboBox" />
|
<widget class="QFontComboBox" name="fontComboBox"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0" >
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="label_3" >
|
<widget class="QLabel" name="label_3">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>Style:</string>
|
<string>Style:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="buddy" >
|
<property name="buddy">
|
||||||
<cstring>style</cstring>
|
<cstring>style</cstring>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1" >
|
<item row="2" column="1">
|
||||||
<widget class="QComboBox" name="style" />
|
<widget class="QComboBox" name="style"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0" >
|
<item row="3" column="0">
|
||||||
<widget class="QLabel" name="label_4" >
|
<widget class="QLabel" name="label_4">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>Layout spacing:</string>
|
<string>Layout spacing:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="buddy" >
|
<property name="buddy">
|
||||||
<cstring>spacing</cstring>
|
<cstring>spacing</cstring>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1" >
|
<item row="3" column="1">
|
||||||
<widget class="QSlider" name="spacing" >
|
<widget class="QSlider" name="spacing">
|
||||||
<property name="orientation" >
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -42,7 +42,9 @@
|
|||||||
#include "customproxy.h"
|
#include "customproxy.h"
|
||||||
#include "embeddeddialog.h"
|
#include "embeddeddialog.h"
|
||||||
|
|
||||||
#include <QtWidgets>
|
#include <QApplication>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsView>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -39,8 +39,10 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "flowlayout.h"
|
#include "flowlayout.h"
|
||||||
#include <QtWidgets/qwidget.h>
|
|
||||||
#include <QtCore/qmath.h>
|
#include <qmath.h>
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
FlowLayout::FlowLayout()
|
FlowLayout::FlowLayout()
|
||||||
{
|
{
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets/qgraphicslayout.h>
|
#include <QGraphicsLayout>
|
||||||
|
|
||||||
class FlowLayout : public QGraphicsLayout
|
class FlowLayout : public QGraphicsLayout
|
||||||
{
|
{
|
||||||
|
@ -38,10 +38,13 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets>
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
#include <QApplication>
|
||||||
|
#include <QGraphicsView>
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
@ -38,17 +38,18 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets/qgraphicsproxywidget.h>
|
|
||||||
#include <QtWidgets/qlabel.h>
|
|
||||||
#include "flowlayout.h"
|
#include "flowlayout.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
|
#include <QGraphicsProxyWidget>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
Window::Window()
|
Window::Window()
|
||||||
: QGraphicsWidget(0, Qt::Window)
|
: QGraphicsWidget(0, Qt::Window)
|
||||||
{
|
{
|
||||||
FlowLayout *lay = new FlowLayout;
|
FlowLayout *lay = new FlowLayout;
|
||||||
QLatin1String wiseWords("I am not bothered by the fact that I am unknown."
|
QLatin1String wiseWords("I am not bothered by the fact that I am unknown."
|
||||||
" I am bothered when I do not know others. (Confucius)");
|
" I am bothered when I do not know others. (Confucius)");
|
||||||
QString sentence(wiseWords);
|
QString sentence(wiseWords);
|
||||||
QStringList words = sentence.split(QLatin1Char(' '), QString::SkipEmptyParts);
|
QStringList words = sentence.split(QLatin1Char(' '), QString::SkipEmptyParts);
|
||||||
for (int i = 0; i < words.count(); ++i) {
|
for (int i = 0; i < words.count(); ++i) {
|
||||||
|
@ -38,10 +38,12 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtWidgets/qgraphicswidget.h>
|
#include <QGraphicsWidget>
|
||||||
|
|
||||||
class Window : public QGraphicsWidget {
|
class Window : public QGraphicsWidget
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Window();
|
Window();
|
||||||
};
|
};
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
#include "flippablepad.h"
|
#include "flippablepad.h"
|
||||||
|
|
||||||
#include <QtWidgets/QtWidgets>
|
#include <QDirIterator>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
static QRectF boundsFromSize(const QSize &size)
|
static QRectF boundsFromSize(const QSize &size)
|
||||||
|
@ -42,9 +42,8 @@
|
|||||||
#include "padnavigator.h"
|
#include "padnavigator.h"
|
||||||
#include "splashitem.h"
|
#include "splashitem.h"
|
||||||
|
|
||||||
#include <QtWidgets/QtWidgets>
|
|
||||||
#ifndef QT_NO_OPENGL
|
#ifndef QT_NO_OPENGL
|
||||||
#include <QtOpenGL/QtOpenGL>
|
#include <QtOpenGL>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
@ -90,8 +89,7 @@ PadNavigator::PadNavigator(const QSize &size, QWidget *parent)
|
|||||||
|
|
||||||
//! [4]
|
//! [4]
|
||||||
// Selection item
|
// Selection item
|
||||||
RoundRectItem *selectionItem = new RoundRectItem(QRectF(-60, -60, 120, 120),
|
RoundRectItem *selectionItem = new RoundRectItem(QRectF(-60, -60, 120, 120), Qt::gray, pad);
|
||||||
Qt::gray, pad);
|
|
||||||
selectionItem->setZValue(0.5);
|
selectionItem->setZValue(0.5);
|
||||||
//! [4]
|
//! [4]
|
||||||
|
|
||||||
@ -288,7 +286,9 @@ PadNavigator::PadNavigator(const QSize &size, QWidget *parent)
|
|||||||
setMinimumSize(50, 50);
|
setMinimumSize(50, 50);
|
||||||
setViewportUpdateMode(FullViewportUpdate);
|
setViewportUpdateMode(FullViewportUpdate);
|
||||||
setCacheMode(CacheBackground);
|
setCacheMode(CacheBackground);
|
||||||
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing);
|
setRenderHints(QPainter::Antialiasing
|
||||||
|
| QPainter::SmoothPixmapTransform
|
||||||
|
| QPainter::TextAntialiasing);
|
||||||
#ifndef QT_NO_OPENGL
|
#ifndef QT_NO_OPENGL
|
||||||
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
|
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
|
||||||
#endif
|
#endif
|
||||||
|
@ -45,11 +45,8 @@
|
|||||||
#include "ui_form.h"
|
#include "ui_form.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class QState;
|
class QState;
|
||||||
class QStateMachine;
|
class QStateMachine;
|
||||||
class Ui_Form;
|
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
@ -63,7 +60,7 @@ protected:
|
|||||||
void resizeEvent(QResizeEvent *event);
|
void resizeEvent(QResizeEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui_Form form;
|
Ui::Form form;
|
||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
|
@ -40,7 +40,9 @@
|
|||||||
|
|
||||||
#include "roundrectitem.h"
|
#include "roundrectitem.h"
|
||||||
|
|
||||||
#include <QtWidgets/QtWidgets>
|
#include <QApplication>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPalette>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
RoundRectItem::RoundRectItem(const QRectF &bounds, const QColor &color,
|
RoundRectItem::RoundRectItem(const QRectF &bounds, const QColor &color,
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
#include "splashitem.h"
|
#include "splashitem.h"
|
||||||
|
|
||||||
#include <QtWidgets/QtWidgets>
|
#include <QPainter>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
SplashItem::SplashItem(QGraphicsItem *parent)
|
SplashItem::SplashItem(QGraphicsItem *parent)
|
||||||
|
@ -45,7 +45,10 @@ class Widget : public QGraphicsWidget
|
|||||||
public:
|
public:
|
||||||
Widget(const QColor &color, const QColor &textColor, const QString &caption,
|
Widget(const QColor &color, const QColor &textColor, const QString &caption,
|
||||||
QGraphicsItem *parent = 0)
|
QGraphicsItem *parent = 0)
|
||||||
: QGraphicsWidget(parent), caption(caption), color(color), textColor(textColor)
|
: QGraphicsWidget(parent)
|
||||||
|
, caption(caption)
|
||||||
|
, color(color)
|
||||||
|
, textColor(textColor)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,23 +38,24 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QApplication>
|
|
||||||
|
|
||||||
#include <QGraphicsView>
|
|
||||||
#include <QGraphicsScene>
|
|
||||||
#include <QGraphicsWidget>
|
|
||||||
#include <QGraphicsProxyWidget>
|
|
||||||
#include <QGraphicsAnchorLayout>
|
#include <QGraphicsAnchorLayout>
|
||||||
|
#include <QGraphicsProxyWidget>
|
||||||
|
#include <QGraphicsScene>
|
||||||
#include <QGraphicsSceneResizeEvent>
|
#include <QGraphicsSceneResizeEvent>
|
||||||
|
#include <QGraphicsView>
|
||||||
|
#include <QGraphicsWidget>
|
||||||
|
|
||||||
|
|
||||||
class GraphicsView : public QGraphicsView
|
class GraphicsView : public QGraphicsView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GraphicsView(QGraphicsScene *scene, QGraphicsWidget *widget) : QGraphicsView(scene), w(widget)
|
GraphicsView(QGraphicsScene *scene, QGraphicsWidget *widget)
|
||||||
|
: QGraphicsView(scene), w(widget)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +71,8 @@ class PixmapWidget : public QGraphicsLayoutItem
|
|||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PixmapWidget(const QPixmap &pix) : QGraphicsLayoutItem()
|
PixmapWidget(const QPixmap &pix)
|
||||||
|
: QGraphicsLayoutItem()
|
||||||
{
|
{
|
||||||
original = new QGraphicsPixmapItem(pix);
|
original = new QGraphicsPixmapItem(pix);
|
||||||
setGraphicsItem(original);
|
setGraphicsItem(original);
|
||||||
@ -91,7 +93,8 @@ public:
|
|||||||
|
|
||||||
void setGeometry (const QRectF &rect)
|
void setGeometry (const QRectF &rect)
|
||||||
{
|
{
|
||||||
original->setTransform(QTransform::fromScale(rect.width() / r.width(), rect.height() / r.height()), true);
|
original->setTransform(QTransform::fromScale(rect.width() / r.width(),
|
||||||
|
rect.height() / r.height()), true);
|
||||||
original->setPos(rect.x(), rect.y());
|
original->setPos(rect.x(), rect.y());
|
||||||
r = rect;
|
r = rect;
|
||||||
}
|
}
|
||||||
@ -114,7 +117,7 @@ protected:
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return sh;
|
return sh;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -128,7 +131,10 @@ class PlaceWidget : public QGraphicsWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PlaceWidget(const QPixmap &pix) : QGraphicsWidget(), original(pix), scaled(pix)
|
PlaceWidget(const QPixmap &pix)
|
||||||
|
: QGraphicsWidget()
|
||||||
|
, original(pix)
|
||||||
|
, scaled(pix)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +189,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
Q_INIT_RESOURCE(weatheranchorlayout);
|
Q_INIT_RESOURCE(weatheranchorlayout);
|
||||||
|
|
||||||
@ -219,51 +225,51 @@ int main(int argc, char **argv)
|
|||||||
sunnyWeather->setZValue(9999);
|
sunnyWeather->setZValue(9999);
|
||||||
|
|
||||||
// start anchor layout
|
// start anchor layout
|
||||||
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
QGraphicsAnchorLayout *layout = new QGraphicsAnchorLayout;
|
||||||
l->setSpacing(0);
|
layout->setSpacing(0);
|
||||||
|
|
||||||
// setup the main widget
|
// setup the main widget
|
||||||
QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window);
|
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
|
||||||
QPalette p;
|
QPalette p;
|
||||||
p.setColor(QPalette::Window, Qt::black);
|
p.setColor(QPalette::Window, Qt::black);
|
||||||
w->setPalette(p);
|
widget->setPalette(p);
|
||||||
w->setPos(20, 20);
|
widget->setPos(20, 20);
|
||||||
w->setLayout(l);
|
widget->setLayout(layout);
|
||||||
|
|
||||||
// vertical anchors
|
// vertical anchors
|
||||||
QGraphicsAnchor *anchor = l->addAnchor(title, Qt::AnchorTop, l, Qt::AnchorTop);
|
QGraphicsAnchor *anchor = layout->addAnchor(title, Qt::AnchorTop, layout, Qt::AnchorTop);
|
||||||
anchor = l->addAnchor(place, Qt::AnchorTop, title, Qt::AnchorBottom);
|
anchor = layout->addAnchor(place, Qt::AnchorTop, title, Qt::AnchorBottom);
|
||||||
anchor->setSpacing(12);
|
anchor->setSpacing(12);
|
||||||
anchor = l->addAnchor(place, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
anchor = layout->addAnchor(place, Qt::AnchorBottom, layout, Qt::AnchorBottom);
|
||||||
anchor->setSpacing(12);
|
anchor->setSpacing(12);
|
||||||
|
|
||||||
anchor = l->addAnchor(sunnyWeather, Qt::AnchorTop, title, Qt::AnchorTop);
|
anchor = layout->addAnchor(sunnyWeather, Qt::AnchorTop, title, Qt::AnchorTop);
|
||||||
anchor = l->addAnchor(sunnyWeather, Qt::AnchorBottom, l, Qt::AnchorVerticalCenter);
|
anchor = layout->addAnchor(sunnyWeather, Qt::AnchorBottom, layout, Qt::AnchorVerticalCenter);
|
||||||
|
|
||||||
anchor = l->addAnchor(tabbar, Qt::AnchorTop, title, Qt::AnchorBottom);
|
anchor = layout->addAnchor(tabbar, Qt::AnchorTop, title, Qt::AnchorBottom);
|
||||||
anchor->setSpacing(5);
|
anchor->setSpacing(5);
|
||||||
anchor = l->addAnchor(details, Qt::AnchorTop, tabbar, Qt::AnchorBottom);
|
anchor = layout->addAnchor(details, Qt::AnchorTop, tabbar, Qt::AnchorBottom);
|
||||||
anchor->setSpacing(2);
|
anchor->setSpacing(2);
|
||||||
anchor = l->addAnchor(details, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
anchor = layout->addAnchor(details, Qt::AnchorBottom, layout, Qt::AnchorBottom);
|
||||||
anchor->setSpacing(12);
|
anchor->setSpacing(12);
|
||||||
|
|
||||||
// horizontal anchors
|
// horizontal anchors
|
||||||
anchor = l->addAnchor(l, Qt::AnchorLeft, title, Qt::AnchorLeft);
|
anchor = layout->addAnchor(layout, Qt::AnchorLeft, title, Qt::AnchorLeft);
|
||||||
anchor = l->addAnchor(title, Qt::AnchorRight, l, Qt::AnchorRight);
|
anchor = layout->addAnchor(title, Qt::AnchorRight, layout, Qt::AnchorRight);
|
||||||
|
|
||||||
anchor = l->addAnchor(place, Qt::AnchorLeft, l, Qt::AnchorLeft);
|
anchor = layout->addAnchor(place, Qt::AnchorLeft, layout, Qt::AnchorLeft);
|
||||||
anchor->setSpacing(15);
|
anchor->setSpacing(15);
|
||||||
anchor = l->addAnchor(place, Qt::AnchorRight, details, Qt::AnchorLeft);
|
anchor = layout->addAnchor(place, Qt::AnchorRight, details, Qt::AnchorLeft);
|
||||||
anchor->setSpacing(35);
|
anchor->setSpacing(35);
|
||||||
|
|
||||||
anchor = l->addAnchor(sunnyWeather, Qt::AnchorLeft, place, Qt::AnchorHorizontalCenter);
|
anchor = layout->addAnchor(sunnyWeather, Qt::AnchorLeft, place, Qt::AnchorHorizontalCenter);
|
||||||
anchor = l->addAnchor(sunnyWeather, Qt::AnchorRight, l, Qt::AnchorHorizontalCenter);
|
anchor = layout->addAnchor(sunnyWeather, Qt::AnchorRight, layout, Qt::AnchorHorizontalCenter);
|
||||||
|
|
||||||
anchor = l->addAnchor(tabbar, Qt::AnchorHorizontalCenter, details, Qt::AnchorHorizontalCenter);
|
anchor = layout->addAnchor(tabbar, Qt::AnchorHorizontalCenter, details, Qt::AnchorHorizontalCenter);
|
||||||
anchor = l->addAnchor(details, Qt::AnchorRight, l, Qt::AnchorRight);
|
anchor = layout->addAnchor(details, Qt::AnchorRight, layout, Qt::AnchorRight);
|
||||||
|
|
||||||
// QGV setup
|
// QGV setup
|
||||||
scene.addItem(w);
|
scene.addItem(widget);
|
||||||
scene.setBackgroundBrush(Qt::white);
|
scene.setBackgroundBrush(Qt::white);
|
||||||
QGraphicsView *view = new QGraphicsView(&scene);
|
QGraphicsView *view = new QGraphicsView(&scene);
|
||||||
view->show();
|
view->show();
|
||||||
|
Loading…
Reference in New Issue
Block a user