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