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

📄 kwizard.cpp

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*  This file is part of the KDE Libraries    Copyright (C) 1998 Thomas Tanghus (tanghus@earthling.net)    This library is free software; you can redistribute it and/or    modify it under the terms of the GNU Library General Public    License as published by the Free Software Foundation; either    version 2 of the License, or (at your option) any later version.    This library is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    Library General Public License for more details.    You should have received a copy of the GNU Library General Public License    along with this library; see the file COPYING.LIB.  If not, write to    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,    Boston, MA 02111-1307, USA.*/  #include "kwizard.h"struct KWizProtected{  QPopupMenu       *menu;  QWidget          *currentwidget;  KSeparator       *sep1;  KSeparator       *sep2;  KDirectionButton *left;  KDirectionButton *right;  QPushButton      *ok;  QPushButton      *cancel;  QPushButton      *def;  QPushButton      *help;  QPushButton      *next;  QPushButton      *previous;  QLabel           *title;  QLabel           *pagina;  bool             directionsreflectspage;  bool             enablepopupmenu;  bool             enablearrowbuttons;  int              numpages;  int              current;  int              minheight;  int              minwidth;  };KDialog::KDialog(QWidget *parent, const char *name, bool modal, WFlags f)  : QDialog(parent, name, modal, f){  //debug("KDialog creation");  initMetaObject();  setFocusPolicy(QWidget::StrongFocus);}// Grab QDialogs keypresses if non-modal.void KDialog::keyPressEvent(QKeyEvent *e){  if ( e->state() == 0 )  {    switch ( e->key() )    {      case Key_Escape:      case Key_Enter:      case Key_Return:      {        if(testWFlags(WType_Modal))          QDialog::keyPressEvent(e);        else        {          //debug("KDialog - Eating keyevent");  	  e->ignore();        }      }      break;      default:	e->ignore();	return;    }  }  else  {    e->ignore();  }}KWizard::KWizard(QWidget *parent, const char *name, bool modal, WFlags f)  : KDialog(parent, name, modal, f)//  : QWidget(parent, name, modal ? (f | WType_Modal) : f){  //debug("KWizard creation");  initMetaObject();  pwiz = new KWizProtected;  pages = new QList<KWizardPage>;  pages->setAutoDelete(true);  pwiz->menu = new QPopupMenu();  connect( pwiz->menu, SIGNAL(activated(int)), SLOT(gotoPage(int)));  pwiz->numpages = 0;  pwiz->current = -1;  pwiz->minwidth = 300;  pwiz->minheight = 300;  pwiz->currentwidget = 0L;  pwiz->ok = pwiz->cancel = pwiz->def = pwiz->help = pwiz->next = pwiz->previous = 0L;  pwiz->directionsreflectspage = pwiz->enablepopupmenu = pwiz->enablearrowbuttons = false;  pwiz->title = new QLabel(this);  pwiz->title->installEventFilter(this);  pwiz->title->setAlignment(AlignLeft|AlignVCenter);  pwiz->pagina = new QLabel("Page 1 of 1", this);  pwiz->pagina->setAlignment(AlignLeft|AlignVCenter);  pwiz->left = new KDirectionButton(LeftArrow, this);  connect( pwiz->left, SIGNAL(clicked()), SLOT(previousPage()));  pwiz->left->hide();  pwiz->right = new KDirectionButton(RightArrow, this);  connect( pwiz->right, SIGNAL(clicked()), SLOT(nextPage()));  pwiz->right->hide();  pwiz->sep1 = new KSeparator(this);  //sep1->setFixedHeight(sep1->sizeHint().height());  pwiz->sep2 = new KSeparator(this);  //sep2->setFixedHeight(sep2->sizeHint().height());  pwiz->previous = new QPushButton(PREV, this);  pwiz->previous->hide();  connect( pwiz->previous, SIGNAL(clicked()), SLOT(previousPage()));  pwiz->next = new QPushButton(NEXT, this);  pwiz->next->hide();  connect( pwiz->next, SIGNAL(clicked()), SLOT(nextPage()));  installEventFilter(this);  //debug("KWizard created");}// DestructorKWizard::~KWizard(){  //debug("KWizard - destructor");  //if (menu) delete menu;  //menu = 0L;  delete pwiz;  delete pages;  //debug("KWizard - destructor done");}void KWizard::setCancelButton(){  setCancelButton(klocale->translate("&Cancel"));}void KWizard::setCancelButton(const char *name){  if(!pwiz->cancel)  {    pwiz->cancel = new QPushButton(name, this);    pwiz->cancel->show();    connect( pwiz->cancel, SIGNAL(clicked()), SLOT(cancelClicked()));  }  else    pwiz->cancel->setText(name);  setSizes();}QButton *KWizard::getCancelButton(){  return pwiz->cancel;}void KWizard::setDefaultButton(){  setDefaultButton(klocale->translate("&Default"));}void KWizard::setDefaultButton(const char *name){  if(!pwiz->def)  {    pwiz->def = new QPushButton(name, this);    pwiz->def->show();    connect( pwiz->def, SIGNAL(clicked()), SLOT(defaultClicked()));  }  else    pwiz->def->setText(name);  setSizes();}QButton *KWizard::getDefaultButton(){  return pwiz->def;}void KWizard::setHelpButton(){  setHelpButton(klocale->translate("&Help"));}void KWizard::setHelpButton(const char *name){  if(!pwiz->help)  {    pwiz->help = new QPushButton(name, this);    pwiz->help->show();    connect( pwiz->help, SIGNAL(clicked()), SLOT(helpClicked()));  }  else    pwiz->help->setText(name);  setSizes();}QButton *KWizard::getHelpButton(){  return pwiz->help;}void KWizard::setOkButton(){  setOkButton(klocale->translate("&OK"));}void KWizard::setOkButton(const char *name){  if(!pwiz->ok)  {    pwiz->ok = new QPushButton(name, this);    pwiz->ok->show();    connect( pwiz->ok, SIGNAL(clicked()), SLOT(okClicked()));  }  else    pwiz->ok->setText(name);  setSizes();}QButton *KWizard::getOkButton(){  return pwiz->ok;}QButton *KWizard::getNextButton(){  return pwiz->next;}QButton *KWizard::getPreviousButton(){  return pwiz->previous;}KDirectionButton *KWizard::getLeftArrow(){  return pwiz->left;}KDirectionButton *KWizard::getRightArrow(){  return pwiz->right;}QSize KWizard::pageSize(){  //debug("Calculating sizes");  QSize size(0,0);  //int x = 0, y = 0;  for(int i = 0; i < pwiz->numpages; i++)  {    QSize csize = pages->at(i)->w->minimumSize();    if(size.height() < csize.height())      size.setHeight(csize.height());    if(size.width() < csize.width())      size.setWidth(csize.width());    //debug("Page size: %d x %d", size.width(), size.height());  }  return size;}void KWizard::setSizes(){  //debug("setSizes");  QFont titlefont;  //titlefont.setPointSize(titlefont.pointSize()*2);  titlefont.setWeight(QFont::Bold);  pwiz->title->setFont(titlefont);  pwiz->title->adjustSize();  //debug("Title points: %d", titlefont.pointSize());  //debug("Title height: %d", title->height());  pwiz->pagina->adjustSize();  QSize pagesize = pageSize();  int subtr = 5;  bool f = false;  if(pwiz->ok)  {    pwiz->ok->adjustSize();    f = true;    subtr = pwiz->ok->height() + 10;  }  if(pwiz->cancel)  {    pwiz->cancel->adjustSize();    if(!f)      subtr = pwiz->cancel->height() + 10;  }  if(pwiz->def)  {    pwiz->def->adjustSize();    if(!f)      subtr = pwiz->def->height() + 10;  }  if(pwiz->help)  {    pwiz->help->adjustSize();    if(!f)      subtr = pwiz->help->height() + 10;  }  int y = pwiz->title->height() + pagesize.height() +  pwiz->next->height() + 35 + subtr;  int x = 20 + pagesize.width();  setMinimumSize(x, y);  //resize(x, y);}void KWizard::resizeEvent(QResizeEvent *){  //QSize pagesize = pageSize();  //debug("KWizard, resizeEvent()");  int subtr = 4;  if(pwiz->ok && pwiz->ok->isVisible())    subtr = pwiz->ok->height() + 10;  else if(pwiz->cancel && pwiz->cancel->isVisible())    subtr = pwiz->cancel->height() + 10;  else if(pwiz->def && pwiz->def->isVisible())    subtr = pwiz->cancel->height() + 10;  else if(pwiz->help && pwiz->help->isVisible())    subtr = pwiz->help->height() + 10;  //main->setGeometry(2, 2, width()-4, height()-(subtr));  //debug("main");  //pagina->adjustSize();  pwiz->title->setGeometry(7, 7,                           width()-14,                           pwiz->title->sizeHint().height());  pwiz->right->setGeometry(width()-(pwiz->title->sizeHint().height()+10),                           5, // had to make a little hack :-(                           pwiz->title->sizeHint().height(),                           pwiz->title->sizeHint().height()+2);  pwiz->left->setGeometry(width()-((pwiz->title->sizeHint().height()*2)+10),                          5,                          pwiz->title->sizeHint().height(),                          pwiz->title->sizeHint().height()+2);  pwiz->pagina->setGeometry(        width()-(pwiz->pagina->sizeHint().width()+(pwiz->title->sizeHint().height()*2)+20),                          7,                          pwiz->pagina->sizeHint().width(),                          pwiz->pagina->sizeHint().height());  if(pwiz->numpages > 1)    pwiz->pagina->show();  else    pwiz->pagina->hide();  //debug("header - pagina: %d", pagina->width());  pwiz->sep1->setGeometry(7,                          pwiz->title->height()+10,                          width()-14,                          2);  //debug("sep1");  if(pwiz->currentwidget)  {    int hack = 15;    if(pwiz->ok || pwiz->cancel || pwiz->help) hack = 0;    int offs = pwiz->title->height() + 12;    pwiz->currentwidget->setGeometry( 7, offs, width()-14,           height()-( pwiz->next->height() + 40 + subtr + hack));  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -