#include "plot.h"
#include "chart.h"
#include <QPainter>
#include <QColor>
#include <QHBoxLayout>
#include <QMenuBar>
#include <QPushButton>
#include <QDebug>
#include <QDockWidget>
//just in shoret do not post .h file Plot inherits QMainWindow
Plot::Plot()
{
exitAction
= new QAction(tr
("E&xit"),
this);
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(exitAction);
scene
= new PlotScene
(QRectF());
//[COLOR="red"][SIZE="6"][SIZE="7"]if I set any value here I my plot will be pained outsie view[/SIZE][/SIZE][/COLOR]
scene
->setBackgroundBrush
(QColor(Qt
::green));
scene->addItem(new chart());//view call paint to do all work
view = new PlotView();
//view->setFixedSize(500,500);
view->setScene(scene);
//view->setBackgroundBrush(QColor(Qt::red));
setCentralWidget(view);
//add docWidget
dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea |
Qt::RightDockWidgetArea);
addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
dockWidget->setWidget(tbutton);
//dockWidget->
//
connect( tbutton, SIGNAL(clicked()), scene, SLOT(clearPlot()) );
}
//-----------------------------------------------------------
#include "chart.h"
#include <QPainter>
#include <QWidget>
#include <QPolygonF>
#include <QStyleOptionGraphicsItem>
#include <QDebug>
#include "plot.h"
#include <math.h>
//chart inherits QGraphicsItem
chart::chart()
{
}
{
painter->drawLine(0,widget->height(), 0, 0-(widget->height()/2));
painter->drawLine(0-(widget->width()/2),0, (widget->width()/2), 0);
int step = 20;
int w = 5;
//draw y markers
for(int i =0; i<(widget->height()*2); i=i+step)
{
painter->drawLine(-w,widget->height()-i, w, widget->height()-i);
}
//draw x marker
for(int i =4; i<(widget->width()*2); i=i+step)
{
painter->drawLine(widget->width()-i, w, widget->width()-i, -w);
}
//draw sin()
for (double i=0; i<90; i=i+0.001)
{
pol.
append(QPointF((i
*60) - (widget
->width
()+155),
sin(i
)*100));
}
painter->drawPolyline(pol);
}
{
// int side = qMin(widget->width(), widget->height());
pen.setColor(color);
painter->setPen(pen);
draw(painter, widget);
qDebug() <<"boundingRect ="<<this->boundingRect();
//seems depend on main window geometry QRect(0,0 798x576)-2,-4
//The viewport represents the physical coordinates specifying an arbitrary rectangle.
qDebug() << "Painter viewport="<< painter->viewport();
//By default the logical and physical coordinate systems coincide,
//and are equivalent to the paint device's rectangle.
qDebug() << "Painter window = "<< painter->window();
//scene
//Returns the item's position in scene coordinates
qDebug() << "scene coordinates="<< this->scenePos();
}
#include "plot.h"
#include "chart.h"
#include <QPainter>
#include <QColor>
#include <QHBoxLayout>
#include <QMenuBar>
#include <QPushButton>
#include <QDebug>
#include <QDockWidget>
//just in shoret do not post .h file Plot inherits QMainWindow
Plot::Plot()
{
exitAction = new QAction(tr("E&xit"), this);
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(exitAction);
scene = new PlotScene(QRectF());//[COLOR="red"][SIZE="6"][SIZE="7"]if I set any value here I my plot will be pained outsie view[/SIZE][/SIZE]
[/COLOR]
scene->setBackgroundBrush(QColor(Qt::green));
scene->addItem(new chart());//view call paint to do all work
view = new PlotView();
//view->setFixedSize(500,500);
view->setScene(scene);
//view->setBackgroundBrush(QColor(Qt::red));
setCentralWidget(view);
//add docWidget
QString s("Dock Widget");
QDockWidget *dockWidget = new QDockWidget(s);
dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea |
Qt::RightDockWidgetArea);
addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
QPushButton* tbutton = new QPushButton("Clear");
dockWidget->setWidget(tbutton);
//dockWidget->
//
connect( tbutton, SIGNAL(clicked()), scene, SLOT(clearPlot()) );
}
//-----------------------------------------------------------
#include "chart.h"
#include <QPainter>
#include <QWidget>
#include <QPolygonF>
#include <QStyleOptionGraphicsItem>
#include <QDebug>
#include "plot.h"
#include <math.h>
//chart inherits QGraphicsItem
chart::chart()
{
}
void chart::draw(QPainter *painter, QWidget *widget)
{
painter->drawLine(0,widget->height(), 0, 0-(widget->height()/2));
painter->drawLine(0-(widget->width()/2),0, (widget->width()/2), 0);
int step = 20;
int w = 5;
//draw y markers
for(int i =0; i<(widget->height()*2); i=i+step)
{
painter->drawLine(-w,widget->height()-i, w, widget->height()-i);
}
//draw x marker
for(int i =4; i<(widget->width()*2); i=i+step)
{
painter->drawLine(widget->width()-i, w, widget->width()-i, -w);
}
//draw sin()
QPolygonF pol;
for (double i=0; i<90; i=i+0.001)
{
pol.append(QPointF((i*60) - (widget->width()+155),sin(i)*100));
}
painter->drawPolyline(pol);
}
void chart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
// int side = qMin(widget->width(), widget->height());
QColor color(255,255,255);
QPen pen(color,1.5);
pen.setColor(color);
painter->setPen(pen);
draw(painter, widget);
qDebug() <<"boundingRect ="<<this->boundingRect();
//seems depend on main window geometry QRect(0,0 798x576)-2,-4
//The viewport represents the physical coordinates specifying an arbitrary rectangle.
qDebug() << "Painter viewport="<< painter->viewport();
//By default the logical and physical coordinate systems coincide,
//and are equivalent to the paint device's rectangle.
qDebug() << "Painter window = "<< painter->window();
//scene
//Returns the item's position in scene coordinates
qDebug() << "scene coordinates="<< this->scenePos();
}
To copy to clipboard, switch view to plain text mode
Bookmarks