kernelinfo::kernelinfo() : QMainWindow( 0, "kernelinfo", WDestructiveClose ) { printer = new QPrinter; QPixmap openIcon, saveIcon, printIcon; QToolBar * fileTools = new QToolBar( this, "file operations" ); fileTools->setLabel( tr("File Operations") ); openIcon = QPixmap( fileopen ); QToolButton * fileOpen = new QToolButton( openIcon, tr("Open File"), QString::null, this, SLOT(choose()), fileTools, "open file" ); saveIcon = QPixmap( filesave ); QToolButton * fileSave = new QToolButton( saveIcon, tr("Save File"), QString::null, this, SLOT(save()), fileTools, "save file" ); printIcon = QPixmap( fileprint ); QToolButton * filePrint = new QToolButton( printIcon, tr("Print File"), QString::null, this, SLOT(print()), fileTools, "print file" ); (void)QWhatsThis::whatsThisButton( fileTools ); QString fileOpenText = tr("<p><img source=\"fileopen\"> " "Click this button to open a <em>new file</em>. <br>" "You can also select the <b>Open</b> command " "from the <b>File</b> menu.</p>"); QWhatsThis::add( fileOpen, fileOpenText ); QMimeSourceFactory::defaultFactory()->setPixmap( "fileopen", openIcon ); QString fileSaveText = tr("<p>Click this button to save the file you " "are editing. You will be prompted for a file name.\n" "You can also select the <b>Save</b> command " "from the <b>File</b> menu.</p>"); QWhatsThis::add( fileSave, fileSaveText ); QString filePrintText = tr("Click this button to print the file you " "are editing.\n You can also select the Print " "command from the File menu."); QWhatsThis::add( filePrint, filePrintText ); QPopupMenu * file = new QPopupMenu( this ); menuBar()->insertItem( tr("&File"), file ); file->insertItem( tr("&New"), this, SLOT(newDoc()), CTRL+Key_N ); int id; id = file->insertItem( openIcon, tr("&Open..."), this, SLOT(choose()), CTRL+Key_O ); file->setWhatsThis( id, fileOpenText ); id = file->insertItem( saveIcon, tr("&Save"), this, SLOT(save()), CTRL+Key_S ); file->setWhatsThis( id, fileSaveText ); id = file->insertItem( tr("Save &As..."), this, SLOT(saveAs()) ); file->setWhatsThis( id, fileSaveText ); file->insertSeparator(); id = file->insertItem( printIcon, tr("&Print..."), this, SLOT(print()), CTRL+Key_P ); file->setWhatsThis( id, filePrintText ); file->insertSeparator(); file->insertItem( tr("&Close"), this, SLOT(close()), CTRL+Key_W ); file->insertItem( tr("&Quit"), qApp, SLOT( closeAllWindows() ), CTRL+Key_Q ); menuBar()->insertSeparator(); QPopupMenu * help = new QPopupMenu( this ); menuBar()->insertItem( tr("&Help"), help ); help->insertItem( tr("&About"), this, SLOT(about()), Key_F1 ); help->insertItem( tr("About &Qt"), this, SLOT(aboutQt()) ); help->insertSeparator(); help->insertItem( tr("What's &This"), this, SLOT(whatsThis()), SHIFT+Key_F1 ); e = new QTextEdit( this, "editor" ); e->setFocus(); setCentralWidget( e ); statusBar()->message( tr("Ready"), 2000 ); resize( 450, 600 ); }
int KAction::plug( QWidget *w, int index ) { //kdDebug(129) << "KAction::plug( " << w << ", " << index << " )" << endl; if (!w ) { kdWarning(129) << "KAction::plug called with 0 argument\n"; return -1; } // Ellis: print warning if there is a shortcut, but no KAccel available (often due to no widget available in the actioncollection) // David: Well, it doesn't matter much, things still work (e.g. Undo in koffice) via QAccel. // We should probably re-enable the warning for things that only KAccel can do, though - e.g. WIN key (mapped to Meta). #if 0 //ndef NDEBUG KAccel* kaccel = kaccelCurrent(); if( !d->m_cut.isNull() && !kaccel ) { kdDebug(129) << "KAction::plug(): has no KAccel object; this = " << this << " name = " << name() << " parentCollection = " << m_parentCollection << endl; // ellis } #endif // Check if action is permitted if (kapp && !kapp->authorizeKAction(name())) return -1; plugShortcut(); if ( ::qt_cast<QPopupMenu *>( w ) ) { QPopupMenu* menu = static_cast<QPopupMenu*>( w ); int id; // Don't insert shortcut into menu if it's already in a KAccel object. int keyQt = (d->m_kaccelList.count() || d->m_kaccel) ? 0 : d->m_cut.keyCodeQt(); if ( d->hasIcon() ) { KInstance *instance; if ( m_parentCollection ) instance = m_parentCollection->instance(); else instance = KGlobal::instance(); id = menu->insertItem( d->iconSet( KIcon::Small, 0, instance ), d->text(), this,//dsweet SLOT( slotPopupActivated() ), keyQt, -1, index ); } else id = menu->insertItem( d->text(), this, SLOT( slotPopupActivated() ), keyQt, -1, index ); // If the shortcut is already in a KAccel object, then // we need to set the menu item's shortcut text. if ( d->m_kaccelList.count() || d->m_kaccel ) updateShortcut( menu, id ); // call setItemEnabled only if the item really should be disabled, // because that method is slow and the item is per default enabled if ( !d->isEnabled() ) menu->setItemEnabled( id, false ); if ( !d->whatsThis().isEmpty() ) menu->setWhatsThis( id, whatsThisWithIcon() ); addContainer( menu, id ); connect( menu, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); if ( m_parentCollection ) m_parentCollection->connectHighlight( menu, this ); return d->m_containers.count() - 1; } else if ( ::qt_cast<KToolBar *>( w ) ) { KToolBar *bar = static_cast<KToolBar *>( w ); int id_ = getToolButtonID(); KInstance *instance; if ( m_parentCollection ) instance = m_parentCollection->instance(); else instance = KGlobal::instance(); if ( icon().isEmpty() && !iconSet().pixmap().isNull() ) // old code using QIconSet directly { bar->insertButton( iconSet().pixmap(), id_, SIGNAL( buttonClicked(int, Qt::ButtonState) ), this, SLOT( slotButtonClicked(int, Qt::ButtonState) ), d->isEnabled(), d->plainText(), index ); } else {
ApplicationWindow::ApplicationWindow() : QMainWindow( 0, "example application main window", WDestructiveClose ) { int id; QPixmap openIcon, saveIcon; fileTools = new QToolBar( this, "file operations" ); addToolBar( fileTools, tr( "File Operations" ), Top, TRUE ); openIcon = QPixmap( fileopen ); QToolButton * fileOpen = new QToolButton( openIcon, "Open File", QString::null, this, SLOT(load()), fileTools, "open file" ); saveIcon = QPixmap( filesave ); QToolButton * fileSave = new QToolButton( saveIcon, "Save File", QString::null, this, SLOT(save()), fileTools, "save file" ); #ifndef QT_NO_PRINTER printer = new QPrinter; QPixmap printIcon; printIcon = QPixmap( fileprint ); QToolButton * filePrint = new QToolButton( printIcon, "Print File", QString::null, this, SLOT(print()), fileTools, "print file" ); QWhatsThis::add( filePrint, filePrintText ); #endif (void)QWhatsThis::whatsThisButton( fileTools ); QWhatsThis::add( fileOpen, fileOpenText ); QWhatsThis::add( fileSave, fileSaveText ); QPopupMenu * file = new QPopupMenu( this ); menuBar()->insertItem( "&File", file ); file->insertItem( "&New", this, SLOT(newDoc()), CTRL+Key_N ); id = file->insertItem( openIcon, "&Open", this, SLOT(load()), CTRL+Key_O ); file->setWhatsThis( id, fileOpenText ); id = file->insertItem( saveIcon, "&Save", this, SLOT(save()), CTRL+Key_S ); file->setWhatsThis( id, fileSaveText ); id = file->insertItem( "Save &as...", this, SLOT(saveAs()) ); file->setWhatsThis( id, fileSaveText ); #ifndef QT_NO_PRINTER file->insertSeparator(); id = file->insertItem( printIcon, "&Print", this, SLOT(print()), CTRL+Key_P ); file->setWhatsThis( id, filePrintText ); #endif file->insertSeparator(); file->insertItem( "&Close", this, SLOT(closeWindow()), CTRL+Key_W ); file->insertItem( "&Quit", qApp, SLOT( closeAllWindows() ), CTRL+Key_Q ); windowsMenu = new QPopupMenu( this ); windowsMenu->setCheckable( TRUE ); connect( windowsMenu, SIGNAL( aboutToShow() ), this, SLOT( windowsMenuAboutToShow() ) ); menuBar()->insertItem( "&Windows", windowsMenu ); menuBar()->insertSeparator(); QPopupMenu * help = new QPopupMenu( this ); menuBar()->insertItem( "&Help", help ); help->insertItem( "&About", this, SLOT(about()), Key_F1); help->insertItem( "About &Qt", this, SLOT(aboutQt())); help->insertSeparator(); help->insertItem( "What's &This", this, SLOT(whatsThis()), SHIFT+Key_F1); QVBox* vb = new QVBox( this ); vb->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken ); ws = new QWorkspace( vb ); setCentralWidget( vb ); statusBar()->message( "Ready", 2000 ); }
ApplicationWindow::ApplicationWindow() : QMainWindow( 0, "example application main window", WDestructiveClose ) { int id; printer = new QPrinter; QPixmap openIcon, saveIcon, printIcon; fileTools = new QToolBar( this, "file operations" ); fileTools->setLabel( tr( "File Operations" ) ); openIcon = QPixmap( fileopen ); QToolButton * fileOpen = new QToolButton( openIcon, "Open File", QString::null, this, SLOT(load()), fileTools, "open file" ); saveIcon = QPixmap( filesave ); QToolButton * fileSave = new QToolButton( saveIcon, "Save File", QString::null, this, SLOT(save()), fileTools, "save file" ); printIcon = QPixmap( fileprint ); QToolButton * filePrint = new QToolButton( printIcon, "Print File", QString::null, this, SLOT(print()), fileTools, "print file" ); (void)QWhatsThis::whatsThisButton( fileTools ); QWhatsThis::add( fileOpen, fileOpenText ); QMimeSourceFactory::defaultFactory()->setPixmap( "fileopen", openIcon ); QWhatsThis::add( fileSave, fileSaveText ); QWhatsThis::add( filePrint, filePrintText ); QPopupMenu * file = new QPopupMenu( this ); menuBar()->insertItem( "&File", file ); file->insertItem( "&New", this, SLOT(newDoc()), CTRL+Key_N ); id = file->insertItem( openIcon, "&Open", this, SLOT(load()), CTRL+Key_O ); file->setWhatsThis( id, fileOpenText ); id = file->insertItem( saveIcon, "&Save", this, SLOT(save()), CTRL+Key_S ); file->setWhatsThis( id, fileSaveText ); id = file->insertItem( "Save &as...", this, SLOT(saveAs()) ); file->setWhatsThis( id, fileSaveText ); file->insertSeparator(); id = file->insertItem( printIcon, "&Print", this, SLOT(print()), CTRL+Key_P ); file->setWhatsThis( id, filePrintText ); file->insertSeparator(); file->insertItem( "&Close", this, SLOT(close()), CTRL+Key_W ); file->insertItem( "&Quit", qApp, SLOT( closeAllWindows() ), CTRL+Key_Q ); QPopupMenu * help = new QPopupMenu( this ); menuBar()->insertSeparator(); menuBar()->insertItem( "&Help", help ); help->insertItem( "&About", this, SLOT(about()), Key_F1 ); help->insertItem( "About &Qt", this, SLOT(aboutQt()) ); help->insertSeparator(); help->insertItem( "What's &This", this, SLOT(whatsThis()), SHIFT+Key_F1 ); e = new QMultiLineEdit( this, "editor" ); e->setFocus(); setCentralWidget( e ); statusBar()->message( "Ready", 2000 ); resize( 450, 600 ); }