#include "mainwindow.h"
#include "canvasview.h"
#include <qmainwindow.h>
#include <qapplication.h>
#include <qlayout.h>
MainWindow
::MainWindow(QWidget* parent,
const char* name
){
int screenW;
int screenH;
this->resize(screenW,screenH);
toolBarMode = TRUE;
init();
}
void MainWindow::init()
{
toolBarDockWindow = new QDockWindow(QDockWindow::InDock,this,"toolbardockwindow",0);
toolBarDockWindow->setOrientation(Qt::Horizontal);
toolBarDockWindow->setHorizontallyStretchable(TRUE);
toolBarDockWindow->setVerticallyStretchable(TRUE);
toolBarDockWindow->setMovingEnabled(FALSE);
this->moveDockWindow(toolBarDockWindow,Qt::DockBottom);
toolBarStack = new QWidgetStack(toolBarDockWindow);
toolBarDockWindow->setWidget(toolBarStack);
toolBarStack->addWidget(editToolBar,0);
toolBarStack->addWidget(graphicToolBar,1);
graphicButton
= new QToolButton(editToolBar,
"graphicutton");
graphicButton->setUsesTextLabel(TRUE);
graphicButton->setTextLabel("Graphic",FALSE);
graphicButton
->setFont
(QFont("Times",
20,
QFont::Bold));
editToolBarLayout->addWidget(graphicButton);
editToolBarLayout->addItem(editToolBarSpacer);
quitButton
= new QToolButton(graphicToolBar,
"quitbutton");
quitButton->setUsesTextLabel(TRUE);
quitButton->setTextLabel("Return",FALSE);
quitButton
->setFont
(QFont("Times",
20,
QFont::Bold));
graphicToolBarLayout->addWidget(quitButton);
graphicToolBarLayout->addItem(graphicToolBarSpacer);
toolBarStack->raiseWidget(0);
connect(graphicButton,SIGNAL(clicked()),this,SLOT(switchToolBarMode()));
connect(quitButton,SIGNAL(clicked()),this,SLOT(switchToolBarMode()));
//construct the QWidgetStack as the MainWindow's main widget.
centralWidgetStack = new QWidgetStack(this);
//add textedit into the QWidgetStack.
textEdit
= new QTextEdit(centralWidgetStack,
"textedit");
textEdit->setTextFormat(Qt::PlainText);
textEdit->setFocus();
centralWidgetStack->addWidget(textEdit,0);
//add canvasView into the QWidgetStack.
canvas = new QCanvas(this);
canvasView = new CanvasView(canvas,centralWidgetStack,"canvasview");
centralWidgetStack->addWidget(canvasView,1);
this->setCentralWidget(centralWidgetStack);
centralWidgetStack->raiseWidget(0);
connect(toolBarStack,SIGNAL(aboutToShow(int)),this,SLOT(switchCentralWidgetMode(int)));
}
void MainWindow::switchToolBarMode()
{
if(toolBarMode){
toolBarStack->raiseWidget(1);
}else{
toolBarStack->raiseWidget(0);
}
toolBarMode = !toolBarMode;
}
void MainWindow::switchCentralWidgetMode(int i)
{
centralWidgetStack->raiseWidget(i);
}
#include "mainwindow.h"
#include "canvasview.h"
#include <qmainwindow.h>
#include <qapplication.h>
#include <qlayout.h>
MainWindow::MainWindow(QWidget* parent, const char* name)
:QMainWindow(parent,name)
{
int screenW;
int screenH;
screenW = QApplication::desktop()->width();
screenH = QApplication::desktop()->height();
this->resize(screenW,screenH);
toolBarMode = TRUE;
init();
}
void MainWindow::init()
{
toolBarDockWindow = new QDockWindow(QDockWindow::InDock,this,"toolbardockwindow",0);
toolBarDockWindow->setOrientation(Qt::Horizontal);
toolBarDockWindow->setHorizontallyStretchable(TRUE);
toolBarDockWindow->setVerticallyStretchable(TRUE);
toolBarDockWindow->setMovingEnabled(FALSE);
this->moveDockWindow(toolBarDockWindow,Qt::DockBottom);
toolBarStack = new QWidgetStack(toolBarDockWindow);
toolBarDockWindow->setWidget(toolBarStack);
QWidget* editToolBar = new QWidget(toolBarStack);
QHBoxLayout* editToolBarLayout = new QHBoxLayout(editToolBar,6,6);
QWidget* graphicToolBar = new QWidget(toolBarStack);
QHBoxLayout* graphicToolBarLayout = new QHBoxLayout(graphicToolBar,6,6);
toolBarStack->addWidget(editToolBar,0);
toolBarStack->addWidget(graphicToolBar,1);
graphicButton = new QToolButton(editToolBar,"graphicutton");
graphicButton->setUsesTextLabel(TRUE);
graphicButton->setTextLabel("Graphic",FALSE);
graphicButton->setFont(QFont("Times",20,QFont::Bold));
editToolBarLayout->addWidget(graphicButton);
QSpacerItem* editToolBarSpacer = new QSpacerItem(0,0,QSizePolicy::Expanding,QSizePolicy::Minimum);
editToolBarLayout->addItem(editToolBarSpacer);
quitButton = new QToolButton(graphicToolBar,"quitbutton");
quitButton->setUsesTextLabel(TRUE);
quitButton->setTextLabel("Return",FALSE);
quitButton->setFont(QFont("Times",20,QFont::Bold));
graphicToolBarLayout->addWidget(quitButton);
QSpacerItem* graphicToolBarSpacer = new QSpacerItem(0,0,QSizePolicy::Expanding,QSizePolicy::Minimum);
graphicToolBarLayout->addItem(graphicToolBarSpacer);
toolBarStack->raiseWidget(0);
connect(graphicButton,SIGNAL(clicked()),this,SLOT(switchToolBarMode()));
connect(quitButton,SIGNAL(clicked()),this,SLOT(switchToolBarMode()));
//construct the QWidgetStack as the MainWindow's main widget.
centralWidgetStack = new QWidgetStack(this);
//add textedit into the QWidgetStack.
textEdit = new QTextEdit(centralWidgetStack,"textedit");
textEdit->setTextFormat(Qt::PlainText);
textEdit->setFocus();
centralWidgetStack->addWidget(textEdit,0);
//add canvasView into the QWidgetStack.
canvas = new QCanvas(this);
canvasView = new CanvasView(canvas,centralWidgetStack,"canvasview");
centralWidgetStack->addWidget(canvasView,1);
this->setCentralWidget(centralWidgetStack);
centralWidgetStack->raiseWidget(0);
connect(toolBarStack,SIGNAL(aboutToShow(int)),this,SLOT(switchCentralWidgetMode(int)));
}
void MainWindow::switchToolBarMode()
{
if(toolBarMode){
toolBarStack->raiseWidget(1);
}else{
toolBarStack->raiseWidget(0);
}
toolBarMode = !toolBarMode;
}
void MainWindow::switchCentralWidgetMode(int i)
{
centralWidgetStack->raiseWidget(i);
}
To copy to clipboard, switch view to plain text mode
#include "canvasview.h"
#include <qcanvas.h>
#include <qapplication.h>
CanvasView
::CanvasView(QCanvas
* canvas,
QWidget* parent,
const char* name
) :QCanvasView(canvas,parent,name)
{
setMouseTracking(TRUE);
}
void CanvasView
::contentsMouseMoveEvent(QMouseEvent* e
) {
qWarning("The MouseMoveEvent has been received!");
}
#include "canvasview.h"
#include <qcanvas.h>
#include <qapplication.h>
CanvasView::CanvasView(QCanvas* canvas, QWidget* parent, const char* name)
:QCanvasView(canvas,parent,name)
{
setMouseTracking(TRUE);
}
void CanvasView::contentsMouseMoveEvent(QMouseEvent* e)
{
qWarning("The MouseMoveEvent has been received!");
}
To copy to clipboard, switch view to plain text mode
#include <qapplication.h>
#include "mainwindow.h"
#include "canvasview.h"
int main(int argc,char* argv[])
{
MainWindow* mainwindow = new MainWindow();
app.setMainWidget(mainwindow);
mainwindow->show();
return app.exec();
}
#include <qapplication.h>
#include "mainwindow.h"
#include "canvasview.h"
int main(int argc,char* argv[])
{
QApplication app(argc,argv);
MainWindow* mainwindow = new MainWindow();
app.setMainWidget(mainwindow);
mainwindow->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks