StatusDialog::StatusDialog( QWidget *parent ) : KDialog( parent ) { setModal( true ); setCaption( i18n( "Set Your Status" ) ); QBoxLayout *topLayout = new QVBoxLayout( this ); topLayout->setSpacing( spacingHint() ); topLayout->setMargin( marginHint() ); QBoxLayout *statusLayout = new QHBoxLayout(); topLayout->addItem( statusLayout ); QLabel *text = new QLabel( i18n( "Set your status" ), this ); statusLayout->addWidget( text ); mStatus = new KComboBox( this ); mStatus->setEditable( false ); mStatus->addItems( Attendee::statusList() ); statusLayout->addWidget( mStatus ); QBoxLayout *buttonLayout = new QHBoxLayout(); topLayout->addItem( buttonLayout ); QPushButton *ok = new KPushButton( KStandardGuiItem::ok(), this ); connect ( ok, SIGNAL(clicked()), this, SLOT(accept()) ); buttonLayout->addWidget( ok ); QPushButton *cancel = new KPushButton( KStandardGuiItem::cancel(), this ); connect ( cancel, SIGNAL(clicked()), this, SLOT(reject()) ); buttonLayout->addWidget( cancel ); }
void MiniProgrammerUI::setVertical(bool vertical) { if(m_isVertical == vertical) return; m_isVertical = vertical; QBoxLayout *from = ui->horLayout; QBoxLayout *to = ui->vertLayout; if(!vertical) std::swap(from, to); while(from->count() != 0) { QLayoutItem *i = from->takeAt(0); if(i->layout()) { i->layout()->setParent(0); to->addLayout(i->layout()); } else to->addItem(i); } delete to->takeAt(to->count()-1); to->addStretch(1); }
WaitDialog::WaitDialog(QWidget* parent) : QDialog(parent), d(new Private(this)) { // Create the UI this->setObjectName("qttools__WaitDialog"); this->setWindowTitle(tr("Waiting")); this->resize(170, 60); d->m_waitLabel = new QLabel(this); d->m_btnBox = new QDialogButtonBox(this); d->m_btnBox->setStandardButtons(QDialogButtonBox::Abort); d->m_progressBar = new QProgressBar(this); d->m_progressBar->setValue(0); d->m_progressBar->setTextVisible(false); QBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(d->m_waitLabel); layout->addWidget(d->m_progressBar); layout->addWidget(d->m_btnBox); layout->addItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding)); // Configure this->setWindowModality(Qt::ApplicationModal); connect(d->m_updateTimer, SIGNAL(timeout()), this, SLOT(updateProgress())); d->m_updateTimer->setInterval(500); }
//============================================================================ // // class SingleConditionWidget (editor for one condition, used in ConditionEditWidget) // //============================================================================ SingleConditionWidget::SingleConditionWidget( KScoringManager *m, QWidget *p, const char * ) : QFrame( p ), manager( m ) { QBoxLayout *topL = new QVBoxLayout( this ); topL->setMargin( 5 ); QBoxLayout *firstRow = new QHBoxLayout(); topL->addItem( firstRow ); neg = new QCheckBox( i18n( "Not" ), this ); neg->setToolTip( i18n( "Negate this condition" ) ); firstRow->addWidget( neg ); headers = new KComboBox( this ); headers->addItems( manager->getDefaultHeaders() ); headers->setEditable( true ); headers->setToolTip( i18n( "Select the header to match this condition against" ) ); firstRow->addWidget( headers, 1 ); matches = new KComboBox( this ); matches->addItems( KScoringExpression::conditionNames() ); matches->setToolTip( i18n( "Select the type of match" ) ); firstRow->addWidget( matches, 1 ); connect( matches, SIGNAL( activated( int ) ), SLOT( toggleRegExpButton( int ) ) ); QHBoxLayout *secondRow = new QHBoxLayout(); secondRow->setSpacing( 1 ); topL->addItem( secondRow ); expr = new KLineEdit( this ); expr->setToolTip( i18n( "The condition for the match" ) ); // reserve space for at least 20 characters expr->setMinimumWidth( fontMetrics().maxWidth() * 20 ); secondRow->addWidget( expr ); regExpButton = new QPushButton( i18n( "Edit..." ), this ); secondRow->addWidget( regExpButton ); connect( regExpButton, SIGNAL( clicked() ), SLOT( showRegExpDialog() ) ); regExpButton->setEnabled(!KServiceTypeTrader::self()->query( "KRegExpEditor/KRegExpEditor" ).isEmpty()); // occupy at much width as possible setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); setFrameStyle( Box | Sunken ); setLineWidth( 1 ); }
Pana::CrashHandlerWidget::CrashHandlerWidget() { QBoxLayout *layout = new QHBoxLayout( this, 18, 12 ); { QBoxLayout *lay = new QVBoxLayout( layout ); QLabel *label = new QLabel( this ); label->setPixmap( locate( "data", "drkonqi/pics/konqi.png" ) ); label->setFrameStyle( QFrame::Plain | QFrame::Box ); lay->add( label ); lay->addItem( new QSpacerItem( 3, 3, QSizePolicy::Minimum, QSizePolicy::Expanding ) ); } layout = new QVBoxLayout( layout, 6 ); layout->add( new QLabel( /*i18n*/( "<p>" "Pana has crashed! We are terribly sorry about this :(" "<p>" "However you now have an opportunity to help us fix this crash so that it doesn't " "happen again! Click <b>Send Email</b> and Pana will prepare an email that you " "can send to us that contains information about the crash, and we'll try to fix it " "as soon as possible." "<p>" "Thanks for choosing Pana.<br>" ), this ) ); layout = new QHBoxLayout( layout, 6 ); layout->addItem( new QSpacerItem( 6, 6, QSizePolicy::Expanding ) ); layout->add( new KPushButton( KGuiItem( i18n("Send Email"), "mail_send" ), this, "email" ) ); layout->add( new KPushButton( KStdGuiItem::close(), this, "close" ) ); static_cast<QPushButton*>(child("email"))->setDefault( true ); connect( child( "email" ), SIGNAL(clicked()), SLOT(accept()) ); connect( child( "close" ), SIGNAL(clicked()), SLOT(reject()) ); setCaption( i18n("Crash Handler") ); setFixedSize( sizeHint() ); }
TopWidget::TopWidget() : KXmlGuiWindow(0) { // Check command line args for "-kppp" KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); bool kpppmode = args->isSet("kppp"); args->clear(); setCaption(i18n("KPPP Log Viewer")); w = new QWidget(this); QBoxLayout *l = new QVBoxLayout(w); l->setSpacing(5); td = new QTabWidget(w); mw = new MonthlyWidget(); td->addTab(mw, i18n("Monthly Log")); // remove buttons if(!kpppmode) { // create menu mb = new KMenuBar; l->addWidget(mb); l->addWidget(td); QMenu *fm = new QMenu; QAction *action = fm->addAction(QIcon(SmallIcon("application-exit")), KStandardGuiItem::quit().text()); action->setShortcut(Qt::CTRL + Qt::Key_Q); connect(action,SIGNAL(triggered()), this, SLOT(slotExit())); fm->setTitle(i18n("&File")); mb->addMenu(fm); } else { l->addWidget(td); mb = 0; QPushButton *but = new KPushButton(KStandardGuiItem::close(),w); QHBoxLayout *lh = new QHBoxLayout(); l->addItem(lh); lh->addStretch(10); lh->addWidget(but); connect(but, SIGNAL(clicked()), kapp, SLOT(quit())); } setMinimumSize(mw->sizeHint().width() + 15, mw->sizeHint().height() + 120); setCentralWidget(w); }
DistributionListDialog::DistributionListDialog( QWidget *parent ) : KDialog( parent ) { QFrame *topFrame = new QFrame( this ); setMainWidget( topFrame ); setCaption( i18nc("@title:window", "Save Distribution List") ); setButtons( User1 | Cancel ); setDefaultButton( User1 ); setModal( false ); setButtonText( User1, i18nc("@action:button","Save List") ); enableButton( User1, false ); QBoxLayout *topLayout = new QVBoxLayout( topFrame ); topLayout->setSpacing( spacingHint() ); QBoxLayout *titleLayout = new QHBoxLayout(); titleLayout->setSpacing( spacingHint() ); topLayout->addItem( titleLayout ); QLabel *label = new QLabel( i18nc("@label:textbox Name of the distribution list.", "&Name:"), topFrame ); titleLayout->addWidget( label ); mTitleEdit = new KLineEdit( topFrame ); titleLayout->addWidget( mTitleEdit ); mTitleEdit->setFocus(); mTitleEdit->setClearButtonShown( true ); label->setBuddy( mTitleEdit ); mRecipientsList = new QTreeWidget( topFrame ); mRecipientsList->setHeaderLabels( QStringList() << i18nc( "@title:column Name of the recipient","Name" ) << i18nc( "@title:column Email of the recipient", "Email" ) ); mRecipientsList->setRootIsDecorated( false ); topLayout->addWidget( mRecipientsList ); connect( this, SIGNAL( user1Clicked() ), this, SLOT( slotUser1() ) ); connect( mTitleEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( slotTitleChanged( const QString& ) ) ); }
FilterWidget::FilterWidget(TQueryMap opts, QList<Attr*> list, Keeper *keeper, QWidget *parent) : QWidget(parent), keeper(keeper), attrList(list), parentWidget(parent), opts(opts) { innerWidget = new QWidget(this); scrollArea = new QScrollArea(this); scrollArea->setWidget( innerWidget ); scrollArea->setWidgetResizable( true ); innerLayout = new QGridLayout( innerWidget ); innerLayout->setSpacing(2); innerLayout->setMargin(2); QWidget *w = 0; int row = 0; for( int i = 0; i < attrList.size(); i++ ) { QApplication::processEvents(); Attr *a = list.at(i); w = getAttrWidget( a, innerWidget ); if ( !w ) continue; QCheckBox *box = new QCheckBox( a->getTitle(), innerWidget); if ( opts.contains(a->getName()) ) { box->setChecked(true); setWidgetData(a, w, opts[a->getName()]); } else { w->setEnabled(false); } widgetMap.insert( a->getName(), w ); connect(box, SIGNAL(toggled(bool)), w, SLOT(setEnabled(bool))); innerLayout->addWidget( box, row++, 0 ); innerLayout->addWidget( w, row++, 0); } filterButton = new QPushButton(tr("Filter"), innerWidget); filterButton->setIcon(QIcon(":/icons/magnifier.png")); clearButton = new QPushButton(tr("Clear"), innerWidget); clearButton->setIcon(QIcon(":/icons/cancel.png")); connect(filterButton, SIGNAL(clicked()), this, SLOT(filterButton_clicked())); connect(clearButton, SIGNAL(clicked()), this, SLOT(clearButton_clicked())); QBoxLayout *hlayout = new QBoxLayout(QBoxLayout::LeftToRight); hlayout->addWidget(filterButton); hlayout->addWidget(clearButton); hlayout->addItem(new QSpacerItem(10, 10 )); innerLayout->addLayout(hlayout, row++, 0); innerLayout->addItem( new QSpacerItem(20, 1200, QSizePolicy::Maximum, QSizePolicy::Maximum), row, 0); QGridLayout *glayout = new QGridLayout(this); glayout->addWidget(scrollArea, 0, 0); glayout->setSpacing(2); glayout->setMargin(2); setLayout(glayout); }
InterfacePlotterDialog::InterfacePlotterDialog( QString name ) : KDialog(), mConfig( KGlobal::config() ), mConfigDlg( 0 ), mLabelsWidget( NULL ), mSetPos( true ), mWasShown( false ), mUseBitrate( generalSettings->useBitrate ), mMultiplier( 1024 ), mOutgoingVisible( false ), mIncomingVisible( false ), mName( name ) { setCaption( i18nc( "interface name", "%1 Traffic", mName ) ); setButtons( None ); setContextMenuPolicy( Qt::DefaultContextMenu ); mByteUnits << ki18n( "%1 B/s" ) << ki18n( "%1 KiB/s" ) << ki18n( "%1 MiB/s" ) << ki18n( "%1 GiB/s" ); mBitUnits << ki18n( "%1 bit/s" ) << ki18n( "%1 kbit/s" ) << ki18n( "%1 Mbit/s" ) << ki18n( "%1 Gbit/s" ); mIndicatorSymbol = '#'; QFontMetrics fm(font()); if (fm.inFont(QChar(0x25CF))) mIndicatorSymbol = QChar(0x25CF); QBoxLayout *layout = new QVBoxLayout(this); layout->setContentsMargins(0,0,0,0); layout->setSpacing(0); mainWidget()->setLayout( layout ); mPlotter = new KSignalPlotter( this ); int axisTextWidth = fontMetrics().width(i18nc("Largest axis title", "99999 XXXX")); mPlotter->setMaxAxisTextWidth( axisTextWidth ); mPlotter->setShowAxis( true ); mPlotter->setUseAutoRange( true ); layout->addWidget(mPlotter); /* Create a set of labels underneath the graph. */ mLabelsWidget = new QWidget; layout->addWidget(mLabelsWidget); QBoxLayout *outerLabelLayout = new QHBoxLayout(mLabelsWidget); outerLabelLayout->setSpacing(0); outerLabelLayout->setContentsMargins(0,0,0,0); /* create a spacer to fill up the space up to the start of the graph */ outerLabelLayout->addItem(new QSpacerItem(axisTextWidth + 10, 0, QSizePolicy::Preferred)); mLabelLayout = new QHBoxLayout; outerLabelLayout->addLayout(mLabelLayout); mReceivedLabel = new FancyPlotterLabel( this ); mSentLabel = new FancyPlotterLabel( this ); mLabelLayout->addWidget( mSentLabel ); mLabelLayout->addWidget( mReceivedLabel ); // Restore window size and position. KConfig *config = mConfig.data(); KConfigGroup interfaceGroup( config, confg_interface + mName ); if ( interfaceGroup.hasKey( conf_plotterPos ) ) { QPoint p = interfaceGroup.readEntry( conf_plotterPos, QPoint() ); // See comment in event() mSetPos = false; move( p ); } if ( interfaceGroup.hasKey( conf_plotterSize ) ) { QSize s = interfaceGroup.readEntry( conf_plotterSize, QSize() ); // A little hack so the plotter's data isn't chopped off the first time // the dialog appears mPlotter->resize( s ); resize( s ); } else { // HACK mPlotter->resize( 500, 350 ); // Improve the chance that we have a decent sized dialog // the first time it's shown resize( 500, 350 ); } connect( mPlotter, SIGNAL(axisScaleChanged()), this, SLOT(setPlotterUnits()) ); loadConfig(); }
ComponentSelection::ComponentSelection(QWidget * parent) : QFrame(parent) , mSelectedComponents() , mAvailableComponents() , mEditView(NULL) , mListView(NULL) , mShipConfig(NULL) { class PrivateSubscriberAdd : public QObject , private SubscribablePushButton::Subscriber { public: ~PrivateSubscriberAdd() { } PrivateSubscriberAdd(SubscribablePushButton * pushButton, ComponentSelection * componentSelection) : QObject(pushButton) , SubscribablePushButton::Subscriber(pushButton) , mComponentSelection(componentSelection) { } private: void clicked(bool checked) { mComponentSelection->selectedComponentsView()->model()->dropMimeData(mComponentSelection->allComponentsView()->model()->mimeData( mComponentSelection->allComponentsView()->selectionModel()->selectedIndexes()), Qt::CopyAction, -1, -1, QModelIndex()); } ComponentSelection * mComponentSelection; }; class PrivateSubscriberRemove : public QObject , private SubscribablePushButton::Subscriber { public: ~PrivateSubscriberRemove() { } PrivateSubscriberRemove(SubscribablePushButton * pushButton, ComponentSelection * componentSelection) : QObject(pushButton) , SubscribablePushButton::Subscriber(pushButton) , mComponentSelection(componentSelection) { } private: void clicked(bool checked) { QModelIndexList indexList = mComponentSelection->selectedComponentsView()->selectionModel()->selectedRows(); std::set<int> rowSet; for (QModelIndexList::const_iterator it = indexList.begin(); it != indexList.end(); ++it) { rowSet.insert((*it).row()); } #ifdef Q_OS_BLACKBERRY std::set<int>::reverse_iterator it; #else std::set<int>::const_reverse_iterator it; #endif for (it = rowSet.rbegin(); it != rowSet.rend(); ++it) { mComponentSelection->selectedComponentsView()->model()->removeRow(*it); } } ComponentSelection * mComponentSelection; }; class PrivateSubscriberClose : public QObject , private SubscribablePushButton::Subscriber { public: ~PrivateSubscriberClose() { } PrivateSubscriberClose(SubscribablePushButton * pushButton, ComponentSelection * componentSelection) : QObject(pushButton) , SubscribablePushButton::Subscriber(pushButton) , mComponentSelection(componentSelection) { } private: void clicked(bool checked) { if (mComponentSelection->shipConfig() != NULL) { mComponentSelection->shipConfig()->setComponents(mComponentSelection->selectedComponents()); } MainWindow::instance().showFrame(MainWindow::ShipDesignIndex); } ComponentSelection * mComponentSelection; }; QBoxLayout * topLayout = new QVBoxLayout(); setLayout(topLayout); topLayout->setContentsMargins(0,0,0,0); QBoxLayout * tableLayout = new QHBoxLayout(); topLayout->addItem(tableLayout); mEditView = new TableView(this); mEditView->setModel(new ComponentModel(mEditView, NULL)); mEditView->setSelectionBehavior(QAbstractItemView::SelectRows); mEditView->setSelectionMode(QAbstractItemView::MultiSelection); mEditView->viewport()->setAcceptDrops(true); mEditView->setDropIndicatorShown(true); mEditView->setDragDropMode(QAbstractItemView::NoDragDrop); mEditView->hideColumn(1); mEditView->resizeColumnsToContents(); mEditView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); mEditView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); tableLayout->addWidget(mEditView); (new QsKineticScroller(mEditView))->enableKineticScrollFor(mEditView); QVBoxLayout * copyButtonsLayout = new QVBoxLayout(); copyButtonsLayout->addStretch(); SubscribablePushButton * addButton = new SubscribablePushButton(this, tr("<<")); addButton->setObjectName("addButton"); new PrivateSubscriberAdd(addButton, this); copyButtonsLayout->addWidget(addButton); SubscribablePushButton * removeButton = new SubscribablePushButton(this, tr(">>")); removeButton->setObjectName("removeButton"); new PrivateSubscriberRemove(removeButton, this); copyButtonsLayout->addWidget(removeButton); copyButtonsLayout->addStretch(); tableLayout->addLayout(copyButtonsLayout); mListView = new TableView(this); mListView->setModel(new ComponentModel(mListView, NULL)); mListView->setSelectionBehavior(QAbstractItemView::SelectRows); mListView->setSelectionMode(QAbstractItemView::MultiSelection); mListView->setDragEnabled(true); mListView->setDropIndicatorShown(true); mListView->setDragDropMode(QAbstractItemView::NoDragDrop); mListView->resizeColumnsToContents(); mListView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); mListView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); tableLayout->addWidget(mListView); (new QsKineticScroller(mListView))->enableKineticScrollFor(mListView); QBoxLayout * buttonLayout = new QHBoxLayout(); topLayout->addItem(buttonLayout); SubscribablePushButton * closeButton = new SubscribablePushButton(this, tr("Close")); closeButton->setObjectName("closeButton"); new PrivateSubscriberClose(closeButton, this); buttonLayout->addStretch(); buttonLayout->addWidget(closeButton); }
HelpPanel::HelpPanel(QWidget * parent) : QFrame(parent) { class PrivateSubscriberClose : public QObject , private SubscribablePushButton::Subscriber { public: ~PrivateSubscriberClose() { } PrivateSubscriberClose(SubscribablePushButton * pushButton) : QObject(pushButton) , SubscribablePushButton::Subscriber(pushButton) { } private: void clicked(bool checked) { MainWindow::instance().showFrame(MainWindow::MainFrameIndex); } }; QBoxLayout * topLayout = new QVBoxLayout(); setLayout(topLayout); QFormLayout * formLayout = new QFormLayout(); QFrame * buttonsWidget = new QFrame(NULL); buttonsWidget->setLayout(formLayout); buttonsWidget->setObjectName("helpButtonsWidget"); buttonsWidget->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); SubscribablePushButton * moveShipButton = new SubscribablePushButton(NULL, tr("M")); moveShipButton->setObjectName("move"); SubscribablePushButton * colonizeButton = new SubscribablePushButton(NULL, tr("C")); colonizeButton->setObjectName("colonize"); SubscribablePushButton * loadButton = new SubscribablePushButton(NULL, tr("L")); loadButton->setObjectName("load"); SubscribablePushButton * unloadButton = new SubscribablePushButton(NULL, tr("U")); unloadButton->setObjectName("unload"); SubscribablePushButton * buildShipButton = new SubscribablePushButton(NULL, tr("B..")); buildShipButton->setObjectName("build"); SubscribablePushButton * nextTurnButton = new SubscribablePushButton(NULL, tr("T")); nextTurnButton->setObjectName("turn"); SubscribablePushButton * shipDesignButton = new SubscribablePushButton(NULL, tr("D..")); shipDesignButton->setObjectName("design"); SubscribablePushButton * researchButton = new SubscribablePushButton(NULL, tr("R..")); researchButton->setObjectName("research"); SubscribablePushButton * newButton = new SubscribablePushButton(NULL, tr("N..")); newButton->setObjectName("new"); SubscribablePushButton * openButton = new SubscribablePushButton(NULL, tr("O..")); openButton->setObjectName("open"); SubscribablePushButton * saveButton = new SubscribablePushButton(NULL, tr("S..")); saveButton->setObjectName("save"); SubscribablePushButton * quitButton = new SubscribablePushButton(NULL, tr("Q")); quitButton->setObjectName("quit"); SubscribablePushButton * helpButton = new SubscribablePushButton(NULL, tr("H..")); helpButton->setObjectName("help"); SubscribablePushButton * setupButton = new SubscribablePushButton(NULL, tr("S..")); setupButton->setObjectName("setup"); SubscribablePushButton * flagButton = new SubscribablePushButton(NULL, tr("F")); flagButton->setObjectName("flag"); formLayout->addRow(newButton, new QLabel("Start a new game.")); formLayout->addRow(openButton, new QLabel("Open a saved game.")); formLayout->addRow(saveButton, new QLabel("Save current game.")); formLayout->addRow(quitButton, new QLabel("Quit the program.")); formLayout->addRow(helpButton, new QLabel("This help panel.")); formLayout->addRow(setupButton, new QLabel("Setup panel.")); formLayout->addRow(flagButton, new QLabel("Center map on your home system.")); formLayout->addRow(moveShipButton, new QLabel("Move selected ship.")); formLayout->addRow(loadButton, new QLabel("Load population from planet to selected ship.")); formLayout->addRow(unloadButton, new QLabel("Unload population from selected ship to planet.")); formLayout->addRow(colonizeButton, new QLabel("Order selected ship to colonize planet.")); formLayout->addRow(buildShipButton, new QLabel("Create a build order for an existing ship design.")); formLayout->addRow(shipDesignButton, new QLabel("Create a new ship design.")); formLayout->addRow(researchButton, new QLabel("Research new technologies.")); formLayout->addRow(nextTurnButton, new QLabel("Advance time by one month.")); QScrollArea * scrollArea = new QScrollArea(); scrollArea->setWidget(buttonsWidget); scrollArea->setWidgetResizable(true); scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); scrollArea->setObjectName("helpButtonsScrollArea"); topLayout->addWidget(scrollArea); QsKineticScroller * kineticScroller = new QsKineticScroller(scrollArea); kineticScroller->enableKineticScrollFor(scrollArea); QBoxLayout * buttonLayout = new QHBoxLayout(); topLayout->addItem(buttonLayout); SubscribablePushButton * closeButton = new SubscribablePushButton(this, tr("Close")); closeButton->setObjectName("closeButton"); new PrivateSubscriberClose(closeButton); buttonLayout->addStretch(); buttonLayout->addWidget(closeButton); }
ShipConfigBuild::ShipConfigBuild(QWidget * parent) : QFrame(parent) , mEditView(NULL) , mShipConfigs() , mSelectionModel(NULL) , mSector(NULL) { class PrivateSubscriberOK : public QObject , private SubscribablePushButton::Subscriber { public: ~PrivateSubscriberOK() { } PrivateSubscriberOK(SubscribablePushButton * pushButton, ShipConfigBuild * shipConfigBuild) : QObject(pushButton) , SubscribablePushButton::Subscriber(pushButton) , mShipConfigBuild(shipConfigBuild) { } private: void clicked(bool checked) { if (Game::Universe::instance().game().currentPlayer() != NULL && mShipConfigBuild->sector() != NULL) { for (std::vector<ShipConfigModel::Row>::iterator it = mShipConfigBuild->shipConfigs().begin(); it!= mShipConfigBuild->shipConfigs().end(); ++it) { while ((*it).count > 0) { if ((*it).config.cost() <= Game::Universe::instance().game().currentPlayer()->money()) { --(*it).count; Game::Universe::instance().game().currentPlayer()->setMoney(Game::Universe::instance().game().currentPlayer()->money() - (*it).config.cost()); Game::Ship * ship = new Game::Ship(mShipConfigBuild->sector(), (*it).config); ship->setPlayer(Game::Universe::instance().game().currentPlayer()); mShipConfigBuild->sector()->addShip(ship); } else { Game::Messages::instance().post("Insufficient funds."); break; } } } } MainWindow::instance().showFrame(MainWindow::MainFrameIndex); } ShipConfigBuild * mShipConfigBuild; }; class PrivateSubscriberCancel : public QObject , private SubscribablePushButton::Subscriber { public: ~PrivateSubscriberCancel() { } PrivateSubscriberCancel(SubscribablePushButton * pushButton) : QObject(pushButton) , SubscribablePushButton::Subscriber(pushButton) { } private: void clicked(bool checked) { MainWindow::instance().showFrame(MainWindow::MainFrameIndex); } }; class PrivateSubscriberPlus : public QObject , private SubscribablePushButton::Subscriber { public: ~PrivateSubscriberPlus() { } PrivateSubscriberPlus(SubscribablePushButton * pushButton, ShipConfigBuild * shipConfigBuild) : QObject(pushButton) , SubscribablePushButton::Subscriber(pushButton) , mShipConfigBuild(shipConfigBuild) { } private: void clicked(bool checked) { if (Game::Universe::instance().game().currentPlayer() != NULL && mShipConfigBuild->sector() != NULL) { const QModelIndexList & indexList = mShipConfigBuild->selectionModel()->selectedRows(); for (QModelIndexList::const_iterator it = indexList.begin(); it!= indexList.end(); ++it) { ShipConfigModel::Row * shipConfig = static_cast<ShipConfigModel::Row *>((*it).internalPointer()); const_cast<QAbstractItemModel *>(mShipConfigBuild->selectionModel()->model())->setData((*it).sibling((*it).row(), 6), shipConfig->count + 1, Qt::EditRole); } } } ShipConfigBuild * mShipConfigBuild; }; class PrivateSubscriberMinus : public QObject , private SubscribablePushButton::Subscriber { public: ~PrivateSubscriberMinus() { } PrivateSubscriberMinus(SubscribablePushButton * pushButton, ShipConfigBuild * shipConfigBuild) : QObject(pushButton) , SubscribablePushButton::Subscriber(pushButton) , mShipConfigBuild(shipConfigBuild) { } private: void clicked(bool checked) { if (Game::Universe::instance().game().currentPlayer() != NULL && mShipConfigBuild->sector() != NULL) { const QModelIndexList & indexList = mShipConfigBuild->selectionModel()->selectedRows(); for (QModelIndexList::const_iterator it = indexList.begin(); it!= indexList.end(); ++it) { ShipConfigModel::Row * shipConfig = static_cast<ShipConfigModel::Row *>((*it).internalPointer()); if (shipConfig->count > 0) { const_cast<QAbstractItemModel *>(mShipConfigBuild->selectionModel()->model())->setData((*it).sibling((*it).row(), 6), shipConfig->count - 1, Qt::EditRole); } } } } ShipConfigBuild * mShipConfigBuild; }; QBoxLayout * topLayout = new QVBoxLayout(); setLayout(topLayout); topLayout->setContentsMargins(0,0,0,0); mEditView = new TableView(this); //ShipConfigModel * shipConfigModel = new ShipConfigModel(mEditView, NULL); //mEditView->setModel(shipConfigModel); mEditView->setSelectionBehavior(QAbstractItemView::SelectRows); mEditView->setSelectionMode(QAbstractItemView::MultiSelection); mEditView->setEditTriggers(QAbstractItemView::AllEditTriggers); mEditView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); mEditView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); topLayout->addWidget(mEditView); QsKineticScroller * kineticScroller = new QsKineticScroller(mEditView); kineticScroller->enableKineticScrollFor(mEditView); QBoxLayout * buttonLayout = new QHBoxLayout(); topLayout->addItem(buttonLayout); SubscribablePushButton * okButton = new SubscribablePushButton(this, tr("OK")); okButton->setObjectName("okButton"); new PrivateSubscriberOK(okButton, this); SubscribablePushButton * cancelButton = new SubscribablePushButton(this, tr("Cancel")); cancelButton->setObjectName("cancelButton"); new PrivateSubscriberCancel(cancelButton); SubscribablePushButton * plusButton = new SubscribablePushButton(this, tr("+")); plusButton->setObjectName("plusButton"); new PrivateSubscriberPlus(plusButton, this); SubscribablePushButton * minusButton = new SubscribablePushButton(this, tr("-")); minusButton->setObjectName("minusButton"); new PrivateSubscriberMinus(minusButton, this); buttonLayout->addStretch(); buttonLayout->addWidget(plusButton); buttonLayout->addWidget(minusButton); buttonLayout->addWidget(okButton); buttonLayout->addWidget(cancelButton); class SpinBoxDelegate : public QItemDelegate { public: SpinBoxDelegate(QObject * parent) : QItemDelegate(parent) { } QWidget *createEditor(QWidget * parent, const QStyleOptionViewItem &, const QModelIndex &) const { QSpinBox * editor = new QSpinBox(parent); editor->setMinimum(0); editor->setMaximum(100); return editor; } void setEditorData(QWidget * editor, const QModelIndex & index) const { int value = index.model()->data(index, Qt::DisplayRole).toInt(); QSpinBox * spinBox = static_cast<QSpinBox *>(editor); spinBox->setValue(value); } void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const { QSpinBox * spinBox = static_cast<QSpinBox *>(editor); spinBox->interpretText(); int value = spinBox->value(); model->setData(index, value, Qt::EditRole); } void updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex &) const { editor->setGeometry(option.rect); } }; SpinBoxDelegate * delegate = new SpinBoxDelegate(mEditView); mEditView->setItemDelegateForColumn(2, delegate); }
//------------------------------------------------------------------------------ void MoleculeElDensSurfaceWidget::CreateGUI() { const QSettings s; /// Layouts // Main layout QVBoxLayout* mainLayout = new QVBoxLayout(); /// Density QHBoxLayout* densityMatrixLayout = new QHBoxLayout; densityMatrixCheckBox_ = new QCheckBox( tr( "Density Matrix" ) ); densityMatrixCheckBox_->setChecked( false ); densityMatrixLayout->addWidget( densityMatrixCheckBox_ ); connect( densityMatrixCheckBox_, SIGNAL( toggled( bool ) ), this, SLOT( DensityMatrixToggledSlot( bool ) ) ); mainLayout->addItem( densityMatrixLayout ); /// MEP QHBoxLayout* mepLayout = new QHBoxLayout; QCheckBox* mepCheckBox = new QCheckBox( tr( "Map Molecular Electrostatic Potential" ) ); mepCheckBox->setChecked( false ); mepLayout->addWidget( mepCheckBox ); connect( mepCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( MEPMappingToggledSlot( bool ) ) ); mainLayout->addItem( mepLayout ); /// Orbitals // Table table_ = new QTableWidget(); table_->setColumnCount( 4 ); QStringList labels; labels << tr( "Generated" ) << tr( "Eigenvalue" ) << tr( "Occupation" ) << tr( "Type" ); table_->setHorizontalHeaderLabels( labels ); table_->setEditTriggers( QAbstractItemView::NoEditTriggers ); table_->setAlternatingRowColors( true ); connect( table_, SIGNAL( cellClicked( int, int ) ), this, SLOT( TableCellClickedSlot( int, int ) ) ); table_->setSelectionBehavior( QAbstractItemView::SelectRows ); table_->setEnabled( false ); // Value & step QLabel* valueLabel = new QLabel( tr( "Isosurface Value" ) ); valueSpinBox_ = new QDoubleSpinBox; const double value = s.value( ISOVALUE_KEY, 0.05 ).toDouble(); valueSpinBox_->setValue( value ); valueSpinBox_->setSingleStep( 0.01 ); valueSpinBox_->setDecimals( 4 ); connect( valueSpinBox_, SIGNAL( valueChanged( double ) ), this, SLOT( ComputeSteps() ) ); QHBoxLayout* valueLayout = new QHBoxLayout; valueLayout->setSpacing( 40 ); valueLayout->addWidget( valueLabel ); valueLayout->addWidget( valueSpinBox_ ); // Check boxes for sign and nodal surface signCheckBox_ = new QCheckBox( "Use both signs" ); nodalSurfaceCheckBox_ = new QCheckBox( "Generate Nodal Surface" ); Qt::CheckState checked = Qt::CheckState( s.value( BOTH_SIGNS_KEY, Qt::Unchecked ).toInt() ); signCheckBox_->setCheckState( checked ); checked = Qt::CheckState( s.value( NODAL_SURFACE_KEY, Qt::Unchecked ).toInt() ); nodalSurfaceCheckBox_->setCheckState( checked ); QHBoxLayout* checkBoxesLayout = new QHBoxLayout; checkBoxesLayout->setSpacing( 40 ); checkBoxesLayout->addWidget( signCheckBox_ ); checkBoxesLayout->addWidget( nodalSurfaceCheckBox_ ); connect( signCheckBox_, SIGNAL( stateChanged( int ) ), this, SLOT( BothSignsSlot( int ) ) ); connect( nodalSurfaceCheckBox_, SIGNAL( stateChanged( int ) ), this, SLOT( NodalSurfaceSlot( int ) ) ); // Combo box for rendering style and transparency QLabel* renderingStyleLabel = new QLabel( tr( "Rendering Style" ) ); renderingStyleComboBox_ = new QComboBox; renderingStyleComboBox_->addItem( tr( "Solid" ), int( MolekelMolecule::SOLID ) ); renderingStyleComboBox_->addItem( tr( "Wireframe" ), int( MolekelMolecule::WIREFRAME ) ); renderingStyleComboBox_->addItem( tr( "Points" ), int( MolekelMolecule::POINTS ) ); renderingStyleComboBox_->setCurrentIndex( 0 ); connect( renderingStyleComboBox_, SIGNAL( currentIndexChanged( int ) ), this, SLOT( RenderingStyleChangedSlot( int ) ) ); QBoxLayout* rsLayout = new QHBoxLayout; rsLayout->addWidget( renderingStyleLabel ); rsLayout->addWidget( renderingStyleComboBox_ ); // Transparency. QGridLayout* tLayout = new QGridLayout; // density matrix dmTransparencyWidget_ = new QDoubleSpinBox; dmTransparencyWidget_->setRange( 0, 1 ); dmTransparencyWidget_->setSingleStep( 0.05 ); double transparency = s.value( DENSITY_MATRIX_TRANSPARENCY_KEY, 0.0 ).toDouble(); dmTransparencyWidget_->setValue( transparency ); connect( dmTransparencyWidget_, SIGNAL( valueChanged( double ) ), this, SLOT( DMTransparencyChangedSlot( double ) ) ); tLayout->addWidget( new QLabel( "Density Matrix" ), 0, 0 ); tLayout->addWidget( dmTransparencyWidget_, 0, 1 ); // negative negTransparencyWidget_ = new QDoubleSpinBox; negTransparencyWidget_->setRange( 0, 1 ); negTransparencyWidget_->setSingleStep( 0.05 ); transparency = s.value( NEGATIVE_TRANSPARENCY_KEY, 0.0 ).toDouble(); negTransparencyWidget_->setValue( transparency ); connect( negTransparencyWidget_, SIGNAL( valueChanged( double ) ), this, SLOT( NegTransparencyChangedSlot( double ) ) ); tLayout->addWidget( new QLabel( "Negative" ), 1, 0 ); tLayout->addWidget( negTransparencyWidget_, 1, 1 ); // nodal nodTransparencyWidget_ = new QDoubleSpinBox; nodTransparencyWidget_->setRange( 0, 1 ); nodTransparencyWidget_->setSingleStep( 0.05 ); transparency = s.value( NODAL_TRANSPARENCY_KEY, 0.0 ).toDouble(); nodTransparencyWidget_->setValue( transparency ); connect( nodTransparencyWidget_, SIGNAL( valueChanged( double ) ), this, SLOT( NodalTransparencyChangedSlot( double ) ) ); tLayout->addWidget( new QLabel( "Nodal" ), 2, 0 ); tLayout->addWidget( nodTransparencyWidget_, 2, 1 ); // positive posTransparencyWidget_ = new QDoubleSpinBox; posTransparencyWidget_->setRange( 0, 1 ); posTransparencyWidget_->setSingleStep( 0.05 ); transparency = s.value( POSITIVE_TRANSPARENCY_KEY, 0.0 ).toDouble(); posTransparencyWidget_->setValue( transparency ); connect( posTransparencyWidget_, SIGNAL( valueChanged( double ) ), this, SLOT( PosTransparencyChangedSlot( double ) ) ); tLayout->addWidget( new QLabel( "Positive" ), 3, 0 ); tLayout->addWidget( posTransparencyWidget_, 3, 1 ); // Color buttons QBoxLayout* cLayout = new QVBoxLayout; cLayout->setSpacing( 3 ); QPushButton* pb = new QPushButton( "Density Matrix" ); connect( pb, SIGNAL( released() ), this, SLOT( DensityMatrixColorSlot() ) ); cLayout->addWidget( pb ); pb = new QPushButton( "Negative" ); connect( pb, SIGNAL( released() ), this, SLOT( NegativeOrbitalColorSlot() ) ); cLayout->addWidget( pb ); pb = new QPushButton( "Nodal" ); connect( pb, SIGNAL( released() ), this, SLOT( NodalSurfaceColorSlot() ) ); cLayout->addWidget( pb ); pb = new QPushButton( "Positive" ); connect( pb, SIGNAL( released() ), this, SLOT( PositiveOrbitalColorSlot() ) ); cLayout->addWidget( pb ); FoldableWidget* tGroup = new FoldableWidget( tLayout, "Transparency" ); FoldableWidget* cGroup = new FoldableWidget( cLayout, "Color" ); QBoxLayout* renderingStyleLayout = new QVBoxLayout; renderingStyleLayout->setSpacing( 3 ); renderingStyleLayout->addItem( rsLayout ); QBoxLayout* tcLayout = new QHBoxLayout; tcLayout->addWidget( tGroup ); tcLayout->addWidget( cGroup ); renderingStyleLayout->addItem( tcLayout ); // Step size QLabel* stepSizeLabel = new QLabel( tr( "Step Size" ) ); stepSizeSpinBox_ = new QDoubleSpinBox; const double sstep = s.value( STEP_SIZE_KEY, 0.25 ).toDouble(); stepSizeSpinBox_->setSingleStep( 0.025 ); stepSizeSpinBox_->setValue( sstep ); connect( stepSizeSpinBox_, SIGNAL( valueChanged( double ) ), this, SLOT( ComputeSteps() ) ); QHBoxLayout* stepSizeLayout = new QHBoxLayout; stepSizeLayout->setSpacing( 50 ); stepSizeLayout->addWidget( stepSizeLabel ); stepSizeLayout->addWidget( stepSizeSpinBox_ ); // Bounding box QGroupBox* bboxFrame = new QGroupBox; bboxFrame->setTitle( tr( "Bounding Box" ) ); QGridLayout* bboxLayout = new QGridLayout; //bboxLayout->setSpacing( 30 ); // all parameters will be re-recomputed from actual molecule // bounding box data const double MAXVALUE = 100.0; // center x bboxLayout->addWidget( new QLabel( tr( "x:" ) ), 0, 0 ); xSpinBox_ = new QDoubleSpinBox; xSpinBox_->setSingleStep( 0.1 ); xSpinBox_->setMinimum( -MAXVALUE ); xSpinBox_->setMaximum( MAXVALUE ); xSpinBox_->setDecimals( 2 ); bboxLayout->addWidget( xSpinBox_, 0, 1 ); connect( xSpinBox_, SIGNAL( valueChanged( double ) ), this, SLOT( MoveCenterSlot() ) ); // center y bboxLayout->addWidget( new QLabel( tr( "y:" ) ), 0, 2 ); ySpinBox_ = new QDoubleSpinBox; ySpinBox_->setSingleStep( 0.1 ); ySpinBox_->setMinimum( -MAXVALUE ); ySpinBox_->setMaximum( MAXVALUE ); ySpinBox_->setDecimals( 2 ); bboxLayout->addWidget( ySpinBox_, 0, 3 ); connect( ySpinBox_, SIGNAL( valueChanged( double ) ), this, SLOT( MoveCenterSlot() ) ); // center z bboxLayout->addWidget( new QLabel( tr( "z:" ) ), 0, 4 ); zSpinBox_ = new QDoubleSpinBox; zSpinBox_->setSingleStep( 0.1 ); zSpinBox_->setMinimum( -MAXVALUE ); zSpinBox_->setMaximum( MAXVALUE ); zSpinBox_->setDecimals( 2 ); bboxLayout->addWidget( zSpinBox_, 0, 5 ); connect( zSpinBox_, SIGNAL( valueChanged( double ) ), this, SLOT( MoveCenterSlot() ) ); // dx bboxLayout->addWidget( new QLabel( tr( "dx:" ) ), 1, 0 ); dxSpinBox_ = new QDoubleSpinBox; dxSpinBox_->setSingleStep( 0.1 ); bboxLayout->addWidget( dxSpinBox_, 1, 1 ); connect( dxSpinBox_, SIGNAL( valueChanged( double ) ), this, SLOT( ComputeSteps() ) ); // dy bboxLayout->addWidget( new QLabel( tr( "dy:" ) ), 1, 2 ); dySpinBox_ = new QDoubleSpinBox; dySpinBox_->setSingleStep( 0.1 ); bboxLayout->addWidget( dySpinBox_, 1, 3 ); connect( dySpinBox_, SIGNAL( valueChanged( double ) ), this, SLOT( ComputeSteps() ) ); // dz bboxLayout->addWidget( new QLabel( tr( "dz:" ) ), 1, 4 ); dzSpinBox_ = new QDoubleSpinBox; dzSpinBox_->setSingleStep( 0.1 ); bboxLayout->addWidget( dzSpinBox_, 1, 5 ); connect( dzSpinBox_, SIGNAL( valueChanged( double ) ), this, SLOT( ComputeSteps() ) ); bboxFrame->setLayout( bboxLayout ); // Steps QGroupBox* stepsFrame = new QGroupBox; stepsFrame->setTitle( tr( "Steps" ) ); QGridLayout* stepsLayout = new QGridLayout; //stepsLayout->setSpacing( 20 ); // nx stepsLayout->addWidget( new QLabel( tr( "Nx" ) ), 0, 0 ); nxLineEdit_ = new QLabel; nxLineEdit_->setFrameStyle( QFrame::StyledPanel ); //nxLineEdit_->setEnabled( false ); stepsLayout->addWidget( nxLineEdit_, 1, 0 ); // ny stepsLayout->addWidget( new QLabel( tr( "Ny" ) ), 0, 1 ); nyLineEdit_ = new QLabel; nyLineEdit_->setFrameStyle( QFrame::StyledPanel ); //nyLineEdit_->setEnabled( false ); stepsLayout->addWidget( nyLineEdit_, 1, 1 ); // nz stepsLayout->addWidget( new QLabel( tr( "Nz" ) ), 0, 2 ); nzLineEdit_ = new QLabel; nzLineEdit_->setFrameStyle( QFrame::StyledPanel ); //nzLineEdit_->setEnabled( false ); stepsLayout->addWidget( nzLineEdit_, 1, 2 ); stepsFrame->setLayout( stepsLayout ); // Bounding box + steps QHBoxLayout* bboxStepsLayout = new QHBoxLayout; bboxStepsLayout->setSpacing( 8 ); bboxStepsLayout->addWidget( bboxFrame ); bboxStepsLayout->addWidget( stepsFrame ); /// Fill layout mainLayout->addWidget( table_ ); mainLayout->addItem( valueLayout ); mainLayout->addItem( checkBoxesLayout ); mainLayout->addItem( stepSizeLayout ); mainLayout->addItem( bboxStepsLayout ); mainLayout->addItem( renderingStyleLayout ); /// Assign layout to this widget this->setLayout( mainLayout ); }
void QBoxLayoutProto::addItem(QLayoutItem *item) { QBoxLayout *boxitem = qscriptvalue_cast<QBoxLayout*>(thisObject()); if (boxitem) boxitem->addItem(item); }