//
//implemention of MainWindow
//
#include"mainwindow.h"
#include<stdio.h>
MainWindow::MainWindow(QWidget* parent, const char* name)
:QWidget(parent, name){
_filemenu = new QPopupMenu(this, "filemenu");
_filemenu->insertItem("&Open", this, SLOT(slotLoad()));
_filemenu->insertItem("&Save", this, SLOT(slotSave()));
_filemenu->insertSeparator();
_filemenu->insertItem("&Quit", qApp, SLOT(quit()), ALT+Key_F4);
_filtermenu = new QPopupMenu(this, "filter");
_filtermenu->insertItem("Grayscale",idGrayScale);
_helpmenu = new QPopupMenu(this, "helpmenu");
_helpmenu->insertItem("&About", this, SLOT(about()));
_helpmenu->insertItem("About Qt", this, SLOT(aboutQt()));
_menu = new QMenuBar(this, "menubar");
_menu->insertItem("&File", _filemenu);
_menu->insertItem("Fil&ter", _filtermenu);
_menu->insertItem("&Help", _helpmenu);
_buffer = new QImage();
_grayscale = new GrayScale();
connect(_filtermenu, SIGNAL(activated(int)),
this, SLOT(callFilter(int)));
}
void MainWindow::about(){
QMessageBox::about( this, "About this program",
"This is a program for tutorial.\n"
"Copyright Dai Kaibazawa" );
}
void MainWindow::aboutQt(){
QMessageBox::aboutQt(this, "About Qt");
}
void MainWindow::slotLoad(){
QString name = QFileDialog::getOpenFileName(".", "Images (*.png *.bmp *.jpg)",this,
"Load dialog");
if(!name.isEmpty()){
if(!_buffer->load(name, "BMP")){
QMessageBox::warning(this, "Load error", "Could not load file.");
}else{
bitBlt(this,0,0,_buffer);
}
}
}
void MainWindow::slotSave(){
QString name = QFileDialog::getSaveFileName(".", "Images (*.bmp)",this,
"Save dialog");
if(!name.isEmpty()){
if(!_buffer->save(name, "BMP")){
QMessageBox::warning(this, "Save error", "Could not save file.");
}
}
}
void MainWindow::paintEvent(QPaintEvent*){
if(!_buffer->isNull())bitBlt(this,0,0,_buffer);
}
void MainWindow::callFilter(int id){
switch(id){
case idGrayScale:
_grayscale->toGrayScale(_buffer);
break;
}
}