⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 window.cpp

📁 QT4.5实现的图片浏览器源码, 实现放大缩小图片,图片切换等功能,可以在LINUX平台和wingdows平台移植.
💻 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 + -