Algorithm-VSM

 view release on metacpan or  search on metacpan

examples/corpus_with_java_and_cpp/WindowWithMenu.cc  view on Meta::CPAN

// This code example is from the following source:
//
// Book Title:  Programming with Objects, A Comparative Presentation
//              of Object-Oriented Programming with C++ and Java
//
// Chapter:     Chapter 17  OO For Graphical User Interfaces, A Tour Of Three Toolkits
//
// Section:     Section 17.17  Windows with Menus in Qt
//
// The links to the rest of the code in this book are at
//     
//      http://programming-with-objects.com/pwocode.html
//
// For further information regarding the book, please visit
//
//      http://programming-with-objects.com
//




///////////  file: WindowWithMenu.cc  /////////////


#include "WindowWithMenu.h"
#include <qfiledialog.h>
#include <iostream> 
using namespace std;


WindowWithMenu::WindowWithMenu( QWidget* parent, const char* name )
    : QWidget( parent, name )
{
    setPalette( QPalette( QColor( 250, 250, 200 ) ) );

    filemenu = new QPopupMenu( this ); //arg is parent, useful for auo destruct
    filemenu->insertItem( "New", this, SLOT( allowTextEntry() ) );
    filemenu->insertItem( "Open", this, SLOT( getTextFromFile() ) );
    filemenu->insertItem( "Save", this, SLOT( saveTextToFile() ) );


    colormenu = new QPopupMenu( this );
    colormenu->insertItem( "blue", BLUE );
    colormenu->insertItem( "yellow", YELLOW );
    colormenu->insertItem( "magenta", MAGENTA );

    QObject::connect( colormenu,
                      SIGNAL( activated( int ) ),
                      this,
                      SLOT( selectColor( int ) ) );


    menubar = new QMenuBar( this );
    menubar->insertItem( "&File", filemenu );
    menubar->insertItem( "Color", colormenu );

    QRect rect = menubar->frameGeometry();
    int h = rect.height();

    textarea = new QMultiLineEdit( this );
    textarea->setGeometry( 0, h, 300, 350 );
    textarea->setReadOnly( TRUE );
}


WindowWithMenu::~WindowWithMenu() { }



void WindowWithMenu::allowTextEntry() 
{
    cout << "New selected" << endl;
    textarea->setReadOnly( FALSE );
}


void WindowWithMenu::getTextFromFile() 
{
    cout << "Open selected" << endl;
    QFileDialog* fd = new QFileDialog();
    QString fileName = 
        fd->getOpenFileName( QString::null, QString::null, this );
    cout << "file selected: " + fileName << endl;    
    if ( !fileName.isEmpty() && !fileName.isNull() )
        load( fileName );
    else
        cout << "File is either empty or does not exist" << endl;
}
                                                                         


void WindowWithMenu::saveTextToFile() {
    cout << "Save selected" << endl;
    QString fileName = 
       QFileDialog::getSaveFileName( QString::null, QString::null, this );
    save( fileName );



( run in 1.688 second using v1.01-cache-2.11-cpan-5b529ec07f3 )