?? window.cpp
字號:
#include <QtGui>
#include "showimage.hpp"
#include "window.hpp"
//constructor
Window::Window()
{
//creat new widgets
prevButton = new QPushButton(tr("&Previous"));
nextButton = new QPushButton(tr("&Next"));
indexButton = new QPushButton(tr("&Choose Path"));
showImage = new ShowImage;
fileDialog = new QFileDialog(this,
tr("Select the image"), tr("E:/images"),
tr("Images (*.jpg *.png *.bmp *.gif)"));
slider = new QSlider(Qt::Horizontal, this);
label = new QLabel;
//set the slot and signal
connect(slider, SIGNAL(valueChanged(int)),
this, SLOT(changelabel(int)));
connect(indexButton, SIGNAL(clicked()),
fileDialog, SLOT(show()));
connect(prevButton, SIGNAL(clicked()),
this, SLOT(turn2prev()));
connect(nextButton, SIGNAL(clicked()),
this, SLOT(turn2next()));
connect(showImage, SIGNAL(get2beg(bool)),
prevButton, SLOT(setDisabled(bool)));
connect(showImage, SIGNAL(get2end(bool)),
nextButton, SLOT(setDisabled(bool)));
connect(fileDialog, SIGNAL(fileSelected(QString)),
this, SLOT(dirChanged(QString)));
connect(slider, SIGNAL(valueChanged(int)),
this, SLOT(scalethepix(int)));
connect(showImage, SIGNAL(turn2default(int)),
slider, SLOT(setValue(int)));
//set layout
QGridLayout *windowLayout = new QGridLayout;
QHBoxLayout *labelLayout = new QHBoxLayout;
labelLayout->addWidget(slider);
labelLayout->addWidget(label);
label->setBuddy(slider);
windowLayout->setColumnStretch(0, 1);
windowLayout->setColumnStretch(1, 2);
windowLayout->setColumnStretch(2, 2);
windowLayout->setColumnStretch(3, 2);
windowLayout->addWidget(showImage, 0, 0, 1, 9);
windowLayout->setRowMinimumHeight(1, 6);
windowLayout->addWidget(prevButton, 2, 1, Qt::AlignRight);
windowLayout->addWidget(nextButton, 2, 2, Qt::AlignLeft);
windowLayout->addWidget(indexButton, 2, 0, Qt::AlignLeft);
windowLayout->addLayout(labelLayout, 2, 3, Qt::AlignRight);
setLayout(windowLayout);
fileDialog->resize(450, 300);
//set the Tab order
setTabOrder(nextButton, prevButton);
nextButton->setDefault(true);
//set the short cut
//PgUp for prevButton
prevButton->setShortcut(QKeySequence(Qt::Key_Left));
//PgDn for nextButton
nextButton->setShortcut(QKeySequence(Qt::Key_Right));
slider->setRange(0, 500);
slider->setValue(100);
prevButton->setDisabled(true);
nextButton->setDisabled(true);
//set window name
setWindowTitle(tr("ImageBrowser"));
setWindowIcon(QIcon(":/icons/qt-logo.png"));
}
void Window::turn2prev()
{
showImage->show_prev();
}
void Window::turn2next()
{
showImage->show_next();
}
void Window::scalethepix(int rate)
{
showImage->arise_scale(rate);
}
void Window::dirChanged(QString newpath)
{
showImage->init_path((fileDialog->directory()), newpath);
}
void Window::changelabel(int val)
{
QString tmp;
tmp.setNum(val);
tmp += "%";
label->setText(tmp);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -