📄 myscalecontrol.cpp
字号:
/************************************************************************************************************************************************************** **** equal III the graphic builder **** **** Copyright (C) 2003 Oleksiy Pylypenko **** **** This file may be distributed and/or modified under the terms of the **** GNU General Public License version 2 as published by the Free Software **** Foundation and appearing in the file license included in the **** packaging of this file. **** **** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE **** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. **** **** Contact earthman@inbox.ru if any conditions of this licensing are **** not clear to you. **** **** ********************************************************************************* *****************************************************************************/#include <qmultilineedit.h>#include <qlayout.h>#include <qlabel.h>#include <qpixmap.h>#include <qtoolbutton.h>#include <qvalidator.h>#include <qapplication.h>#include <qlabel.h>#include "myscalecontrol.h"#include "xpms.h"void myScaleControl::clear(void){ top = 10; left = -10; right = 10; bottom = -10; setScales(); update();}myScaleControl::myScaleControl( QWidget *parent) : QWidget( parent ){ QBoxLayout *topLayout = new QVBoxLayout( this , 10 ); QGridLayout *grid = new QGridLayout( topLayout, 6, 5 ); wnd_top = new QLineEdit(this); wnd_left = new QLineEdit(this); wnd_right = new QLineEdit(this); wnd_bottom = new QLineEdit(this); QDoubleValidator *validator = new QDoubleValidator(this); wnd_top->setValidator(validator); wnd_left->setValidator(validator); wnd_right->setValidator(validator); wnd_bottom->setValidator(validator); wnd_top->setFixedWidth(50); wnd_left->setFixedWidth(50); wnd_right->setFixedWidth(50); wnd_bottom->setFixedWidth(50); this->connect(wnd_top,SIGNAL(returnPressed()),SIGNAL(update())); this->connect(wnd_left,SIGNAL(returnPressed()),SIGNAL(update())); this->connect(wnd_right,SIGNAL(returnPressed()),SIGNAL(update())); this->connect(wnd_bottom,SIGNAL(returnPressed()),SIGNAL(update())); grid->addMultiCellWidget( wnd_top, 1, 1, 2, 3, Qt::AlignCenter ); grid->addMultiCellWidget( wnd_left, 2, 2, 1, 2, Qt::AlignCenter ); grid->addMultiCellWidget( wnd_right, 2, 2, 3, 4, Qt::AlignCenter ); grid->addMultiCellWidget( wnd_bottom, 3, 3, 2, 3, Qt::AlignCenter ); grid->setColStretch(0,100); grid->setColStretch(1,1); grid->setColStretch(2,1); grid->setColStretch(3,1); grid->setColStretch(4,1); grid->setColStretch(5,100); grid->setRowStretch(0,100); grid->setRowStretch(1,1); grid->setRowStretch(2,1); grid->setRowStretch(3,1); grid->setRowStretch(4,100); topLayout->setStretchFactor(grid,1); grid = new QGridLayout(topLayout,5,5,10); topLayout->setStretchFactor(grid,1); QToolButton *abutton; abutton = new QToolButton(this); abutton->setPixmap( QPixmap(zoom_in)); abutton->setAutoRaise(true); abutton->setFocusPolicy(WheelFocus); this->connect(abutton,SIGNAL(pressed()),SLOT(pushZoomOut())); grid->addWidget(abutton,1,3); abutton = new QToolButton(this); abutton->setPixmap( QPixmap(zoom_out)); abutton->setAutoRaise(true); abutton->setFocusPolicy(WheelFocus); this->connect(abutton,SIGNAL(pressed()),SLOT(pushZoomIn())); grid->addWidget(abutton,1,1); abutton = new QToolButton(this); abutton->setPixmap( QPixmap(up_button)); abutton->setAutoRaise(true); abutton->setFocusPolicy(WheelFocus); this->connect(abutton,SIGNAL(pressed()),SLOT(pushUp())); grid->addWidget(abutton,1,2); abutton = new QToolButton(this); abutton->setPixmap( QPixmap(left_button)); abutton->setAutoRaise(true); abutton->setFocusPolicy(WheelFocus); this->connect(abutton,SIGNAL(pressed()),SLOT(pushLeft())); grid->addWidget(abutton,2,1); abutton = new QToolButton(this); abutton->setPixmap( QPixmap(right_button)); abutton->setAutoRaise(true); abutton->setFocusPolicy(WheelFocus); this->connect(abutton,SIGNAL(pressed()),SLOT(pushRight())); grid->addWidget(abutton,2,3); abutton = new QToolButton(this); abutton->setPixmap( QPixmap(down_button)); abutton->setAutoRaise(true); abutton->setFocusPolicy(WheelFocus); this->connect(abutton,SIGNAL(pressed()),SLOT(pushDown())); grid->addWidget(abutton,3,2); grid->setRowStretch(0,100); grid->setRowStretch(1,1); grid->setRowStretch(2,1); grid->setRowStretch(3,1); grid->setRowStretch(4,100); grid->setColStretch(0,100); grid->setColStretch(1,1); grid->setColStretch(2,1); grid->setColStretch(3,1); grid->setColStretch(4,100); QLabel *l = new QLabel("",this); topLayout->addWidget(l); topLayout->setStretchFactor(l,2); clear();}void myScaleControl::setScales(void){ wnd_top->setText(QString("%1").arg(top)); wnd_left->setText(QString("%1").arg(left)); wnd_right->setText(QString("%1").arg(right)); wnd_bottom->setText(QString("%1").arg(bottom));}void myScaleControl::readScales(void){ top=wnd_top->text().toDouble(); left=wnd_left->text().toDouble(); right=wnd_right->text().toDouble(); bottom=wnd_bottom->text().toDouble();}void myScaleControl::pushUp(void){ readScales(); double d = (top-bottom)/5.; bottom += d;top += d; setScales(); update();}void myScaleControl::pushDown(void){ readScales(); double d = (bottom-top)/5.; bottom += d;top += d; setScales(); update();}void myScaleControl::pushLeft(void){ readScales(); double d = (left-right)/5.; left += d;right += d; setScales(); update();}void myScaleControl::pushRight(void){ readScales(); double d = (right-left)/5.; left += d;right += d; setScales(); update();}void myScaleControl::pushZoomIn(void){ readScales(); double w = left-right;w/=0.6; double h = bottom-top;h/=0.6; double cx = (left+right) / 2.; double cy = (top+bottom) / 2.; right = cx - w / 2.; left = cx + w / 2.; top = cy - h / 2.; bottom = cy + h / 2.; setScales(); update();}void myScaleControl::pushZoomOut(void){ readScales(); double w = left-right;w*=0.6; double h = bottom-top;h*=0.6; double cx = (left+right) / 2.; double cy = (top+bottom) / 2.; right = cx - w / 2.; left = cx + w / 2.; top = cy - h / 2.; bottom = cy + h / 2.; setScales(); update();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -