PreFlightGliderPage::PreFlightGliderPage(QWidget *parent) : QWidget(parent), m_lastGlider(0) { setObjectName("PreFlightGliderPage"); setWindowFlags( Qt::Tool ); setWindowModality( Qt::WindowModal ); setAttribute(Qt::WA_DeleteOnClose); setWindowTitle( tr("PreFlight - Glider") ); if( parent ) { resize( parent->size() ); } QHBoxLayout *contentLayout = new QHBoxLayout; setLayout(contentLayout); QGridLayout* topLayout = new QGridLayout; topLayout->setMargin(5); contentLayout->addLayout(topLayout); int row = 0; QLabel* lblPilot = new QLabel(tr("Pilot:"), this); topLayout->addWidget(lblPilot, row, 0); Qt::InputMethodHints imh; m_edtPilot = new QLineEdit(this); imh = (m_edtPilot->inputMethodHints() | Qt::ImhNoPredictiveText); m_edtPilot->setInputMethodHints(imh); m_edtPilot->setText( GeneralConfig::instance()->getSurname() ); connect( m_edtPilot, SIGNAL(returnPressed()), MainWindow::mainWindow(), SLOT(slotCloseSip()) ); topLayout->addWidget(m_edtPilot, row, 1); QLabel* lblLoad = new QLabel(tr("Load corr:"), this); topLayout->addWidget(lblLoad, row, 2); m_edtLoad = new NumberEditor; m_edtLoad->setDecimalVisible( false ); m_edtLoad->setPmVisible( true ); m_edtLoad->setMaxLength(4); m_edtLoad->setSuffix(" kg"); m_edtLoad->setRange( -999, 999 ); m_edtLoad->setValue( 0 ); topLayout->addWidget(m_edtLoad, row, 3); row++; m_edtCoPilotLabel = new QLabel(tr("Copilot:"), this); topLayout->addWidget(m_edtCoPilotLabel, row, 0); m_edtCoPilot = new QLineEdit(this); m_edtCoPilot->setInputMethodHints(imh); connect( m_edtCoPilot, SIGNAL(returnPressed()), MainWindow::mainWindow(), SLOT(slotCloseSip()) ); topLayout->addWidget(m_edtCoPilot, row, 1); QLabel* lblWater = new QLabel(tr("Water ballast:"), this); topLayout->addWidget(lblWater, row, 2); m_edtWater = new NumberEditor; m_edtWater->setDecimalVisible( false ); m_edtWater->setPmVisible( false ); m_edtWater->setMaxLength(4); m_edtWater->setSuffix(" l"); m_edtWater->setRange( 0, 9999 ); m_edtWater->setValue( 0 ); topLayout->addWidget(m_edtWater, row, 3); row++; QHBoxLayout* hbox = new QHBoxLayout; hbox->addWidget( new QLabel(tr("Ref. weight:"), this) ); m_refWeight = new QLabel; m_refWeight->setFocusPolicy(Qt::NoFocus); hbox->addWidget( m_refWeight, 10 ); topLayout->addLayout( hbox, row, 0, 1, 2 ); hbox = new QHBoxLayout; hbox->addWidget( new QLabel(tr("Wing load:"), this) ); m_wingLoad = new QLabel; m_wingLoad->setFocusPolicy(Qt::NoFocus); hbox->addWidget( m_wingLoad, 10 ); topLayout->addLayout( hbox, row, 2, 1, 2 ); row++; topLayout->setRowMinimumHeight( row, 10 ); row++; m_gliderList = new GliderListWidget( this, true ); #ifndef ANDROID m_gliderList->setToolTip(tr("Select a glider to be used")); #endif #ifdef ANDROID QScrollBar* lvsb = m_gliderList->verticalScrollBar(); lvsb->setStyleSheet( Layout::getCbSbStyle() ); #endif #ifdef QSCROLLER QScroller::grabGesture(m_gliderList->viewport(), QScroller::LeftMouseButtonGesture); #endif #ifdef QTSCROLLER QtScroller::grabGesture(m_gliderList->viewport(), QtScroller::LeftMouseButtonGesture); #endif topLayout->addWidget(m_gliderList, row, 0, 1, 4); row++; //--------------------------------------------------------------------- QPushButton* deselect = new QPushButton( tr("Deselect"), this ); #ifndef ANDROID deselect->setToolTip( tr("Clear glider selection") ); #endif topLayout->addWidget( deselect, row, 3 ); //--------------------------------------------------------------------- m_gliderList->fillList(); m_gliderList->clearSelection(); m_gliderList->selectItemFromList(); connect(deselect, SIGNAL(clicked()), this, SLOT(slotGliderDeselected()) ); connect(m_gliderList, SIGNAL(itemSelectionChanged()), this, SLOT(slotGliderChanged())); connect(m_edtLoad, SIGNAL(numberEdited(const QString&)), this, SLOT(slotLoadEdited(const QString&))); connect(m_edtWater, SIGNAL(numberEdited(const QString&)), this, SLOT(slotWaterEdited(const QString&))); QPushButton *help = new QPushButton(this); help->setIcon(QIcon(GeneralConfig::instance()->loadPixmap("help32.png"))); help->setIconSize(QSize(Layout::getButtonSize(12), Layout::getButtonSize(12))); help->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::QSizePolicy::Preferred); QPushButton *cancel = new QPushButton(this); cancel->setIcon(QIcon(GeneralConfig::instance()->loadPixmap("cancel.png"))); cancel->setIconSize(QSize(Layout::getButtonSize(12), Layout::getButtonSize(12))); cancel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::QSizePolicy::Preferred); QPushButton *ok = new QPushButton(this); ok->setIcon(QIcon(GeneralConfig::instance()->loadPixmap("ok.png"))); ok->setIconSize(QSize(Layout::getButtonSize(12), Layout::getButtonSize(12))); ok->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::QSizePolicy::Preferred); QLabel *titlePix = new QLabel(this); titlePix->setAlignment( Qt::AlignCenter ); titlePix->setPixmap( _globalMapConfig->createGlider(315, 1.6) ); connect(help, SIGNAL(pressed()), this, SLOT(slotHelp())); connect(ok, SIGNAL(pressed()), this, SLOT(slotAccept())); connect(cancel, SIGNAL(pressed()), this, SLOT(slotReject())); QVBoxLayout *buttonBox = new QVBoxLayout; buttonBox->setSpacing(0); buttonBox->addWidget(help, 1); buttonBox->addStretch(2); buttonBox->addWidget(cancel, 1); buttonBox->addSpacing(30); buttonBox->addWidget(ok, 1); buttonBox->addStretch(2); buttonBox->addWidget(titlePix); contentLayout->addLayout(buttonBox); }
QWidget* WidgetStyle::createWidget(const QString& name) { if(name == "CheckBox") { QCheckBox* box = new QCheckBox("CheckBox"); box->setObjectName("CheckBox"); return setLayoutWidget({ box }, { 100, 30 }); } else if(name == "ComboBox") { QComboBox* box = new QComboBox; box->addItem("Item1"); box->addItem("Item3"); box->addItem("Item3"); box->setObjectName("ComboBox"); return setLayoutWidget({ box }, { 70, 30 }); } else if(name == "DateEdit") { QDateEdit* date = new QDateEdit; date->setObjectName("DateEdit"); return setLayoutWidget({ date }, { 110, 40 }); } else if(name == "DateTimeEdit") { QDateTimeEdit* date = new QDateTimeEdit; date->setObjectName("DateTimeEdit"); return setLayoutWidget({ date }, { 160, 30 }); } else if(name == "Dialog") { QDialog* dialog = new QDialog; dialog->setObjectName("Dialog"); return setLayoutWidget({ dialog }, { 160, 110 }); } else if(name == "DockWidget") //? { QDockWidget* widget = new QDockWidget; widget->setObjectName("DockWidget"); widget->resize(61, 22); return widget; } else if(name == "DoubleSpinBox") { QDoubleSpinBox* box = new QDoubleSpinBox; box->setObjectName("DoubleSpinBox"); return setLayoutWidget({ box }, { 90, 40 }); } else if(name == "Frame") //?? { QFrame* frame = new QFrame; frame->setObjectName("Frame"); frame->resize(150, 100); return frame; } else if(name == "GroupBox") { QGroupBox* box = new QGroupBox("GroupBox"); box->setObjectName("GroupBox"); return setLayoutWidget({ box }, { 160, 110 }); } else if(name == "Label") { QLabel* label = new QLabel("Label"); label->setObjectName("Label"); return setLayoutWidget({ label }, { 40, 20}); } else if(name == "LineEdit") { QLineEdit* line = new QLineEdit; line->setObjectName("LineEdit"); return setLayoutWidget({ line }, { 30, 30 }); } else if(name == "ListView") //?? { QListView* view = new QListView; view->setObjectName("ListView"); view->resize(71, 71); return view; } else if(name == "ListWidget") { QListWidget* list = new QListWidget; list->setObjectName("ListWidget"); for(int i = 0; i < 20; i++) list->addItem(QString("Item %1").arg(i)); return setLayoutWidget({ list }, { 80, 80 }); } else if(name == "MainWindow") { QMainWindow* window = new QMainWindow; window->setObjectName("MainWindow"); return setLayoutWidget({ window }, { 160, 110 }); } else if(name == "Menu") { QMenu* parentMenu = new QMenu; parentMenu->setObjectName("Menu"); parentMenu->addMenu("Menu1"); QMenu* menu1 = parentMenu->addMenu("Menu2"); menu1->addMenu("Menu1"); menu1->addMenu("Menu2"); parentMenu->addSeparator(); parentMenu->addMenu("Menu3"); return setLayoutWidget({ parentMenu }, { 160, 110 }); } else if(name == "MenuBar") { QMenuBar* bar = new QMenuBar; bar->setObjectName("QMenuBar"); QMenu* menu1 = bar->addMenu("MenuBar1"); menu1->addMenu("Menu1"); menu1->addSeparator(); menu1->addMenu("Menu2"); QMenu* menu2 = bar->addMenu("MenuBar2"); menu2->addMenu("Menu1"); menu2->addSeparator(); menu2->addMenu("Menu2"); QMenu* menu3 = bar->addMenu("MenuBar3"); menu3->addMenu("Menu1"); menu3->addSeparator(); menu3->addMenu("Menu2"); return setLayoutWidget({ bar }, { 280, 60 }); } else if(name == "ProgressBar") { QProgressBar* bar = new QProgressBar; bar->setObjectName("ProgressBar"); bar->setRange(0, 100); bar->setValue(0); QTimer* timer = new QTimer(bar); this->connect(timer, &QTimer::timeout, this, [bar]() { if(bar->value() == 100) bar->setValue(0); else bar->setValue(bar->value() + 1); }); timer->start(100); return setLayoutWidget({ bar }, { 110, 30 }); } else if(name == "PushButton") { QPushButton* button = new QPushButton("PushButton"); button->setObjectName("PushButton"); return setLayoutWidget({ button }, { 125, 30 }); } else if(name == "RadioButton") { QRadioButton* button = new QRadioButton("RadioButton"); button->setObjectName("RadioButton"); return setLayoutWidget({ button }, { 125, 30 }); } else if(name == "ScrollBar") { QScrollBar* barH = new QScrollBar(Qt::Horizontal); QScrollBar* barV = new QScrollBar(Qt::Vertical); barH->setObjectName("ScrollBarH"); barV->setObjectName("ScrollBarV"); return setLayoutWidget({ barH, barV }, { 200, 100 }); } else if(name == "Slider") { QSlider* sliderH = new QSlider(Qt::Horizontal); QSlider* sliderV = new QSlider(Qt::Vertical); sliderH->setObjectName("SliderH"); sliderV->setObjectName("SliderV"); return setLayoutWidget({ sliderH, sliderV }, { 200, 100 }); } else if(name == "SpinBox") { QSpinBox* spinBox = new QSpinBox; spinBox->setObjectName("SpinBox"); return setLayoutWidget({ spinBox }, { 60, 35 }); } else if(name == "Splitter") { QSplitter* splitterV = new QSplitter(Qt::Vertical); QSplitter* splitterH = new QSplitter(Qt::Horizontal); splitterV->setObjectName("SplitterV"); splitterH->setObjectName("SplitterH"); splitterV->addWidget(new QPushButton("PushButton1")); splitterV->addWidget(new QPushButton("PushButton2")); splitterH->addWidget(splitterV); splitterH->addWidget(new QPushButton("PushButton3")); return setLayoutWidget({ splitterH }, { 250, 110 }); } else if(name == "TabWidget") { QTabWidget* tab = new QTabWidget; tab->addTab(new QWidget, "Widget1"); tab->addTab(new QWidget, "Widget2"); tab->addTab(new QWidget, "Widget3"); tab->setObjectName("TabWidget"); return setLayoutWidget({ tab }, { 210, 110 }); } else if(name == "TableView") //? { QTableView* view = new QTableView; view->setObjectName("TableView"); view->resize(200, 100); return view; } else if(name == "TableWidget") { const int n = 100; QStringList list = { "one", "two", "three" }; QTableWidget* table = new QTableWidget(n, n); table->setObjectName("TableWidget"); table->setHorizontalHeaderLabels(list); table->setVerticalHeaderLabels(list); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) table->setItem(i, j, new QTableWidgetItem(QString("%1, %2").arg(i).arg(j))); return setLayoutWidget({ table }, { 210, 110 }); } else if(name == "TextEdit") { QTextEdit* text = new QTextEdit; text->setObjectName("TextEdit"); return setLayoutWidget({ text }, { 80, 80 }); } else if(name == "TimeEdit") { QTimeEdit* time = new QTimeEdit; time->setObjectName("TimeEdit"); return setLayoutWidget({ time }, { 80, 80 }); } else if(name == "ToolButton") { QToolButton* button = new QToolButton; button->setText("ToolButton"); button->setObjectName("ToolButton"); return setLayoutWidget({ button }, { 95, 25 }); } else if(name == "ToolBox") { QToolBox* box = new QToolBox; box->addItem(new QWidget, "Widget1"); box->addItem(new QWidget, "Widget2"); box->addItem(new QWidget, "Widget3"); box->setObjectName("ToolBox"); return setLayoutWidget({ box }, { 110, 180 }); } else if(name == "TreeView") //? { QTreeView* tree = new QTreeView; tree->setObjectName("TreeView"); tree->resize(200, 100); return tree; } else if(name == "TreeWidget") { QTreeWidget* tree = new QTreeWidget; tree->setObjectName("TreeWidget"); tree->setHeaderLabels({ "Folders", "Used Space" }); QTreeWidgetItem* item = new QTreeWidgetItem(tree); item->setText(0, "Local Disk"); for(int i = 1; i < 20; i++) { QTreeWidgetItem* dir = new QTreeWidgetItem(item); dir->setText(0, "Directory" + QString::number(i)); dir->setText(1, QString::number(i) + "MB"); } tree->setItemExpanded(item, true); return setLayoutWidget({ tree }, { 210, 110 }); } else if(name == "Widget") { QWidget* widget = new QWidget; widget->setObjectName("Widget"); return setLayoutWidget({ widget }, { 210, 110 }); } return nullptr; }
void tst_QAbstractScrollArea::setScrollBars2() { QAbstractScrollArea scrollArea; scrollArea.resize(300, 300); QScrollBar *hbar = new QScrollBar; scrollArea.setHorizontalScrollBar(hbar); qApp->processEvents(); QCOMPARE(scrollArea.horizontalScrollBar(), hbar); QScrollBar *vbar = new QScrollBar; scrollArea.setVerticalScrollBar(vbar); qApp->processEvents(); QCOMPARE(scrollArea.verticalScrollBar(), vbar); scrollArea.horizontalScrollBar()->setRange(0, 100); scrollArea.verticalScrollBar()->setRange(0, 100); scrollArea.show(); // Make sure scroll bars are not explicitly hidden by QAbstractScrollArea itself. QVERIFY(hbar->isVisible()); QVERIFY(vbar->isVisible()); // Hide the OLD scroll bar and ensure that the NEW one is hidden. hbar->hide(); scrollArea.setHorizontalScrollBar(new QScrollBar); qApp->processEvents(); QVERIFY(!scrollArea.horizontalScrollBar()->isVisible()); vbar->hide(); scrollArea.setVerticalScrollBar(new QScrollBar); qApp->processEvents(); QVERIFY(!scrollArea.verticalScrollBar()->isVisible()); scrollArea.verticalScrollBar()->show(); scrollArea.horizontalScrollBar()->show(); // Hide the NEW scroll bar and ensure that it's visible // (because the OLD one is visible). hbar = new QScrollBar; hbar->hide(); scrollArea.setHorizontalScrollBar(hbar); qApp->processEvents(); QVERIFY(hbar->isVisible()); vbar = new QScrollBar; vbar->hide(); scrollArea.setVerticalScrollBar(vbar); qApp->processEvents(); QVERIFY(vbar->isVisible()); vbar->setRange(0, 0); qApp->processEvents(); QVERIFY(!vbar->isVisible()); hbar->setRange(0, 0); qApp->processEvents(); QVERIFY(!hbar->isVisible()); }
void ChatAreaWidget::onSliderRangeChanged() { QScrollBar* scroll = verticalScrollBar(); if (lockSliderToBottom) scroll->setValue(scroll->maximum()); }
/** * Adds a log entry */ void LogWidget::log(LogType logType, QString text) { #ifndef INTEGRATION_TESTS // return if logging wasn't enabled if (!qApp->property("loggingEnabled").toBool()) { return; } QString type = ""; QColor color = QColor(Qt::black); switch (logType) { case DebugLogType: if (!ui->debugCheckBox->isChecked()) { return; } type = "debug"; // gray color = QColor(98, 98, 98); break; case InfoLogType: if (!ui->infoCheckBox->isChecked()) { return; } type = "info"; color = QColor(Qt::darkBlue); break; case WarningLogType: if (!ui->warningCheckBox->isChecked()) { return; } type = "warning"; // orange color = QColor(255, 128, 0); break; case CriticalLogType: if (!ui->criticalCheckBox->isChecked()) { return; } type = "critical"; // light red color = QColor(192, 0, 0); break; case FatalLogType: if (!ui->fatalCheckBox->isChecked()) { return; } type = "fatal"; // lighter red color = QColor(210, 0, 0); break; case StatusLogType: if (!ui->statusCheckBox->isChecked()) { return; } type = "status"; // green color = QColor(0, 128, 0); break; case ScriptingLogType: if (!ui->scriptingCheckBox->isChecked()) { return; } type = "scripting"; // blue color = QColor(0, 102, 255); break; default: type = "unknown"; break; } QDateTime dateTime = QDateTime::currentDateTime(); // text.prepend("[" + dateTime.toString("hh:mm:ss") + "] [" + type + "] "); // text.append("\n"); QString html = QString("<div style=\"color: %1\">[%2] [%3] %4</div><br />") .arg(color.name(), dateTime.toString("hh:mm:ss"), type, text.toHtmlEscaped()); QScrollBar *scrollBar = ui->logTextEdit->verticalScrollBar(); // we want to scroll down later if the scrollbar is near the end bottom bool scrollDown = scrollBar->value() >= (scrollBar->maximum() - scrollBar->singleStep()); QTextCursor c = ui->logTextEdit->textCursor(); // insert the text at the end c.movePosition(QTextCursor::End); c.insertHtml(html); if (scrollDown) { // move the text cursor to the end ui->logTextEdit->moveCursor(QTextCursor::End); } #else Q_UNUSED(logType); Q_UNUSED(text); #endif }
void Console::scrollDown() { QScrollBar *vbar = verticalScrollBar(); vbar->setValue(vbar->maximum()); }
ReportList::ReportList(BoxType type, bool sortByScore, QWidget *parent) : QMainWindow(parent) { this->sort = sortByScore; printAction = new QAction("&Print...", this); QMenu* fileMenu = menuBar()->addMenu("&File"); fileMenu->addAction(printAction); connect(printAction, SIGNAL(triggered()), this, SLOT(print())); QWidget* central = new QWidget(); this->setCentralWidget(central); QHBoxLayout* mainLayout = new QHBoxLayout(); central->setLayout(mainLayout); this->reports = new QStackedWidget(); int size = 0; if(type == employee) { employeeData = DataInterface::getEmployees(); if(sortByScore) { this->setWindowTitle("Employee View - Sorted By Average Score"); qSort(employeeData.begin(), employeeData.end()); } else { this->setWindowTitle("Employee View"); } size = employeeData.size(); for(int i = 0; i < size; i++) { EmployeeReportBox* box = new EmployeeReportBox(employeeData.at(i), i, size); reports->addWidget(box); } } else if(type == employer) { this->setWindowTitle("Employer View"); employerData = DataInterface::getEmployers(); size = employerData.size(); for(int i = 0; i < size; i++) { EmployerReportBox* box = new EmployerReportBox(employerData.at(i), i, size); reports->addWidget(box); } } else { QMessageBox::information(this, "Failed To Read Data", "Failed to read the data from the file."); return; } QScrollBar *scrollBar = new QScrollBar(Qt::Vertical); scrollBar->setRange(0, size - 1); scrollBar->setValue(0); scrollBar->setFocusPolicy(Qt::WheelFocus); connect(scrollBar, SIGNAL(valueChanged(int)), this, SLOT(moveToBox(int))); this->setFixedHeight(370); reports->setCurrentIndex(0); mainLayout->addWidget(reports); mainLayout->addWidget(scrollBar); }
void MapArea::mouseMoveEvent(QMouseEvent *event) { const QPoint &point = event->pos(); if( !mapInfo || !this->rect().contains(point) ) return; // Move sliders if( event->buttons() & Qt::RightButton ) { globalPoint = event->globalPos(); QScrollBar *hSB = scrollArea->horizontalScrollBar(); hSB->setSliderPosition(hSB->sliderPosition() - globalPoint.x() + lastGlobalPoint.x()); QScrollBar *vSB = scrollArea->verticalScrollBar(); vSB->setSliderPosition(vSB->sliderPosition() - globalPoint.y() + lastGlobalPoint.y()); lastGlobalPoint = globalPoint; } const int tileX = point.x() / tileSize; const int tileY = point.y() / tileSize; const QRect &rc = QRect(tileX * tileSize, tileY * tileSize, tileSize, tileSize); // Draw objects, if LMB and current item is valid. if( (event->buttons() & Qt::LeftButton) && (mainForm->currentItem) ) { isHighlight = false; MapInfo::Tile &tile = mapInfo->tiles[tileY][tileX]; // On map const sh_p<ObjectInfo> newObj = objectFromItem[mainForm->currentItem]; // In mouse // *** currentItem is only from currentToolboxIndex *** switch( mainForm->currentToolboxIndex ) { case 0: // Tools { sh_p<ObjectInfo> &obj = tile.object; if( obj != newObj ) { AddObjectWithPainter(frontPixmap, rc, obj, newObj); } } break; case 1: // Terrain changing { sh_p<ObjectInfo> &terr = tile.terrain; if( terr != newObj ) { AddObjectWithPainter(groundPixmap, rc, terr, newObj); } } break; case 2: // Resource add { sh_p<ObjectInfo> &obj = tile.object; if( obj != newObj ) { AddObjectWithPainter(frontPixmap, rc, obj, newObj); } } break; } } else // Highlight current rectangle { isHighlight = true; } // Update rects if( lastRc.topLeft() != rc.topLeft() ) { this->update(lastRc); lastRc = rc; this->update(lastRc); } }
void TrackListView::populateTable()/*{{{*/ { if(debugMsg) printf("TrackListView::populateTable\n"); QScrollBar *bar = m_table->verticalScrollBar(); int barPos = 0; if(bar) barPos = bar->sliderPosition(); m_model->clear(); for(iMidiTrack i = song->artracks()->begin(); i != song->artracks()->end(); ++i) { MidiTrack* track = (MidiTrack*)(*i); PartList* pl = track->parts(); if(m_displayRole == PartRole && pl->empty()) { continue; } QStandardItem* trackName = new QStandardItem(); trackName->setForeground(QBrush(QColor(205,209,205))); trackName->setBackground(QBrush(QColor(20,20,20))); trackName->setFont(QFont("fixed-width", 10, QFont::Bold)); trackName->setText(track->name()); trackName->setCheckable(true); trackName->setCheckState(m_selectedTracks.contains(track->id()) ? Qt::Checked : Qt::Unchecked); trackName->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); trackName->setData(1, TrackRole); trackName->setData(track->name(), TrackNameRole); trackName->setData(track->id(), TrackIdRole); trackName->setEditable(true); m_model->appendRow(trackName); for(iPart ip = pl->begin(); ip != pl->end(); ++ip) { Part* part = ip->second; QStandardItem* partName = new QStandardItem(); partName->setFont(QFont("fixed-width", 9, QFont::Bold)); partName->setText(part->name()); partName->setData(part->sn(), PartRole); partName->setData(2, TrackRole); partName->setData(track->name(), TrackNameRole); partName->setData(part->name(), PartNameRole); partName->setData(part->tick(), TickRole); partName->setData(track->id(), TrackIdRole); partName->setEditable(true); partName->setCheckable(true); partName->setCheckState(m_editor->hasPart(part->sn()) ? Qt::Checked : Qt::Unchecked); if(!partColorIcons.isEmpty() && part->colorIndex() < partColorIcons.size()) partName->setIcon(partColorIcons.at(part->colorIndex())); m_model->appendRow(partName); } } m_model->setHorizontalHeaderLabels(m_headers); if(m_selectedIndex < m_model->rowCount()) { m_table->selectRow(m_selectedIndex); m_table->scrollTo(m_model->index(m_selectedIndex, 0)); } if(bar) bar->setSliderPosition(barPos); }/*}}}*/
void GroupChatForm::onSliderRangeChanged() { QScrollBar* scroll = chatArea->verticalScrollBar(); if (lockSliderToBottom) scroll->setValue(scroll->maximum()); }
void CtrlRegisterList::paintEvent(QPaintEvent *) { int numRowsTotal = cpu->GetNumRegsInCategory(category); int maxRowsDisplay =rect().bottom()/rowHeight - 1; selection = std::min(std::max(selection,0),numRowsTotal); curVertOffset = std::max(std::min(curVertOffset,numRowsTotal - maxRowsDisplay),0); QScrollBar *bar = findChild<QScrollBar*>("RegListScroll"); if(bar) { bar->setMinimum(0); bar->setMaximum(numRowsTotal - maxRowsDisplay); bar->setPageStep(1); bar->setValue(curVertOffset); } QPainter painter(this); painter.setBrush(Qt::white); painter.setPen(Qt::white); painter.drawRect(rect()); if (!cpu) return; QFont normalFont = QFont("Arial", 10); painter.setFont(normalFont); int width = rect().width(); QColor bgColor(0xffffff); QPen nullPen(bgColor); QPen currentPen(QColor(0xFF000000)); QPen selPen(0x808080); QPen textPen; QBrush lbr; lbr.setColor(bgColor); QBrush nullBrush(bgColor); QBrush currentBrush(0xFFEfE8); QBrush pcBrush(0x70FF70); int nc = cpu->GetNumCategories(); for (int i=0; i<nc; i++) { painter.setPen(i==category?currentPen:nullPen); painter.setBrush(i==category?pcBrush:nullBrush); painter.drawRect(width*i/nc,0,width*(i+1)/nc - width*i/nc -1,rowHeight-1); QString name = cpu->GetCategoryName(i); painter.setPen(currentPen); painter.drawText(width*i/nc+1,-3+rowHeight,name); } int numRows=rect().bottom()/rowHeight; for (int i=curVertOffset; i<curVertOffset+numRows; i++) { int rowY1 = rowHeight*(i-curVertOffset+1); int rowY2 = rowHeight*(i-curVertOffset+2)-1; lbr.setColor(i==selection?0xffeee0:0xffffff); painter.setBrush(currentBrush); painter.setPen(nullPen); painter.drawRect(0,rowY1,16-1,rowY2-rowY1); if (selecting && i == selection) painter.setPen(selPen); else painter.setPen(nullPen); QBrush mojsBrush(lbr.color()); painter.setBrush(mojsBrush); painter.drawRect(16,rowY1,width-16-1,rowY2-rowY1); // Check for any changes in the registers. if (lastPC != cpu->GetPC()) { for (int i = 0, n = cpu->GetNumRegsInCategory(0); i < n; ++i) { u32 v = cpu->GetRegValue(0, i); changedCat0Regs[i] = v != lastCat0Values[i]; lastCat0Values[i] = v; } lastPC = cpu->GetPC(); } painter.setBrush(currentBrush); if (i<cpu->GetNumRegsInCategory(category)) { QString regName = cpu->GetRegName(category,i); textPen.setColor(0x600000); painter.setPen(textPen); painter.drawText(17,rowY1-3+rowHeight,regName); textPen.setColor(0xFF000000); painter.setPen(textPen); char temp[256]; cpu->PrintRegValue(category,i,temp); if (category == 0 && changedCat0Regs[i]) { textPen.setColor(0x0000FF); painter.setPen(textPen); } else { textPen.setColor(0x004000); painter.setPen(textPen); } painter.drawText(77,rowY1-3+rowHeight,temp); } } }
void gestureEvent(QGestureEvent *event) { QPanGesture *pan = static_cast<QPanGesture *>(event->gesture(Qt::PanGesture)); if (pan) { switch(pan->state()) { case Qt::GestureStarted: qDebug() << this << "Pan: started"; break; case Qt::GestureFinished: qDebug() << this << "Pan: finished"; break; case Qt::GestureCanceled: qDebug() << this << "Pan: canceled"; break; case Qt::GestureUpdated: break; default: qDebug() << this << "Pan: <unknown state>"; break; } if (pan->state() == Qt::GestureStarted) outside = false; event->ignore(); event->ignore(pan); if (outside) return; const QPointF delta = pan->delta(); const QPointF totalOffset = pan->offset(); QScrollBar *vbar = verticalScrollBar(); QScrollBar *hbar = horizontalScrollBar(); if ((vbar->value() == vbar->minimum() && totalOffset.y() > 10) || (vbar->value() == vbar->maximum() && totalOffset.y() < -10)) { outside = true; return; } if ((hbar->value() == hbar->minimum() && totalOffset.x() > 10) || (hbar->value() == hbar->maximum() && totalOffset.x() < -10)) { outside = true; return; } vbar->setValue(vbar->value() - delta.y()); hbar->setValue(hbar->value() - delta.x()); event->accept(pan); } }
void LogViewForm::scrollToBottom() { QScrollBar* vsb = logTextEdit->verticalScrollBar(); vsb->setValue(vsb->maximum()); logTextEdit->update(); }
void ScriptLogWindow::ScrollChanged(int val) { QScrollBar *scroll = scriptLogWidget->verticalScrollBar(); bottomScrolled = (val == scroll->maximum()); }
void KTreeView::KTreeViewPrivate::updateVerticalScrollBar(int value) { QScrollBar *scrollBar = parent->horizontalScrollBar(); scrollBar->setValue(value); }
void Serveur::ecrire(QString txt,QString destChan,QString msgTray) { if(destChan.toStdString() == "Console/PM") { affichage->setHtml(affichage->toHtml()+txt); QScrollBar *sb = affichage->verticalScrollBar(); sb->setValue(sb->maximum()); } else if(destChan!="") { conversations[destChan]->setHtml(conversations[destChan]->toHtml()+txt); QScrollBar *sb = conversations[destChan]->verticalScrollBar(); sb->setValue(sb->maximum()); } else if(txt.startsWith("#")) { QString dest=txt.split(" ").first(); QStringList list=txt.split(" "); list.removeFirst(); txt=list.join(" "); conversations[dest]->setHtml(conversations[dest]->toHtml()+txt); QScrollBar *sb = conversations[dest]->verticalScrollBar(); sb->setValue(sb->maximum()); } else { affichage->setHtml(affichage->toHtml()+txt); QScrollBar *sb = affichage->verticalScrollBar(); sb->setValue(sb->maximum()); } }
void DiffZoomWidget::setDiffView(DiffView *view) { diffview = view; QScrollBar *sb = const_cast<QScrollBar*>(diffview->scrollBar()); sb->installEventFilter(this); }
void GuiFindToolBar::on_findDown() { termline *line; tree234 *whichtree; unsigned long tchar; GuiTerminalWindow *gterm = mainWnd->getCurrentTerminal(); Terminal *term; QScrollBar *scrollbar; QString str = ""; int tempStartPosition = 0; int tempCol, tempRow; if (!gterm) return; term = gterm->term; scrollbar = gterm->verticalScrollBar(); findTextFlag = true; if(getSearchedText() == "") { findTextFlag = false; gterm->viewport()->repaint(); return; } tempCol = currentCol; tempRow = currentRow; currentCol = currentCol + currentSearchedText.length(); if(getSearchedText().compare(currentSearchedText, Qt::CaseInsensitive)) { pageStartPosition = scrollbar->value(); currentSearchedText = getSearchedText(); if(currentCol < 0) currentCol = 0; whichtree = NULL; } if(currentRow < 0) currentRow = scrollbar->value(); while(1) { str = ""; if(currentRow >= scrollbar->maximum()+term->rows) { currentRow = 0; } if(count234(term->scrollback) > currentRow) { whichtree = term->scrollback; unsigned char *cline = (unsigned char*)index234(whichtree, currentRow); line = (termline*) decompressline(cline, NULL); } else { whichtree = term->screen; line = (termline*)index234(whichtree, abs(currentRow - count234(term->scrollback))); } for(int i = 0; line && i < line->size; i++) { //qDebug() << line->chars[i].chr; tchar = line->chars[i].chr; switch (tchar & CSET_MASK) { case CSET_ASCII: tchar = term->ucsdata->unitab_line[tchar & 0xFF]; break; case CSET_LINEDRW: tchar = term->ucsdata->unitab_xterm[tchar & 0xFF]; break; case CSET_SCOACS: tchar = term->ucsdata->unitab_scoacs[tchar&0xFF]; break; } str.append((char)tchar); } if(currentCol < term->cols && (currentCol = str.indexOf(currentSearchedText, currentCol, Qt::CaseInsensitive)) >= 0) { if(pageStartPosition != scrollbar->value()) gterm->setScrollBar(scrollbar->maximum()+term->rows, pageStartPosition, term->rows); else { if(currentRow < scrollbar->value() || currentRow >= (scrollbar->value() + term->rows)) { gterm->setScrollBar(scrollbar->maximum()+term->rows, currentRow, term->rows); pageStartPosition = scrollbar->value(); } } currentSearchedText = str.mid(currentCol, currentSearchedText.length()); tempStartPosition = pageStartPosition; break; } tempStartPosition++; if(tempStartPosition > (scrollbar->maximum()+term->rows)) { findTextFlag = false; currentCol = tempCol; currentRow = tempRow; gterm->viewport()->repaint(); return; } currentRow++; currentCol = 0; } gterm->viewport()->repaint(); }
void MainWindow::appendToLog(QString msg) { ui->parsedOutputPlainTextEdit->appendPlainText(msg); QScrollBar *scrollbar = ui->parsedOutputPlainTextEdit->verticalScrollBar(); scrollbar->setValue(scrollbar->maximum()); }
void PianorollTrackView::ensureNoteVisible( VSQ_NS::tick_t tick, VSQ_NS::tick_t length, int noteNumber) { int left = controllerAdapter->getXFromTick(tick); int right = controllerAdapter->getXFromTick(tick + length); QRect visibleArea = ui->mainContent->getVisibleArea(); QScrollBar *horizontalScrollBar = ui->mainContent->horizontalScrollBar(); QScrollBar *verticalScrollBar = ui->mainContent->verticalScrollBar(); int dx = 0; int newValue = verticalScrollBar->value(); if (visibleArea.right() < right) { dx = ui->mainContent->width() - (right - left); } else if (left < visibleArea.left()) { dx = -ui->mainContent->width() + (right - left); } if (0 <= noteNumber) { int top = getYFromNoteNumber(noteNumber, trackHeight); int bottom = top + trackHeight; if (top < visibleArea.top() || visibleArea.bottom() < bottom) { newValue = (bottom + top) / 2 - visibleArea.height() / 2; } if (verticalScrollBar->value() != newValue) { if (newValue < verticalScrollBar->minimum()) { verticalScrollBar->setValue(verticalScrollBar->minimum()); } else if (verticalScrollBar->maximum() < newValue) { verticalScrollBar->setValue(verticalScrollBar->maximum()); } else { verticalScrollBar->setValue(newValue); } } } if (dx) { int value = horizontalScrollBar->value() + dx; if (value < horizontalScrollBar->minimum()) { horizontalScrollBar->setValue(horizontalScrollBar->minimum()); } else if (horizontalScrollBar->maximum() < value) { horizontalScrollBar->setValue(horizontalScrollBar->maximum()); } else { horizontalScrollBar->setValue(value); } } }
bool QtScrollerFilter::eventFilter_QAbstractScrollArea(QAbstractScrollArea *area, QEvent *event) { switch (event->type()) { case QtScrollPrepareEvent::ScrollPrepare: { QtScrollPrepareEvent *se = static_cast<QtScrollPrepareEvent *>(event); if (canStartScrollingAt_QAbstractScrollArea(area, se->startPos().toPoint())) { QScrollBar *hBar = area->horizontalScrollBar(); QScrollBar *vBar = area->verticalScrollBar(); se->setViewportSize(QSizeF(area->viewport()->size())); se->setContentPosRange(QRectF(0, 0, hBar->maximum(), vBar->maximum())); se->setContentPos(QPointF(hBar->value(), vBar->value())); se->accept(); return true; } return false; } case QtScrollEvent::Scroll: { QtScrollEvent *se = static_cast<QtScrollEvent *>(event); QScrollBar *hBar = area->horizontalScrollBar(); QScrollBar *vBar = area->verticalScrollBar(); hBar->setValue(se->contentPos().x()); vBar->setValue(se->contentPos().y()); QPoint os = overshoot.value(area); #ifdef Q_WS_WIN typedef BOOL (*PtrBeginPanningFeedback)(HWND); typedef BOOL (*PtrUpdatePanningFeedback)(HWND, LONG, LONG, BOOL); typedef BOOL (*PtrEndPanningFeedback)(HWND, BOOL); static PtrBeginPanningFeedback ptrBeginPanningFeedback = 0; static PtrUpdatePanningFeedback ptrUpdatePanningFeedback = 0; static PtrEndPanningFeedback ptrEndPanningFeedback = 0; if (!ptrBeginPanningFeedback) ptrBeginPanningFeedback = (PtrBeginPanningFeedback) QLibrary::resolve(QLatin1String("UxTheme"), "BeginPanningFeedback"); if (!ptrUpdatePanningFeedback) ptrUpdatePanningFeedback = (PtrUpdatePanningFeedback) QLibrary::resolve(QLatin1String("UxTheme"), "UpdatePanningFeedback"); if (!ptrEndPanningFeedback) ptrEndPanningFeedback = (PtrEndPanningFeedback) QLibrary::resolve(QLatin1String("UxTheme"), "EndPanningFeedback"); if (ptrBeginPanningFeedback && ptrUpdatePanningFeedback && ptrEndPanningFeedback) { WId wid = area->window()->winId(); if (!se->overshootDistance().isNull() && os.isNull()) ptrBeginPanningFeedback(wid); if (!se->overshootDistance().isNull()) ptrUpdatePanningFeedback(wid, -se->overshootDistance().x(), -se->overshootDistance().y(), false); if (se->overshootDistance().isNull() && !os.isNull()) ptrEndPanningFeedback(wid, true); } else #endif { QPoint delta = os - se->overshootDistance().toPoint(); if (!delta.isNull()) { ignoreMove = true; area->viewport()->move(area->viewport()->pos() + delta); ignoreMove = false; } } overshoot[area] = se->overshootDistance().toPoint(); return true; } case QEvent::Move: { if (!ignoreMove && !overshoot.value(area).isNull()) { ignoreMove = true; area->viewport()->move(area->viewport()->pos() - overshoot.value(area)); ignoreMove = false; } return false; } default: return false; } }
QSize PianorollTrackView::getPreferredMainContentSceneSize() { QScrollBar *scrollBar = ui->mainContent->verticalScrollBar(); int width = controllerAdapter->getPreferredComponentWidth() - scrollBar->width(); int height = trackHeight * (NOTE_MAX - NOTE_MIN + 1); return QSize(width, height); }
void ChatAreaWidget::checkSlider() { QScrollBar* scroll = verticalScrollBar(); lockSliderToBottom = scroll && scroll->value() == scroll->maximum(); }
// ------------------------------------------------------------------------- void ctkTreeComboBox::resizePopup() { // copied from QComboBox.cpp Q_D(ctkTreeComboBox); QStyle * const style = this->style(); QWidget* container = qobject_cast<QWidget*>(this->view()->parent()); QStyleOptionComboBox opt; this->initStyleOption(&opt); QRect listRect(style->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxListBoxPopup, this)); QRect screen = QApplication::desktop()->availableGeometry( QApplication::desktop()->screenNumber(this)); QPoint below = this->mapToGlobal(listRect.bottomLeft()); int belowHeight = screen.bottom() - below.y(); QPoint above = this->mapToGlobal(listRect.topLeft()); int aboveHeight = above.y() - screen.y(); bool boundToScreen = !this->window()->testAttribute(Qt::WA_DontShowOnScreen); const bool usePopup = style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this); { int listHeight = 0; int count = 0; QStack<QModelIndex> toCheck; toCheck.push(this->view()->rootIndex()); #ifndef QT_NO_TREEVIEW QTreeView *treeView = qobject_cast<QTreeView*>(this->view()); if (treeView && treeView->header() && !treeView->header()->isHidden()) listHeight += treeView->header()->height(); #endif while (!toCheck.isEmpty()) { QModelIndex parent = toCheck.pop(); for (int i = 0; i < this->model()->rowCount(parent); ++i) { QModelIndex idx = this->model()->index(i, this->modelColumn(), parent); if (!idx.isValid()) { continue; } listHeight += this->view()->visualRect(idx).height(); /* + container->spacing() */; #ifndef QT_NO_TREEVIEW if (this->model()->hasChildren(idx) && treeView && treeView->isExpanded(idx)) { toCheck.push(idx); } #endif ++count; if (!usePopup && count > this->maxVisibleItems()) { toCheck.clear(); break; } } } listRect.setHeight(listHeight); } { // add the spacing for the grid on the top and the bottom; int heightMargin = 0;//2*container->spacing(); // add the frame of the container int marginTop, marginBottom; container->getContentsMargins(0, &marginTop, 0, &marginBottom); heightMargin += marginTop + marginBottom; //add the frame of the view this->view()->getContentsMargins(0, &marginTop, 0, &marginBottom); //marginTop += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(this->view()))->top; //marginBottom += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(this->view()))->bottom; heightMargin += marginTop + marginBottom; listRect.setHeight(listRect.height() + heightMargin); } // Add space for margin at top and bottom if the style wants it. if (usePopup) { listRect.setHeight(listRect.height() + style->pixelMetric(QStyle::PM_MenuVMargin, &opt, this) * 2); } // Make sure the popup is wide enough to display its contents. if (usePopup) { const int diff = d->computeWidthHint() - this->width(); if (diff > 0) { listRect.setWidth(listRect.width() + diff); } } //we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show container->layout()->activate(); //takes account of the minimum/maximum size of the container listRect.setSize( listRect.size().expandedTo(container->minimumSize()) .boundedTo(container->maximumSize())); // make sure the widget fits on screen if (boundToScreen) { if (listRect.width() > screen.width() ) { listRect.setWidth(screen.width()); } if (this->mapToGlobal(listRect.bottomRight()).x() > screen.right()) { below.setX(screen.x() + screen.width() - listRect.width()); above.setX(screen.x() + screen.width() - listRect.width()); } if (this->mapToGlobal(listRect.topLeft()).x() < screen.x() ) { below.setX(screen.x()); above.setX(screen.x()); } } if (usePopup) { // Position horizontally. listRect.moveLeft(above.x()); #ifndef Q_WS_S60 // Position vertically so the curently selected item lines up // with the combo box. const QRect currentItemRect = this->view()->visualRect(this->view()->currentIndex()); const int offset = listRect.top() - currentItemRect.top(); listRect.moveTop(above.y() + offset - listRect.top()); #endif // Clamp the listRect height and vertical position so we don't expand outside the // available screen geometry.This may override the vertical position, but it is more // important to show as much as possible of the popup. const int height = !boundToScreen ? listRect.height() : qMin(listRect.height(), screen.height()); #ifdef Q_WS_S60 //popup needs to be stretched with screen minimum dimension listRect.setHeight(qMin(screen.height(), screen.width())); #else listRect.setHeight(height); #endif if (boundToScreen) { if (listRect.top() < screen.top()) { listRect.moveTop(screen.top()); } if (listRect.bottom() > screen.bottom()) { listRect.moveBottom(screen.bottom()); } } #ifdef Q_WS_S60 if (screen.width() < screen.height()) { // in portait, menu should be positioned above softkeys listRect.moveBottom(screen.bottom()); } else { TRect staConTopRect = TRect(); AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStaconTop, staConTopRect); listRect.setWidth(listRect.height()); //by default popup is centered on screen in landscape listRect.moveCenter(screen.center()); if (staConTopRect.IsEmpty()) { // landscape without stacon, menu should be at the right (opt.direction == Qt::LeftToRight) ? listRect.setRight(screen.right()) : listRect.setLeft(screen.left()); } } #endif } else if (!boundToScreen || listRect.height() <= belowHeight) { listRect.moveTopLeft(below); } else if (listRect.height() <= aboveHeight) { listRect.moveBottomLeft(above); } else if (belowHeight >= aboveHeight) { listRect.setHeight(belowHeight); listRect.moveTopLeft(below); } else { listRect.setHeight(aboveHeight); listRect.moveBottomLeft(above); } #if QT_VERSION < QT_VERSION_CHECK(5,0,0) && !defined QT_NO_IM if (QInputContext *qic = this->inputContext()) { qic->reset(); } #endif QScrollBar *sb = this->view()->horizontalScrollBar(); Qt::ScrollBarPolicy policy = this->view()->horizontalScrollBarPolicy(); bool needHorizontalScrollBar = (policy == Qt::ScrollBarAsNeeded || policy == Qt::ScrollBarAlwaysOn) && sb->minimum() < sb->maximum(); if (needHorizontalScrollBar) { listRect.adjust(0, 0, 0, sb->height()); } container->setGeometry(listRect); }
void pTreeComboBox::calculPopupGeometry() { if ( !mView ) { return; } QStyle * const style = this->style(); // set current item and select it view()->selectionModel()->setCurrentIndex( mCurrentIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows ); QFrame* container = mFrame; QStyleOptionComboBox opt; initStyleOption( &opt ); QRect listRect( style->subControlRect( QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxListBoxPopup, this ) ); QRect screen = popupGeometry( QApplication::desktop()->screenNumber( this ) ); QPoint below = mapToGlobal( listRect.bottomLeft() ); int belowHeight = screen.bottom() -below.y(); QPoint above = mapToGlobal( listRect.topLeft() ); int aboveHeight = above.y() -screen.y(); bool boundToScreen = !window()->testAttribute( Qt::WA_DontShowOnScreen ); listRect.moveTopLeft( mapToGlobal( rect().bottomLeft() ) ); listRect.setSize( QSize( qMax( qMax( view()->viewport()->width(), mFrame->width() ), width() ) , qMax( view()->viewport()->height(), mFrame->height() ) ) ); const bool usePopup = style->styleHint( QStyle::SH_ComboBox_Popup, &opt, this ); { int listHeight = 0; int count = 0; QStack<QModelIndex> toCheck; toCheck.push( view()->rootIndex() ); #ifndef QT_NO_TREEVIEW QTreeView* treeView = qobject_cast<QTreeView*>( view() ); if ( treeView && treeView->header() && !treeView->header()->isHidden() ) listHeight += treeView->header()->height(); #endif while ( !toCheck.isEmpty() ) { QModelIndex parent = toCheck.pop(); for ( int i = 0; i < model()->rowCount( parent ); ++i ) { QModelIndex idx = model()->index( i, mModelColumn, parent ); if ( !idx.isValid() ) continue; listHeight += view()->visualRect( idx ).height(); #ifndef QT_NO_TREEVIEW if ( model()->hasChildren( idx ) && treeView && treeView->isExpanded( idx ) ) toCheck.push( idx ); #endif ++count; if ( !usePopup && count > mMaxVisibleItems ) { toCheck.clear(); break; } } } listRect.setHeight( listHeight ); } { // add the spacing for the grid on the top and the bottom; int heightMargin = 0; // add the frame of the container int marginTop, marginBottom; container->getContentsMargins( 0, &marginTop, 0, &marginBottom ); heightMargin += marginTop +marginBottom; //add the frame of the view view()->getContentsMargins( 0, &marginTop, 0, &marginBottom ); marginTop += 0/*static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top*/; marginBottom += 0/*static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom*/; heightMargin += marginTop +marginBottom; listRect.setHeight( listRect.height() +heightMargin ); } // Add space for margin at top and bottom if the style wants it. if ( usePopup ) listRect.setHeight( listRect.height() +style->pixelMetric( QStyle::PM_MenuVMargin, &opt, this ) *2 ); // Make sure the popup is wide enough to display its contents. if ( usePopup ) { const int diff = sizeHint().width() /*d->computeWidthHint()*/ -width(); if ( diff > 0 ) listRect.setWidth( listRect.width() +diff ); } //we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show container->layout()->activate(); //takes account of the minimum/maximum size of the container listRect.setSize( listRect.size().expandedTo(container->minimumSize()) .boundedTo(container->maximumSize())); // make sure the widget fits on screen if (boundToScreen) { if (listRect.width() > screen.width() ) listRect.setWidth(screen.width()); if (/*mapToGlobal(*/listRect/*.bottomRight())*/.x() > screen.right()) { below.setX(screen.x() + screen.width() - listRect.width()); above.setX(screen.x() + screen.width() - listRect.width()); } if (/*mapToGlobal(*/listRect/*.topLeft())*/.x() < screen.x() ) { below.setX(screen.x()); above.setX(screen.x()); } } if ( usePopup ) { // Position horizontally. listRect.moveLeft( above.x() ); // Position vertically so the curently selected item lines up // with the combo box. /*const QRect currentItemRect = view()->visualRect( view()->currentIndex() ); const int offset = listRect.top() -currentItemRect.top(); listRect.moveTop( above.y() +offset -listRect.top() );*/ // Clamp the listRect height and vertical position so we don't expand outside the // available screen geometry.This may override the vertical position, but it is more // important to show as much as possible of the popup. const int height = !boundToScreen ? listRect.height() : qMin(listRect.height(), screen.height()); listRect.setHeight(height); if (boundToScreen) { if (listRect.top() < screen.top()) listRect.moveTop(screen.top()); if (listRect.bottom() > screen.bottom()) listRect.moveBottom(screen.bottom()); } } else if (!boundToScreen || listRect.height() <= belowHeight) { listRect.moveTopLeft(below); } else if (listRect.height() <= aboveHeight) { listRect.moveBottomLeft(above); } else if (belowHeight >= aboveHeight) { listRect.setHeight(belowHeight); listRect.moveTopLeft(below); } else { listRect.setHeight(aboveHeight); listRect.moveBottomLeft(above); } #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) #ifndef QT_NO_IM if ( QInputContext *qic = inputContext() ) qic->reset(); #endif #endif QScrollBar* sb = view()->horizontalScrollBar(); Qt::ScrollBarPolicy policy = view()->horizontalScrollBarPolicy(); bool needHorizontalScrollBar = ( policy == Qt::ScrollBarAsNeeded || policy == Qt::ScrollBarAlwaysOn ) && sb->minimum() < sb->maximum(); if ( needHorizontalScrollBar ) { listRect.adjust( 0, 0, 0, sb->height() ); } container->setGeometry( listRect ); #ifndef Q_WS_MAC const bool updatesEnabled = container->updatesEnabled(); #endif #if defined( Q_WS_WIN ) && !defined( QT_NO_EFFECTS ) // FIXME Fix me ASAP /*bool scrollDown = ( listRect.topLeft() == below ); if ( QApplication::isEffectEnabled( Qt::UI_AnimateCombo ) && !style->styleHint( QStyle::SH_ComboBox_Popup, &opt, this ) && !window()->testAttribute( Qt::WA_DontShowOnScreen ) ) qScrollEffect( container, scrollDown ? QEffects::DownScroll : QEffects::UpScroll, 150 );*/ #endif // Don't disable updates on Mac OS X. Windows are displayed immediately on this platform, // which means that the window will be visible before the call to container->show() returns. // If updates are disabled at this point we'll miss our chance at painting the popup // menu before it's shown, causing flicker since the window then displays the standard gray // background. #ifndef Q_WS_MAC container->setUpdatesEnabled( false ); #endif container->raise(); container->show(); //container->updateScrollers(); view()->setFocus(); view()->scrollTo( view()->currentIndex(), style->styleHint( QStyle::SH_ComboBox_Popup, &opt, this ) ? QAbstractItemView::PositionAtCenter : QAbstractItemView::EnsureVisible ); #ifndef Q_WS_MAC container->setUpdatesEnabled( updatesEnabled ); #endif container->update(); #ifdef QT_KEYPAD_NAVIGATION if ( QApplication::keypadNavigationEnabled() ) view()->setEditFocus( true ); #endif }
//----------------------------------------------------------------------------- //! Rebuilt the trip history list layout, which updates the trip history list //----------------------------------------------------------------------------- void tTripHistoryList::RebuildList(tFocusAction focusAction) { m_WidgetToDataMap.clear(); QWidget* pFocusWidget = 0; pFocusWidget = focusWidget(); QLayout* pLayout = layout(); // Rebuilding the layout. may need to record focus index of current widget, and record current QScrollArea vertical position. int focusIndex = -1; int verticalScrollPos = -1; tScrollArea* pScrollArea = GetScrollAreaLayout(pLayout); if (pScrollArea != 0) { QScrollBar* pVerticalBar = pScrollArea->verticalScrollBar(); verticalScrollPos = pVerticalBar->value(); QVBoxLayout* pVBoxLayout = GetTripWidgetLayout(pScrollArea); if (pVBoxLayout != 0) { focusIndex = pVBoxLayout->indexOf(pFocusWidget); } } // NB: Deleting layouts doesn't delete the widgets that are added to it // because the QWidgets are parented to the QWidget that owns the QLayout. // Because of this, explicitly delete the child widgets first before they're // recreated in tMfdUiHeroicFactory::CreateTripHistoryListLayout // SM: Only delete widgets in the layout if (pLayout != 0) { QLayoutItem* item; while ( ( item = pLayout->takeAt( 0 ) ) != 0 ) { delete item->widget(); delete item; } delete pLayout; } //Build a new layout QLayout* pNewLayout = m_MfdUiHeroicFactory.CreateTripHistoryListLayout(this); setLayout(pNewLayout); // Restore focus of current widget if necessary, restore QScrollArea position. pScrollArea = GetScrollAreaLayout(pNewLayout); if (pScrollArea != 0 && focusIndex != -1) { if (focusAction == KEEP_FOCUS) { QVBoxLayout* pVBoxLayout = GetTripWidgetLayout(pScrollArea); if (pVBoxLayout != 0) { QLayoutItem* pNewLayoutItem = pVBoxLayout->itemAt(focusIndex); if (dynamic_cast<QWidgetItem *>(pNewLayoutItem)) { QWidget* pNewFocusWidget = pNewLayoutItem->widget(); pNewFocusWidget->setFocus(); } } } if (verticalScrollPos != -1) { pScrollArea->verticalScrollBar()->setValue(verticalScrollPos); } } }
void ResultDisplay::scrollLines(int numberOfLines) { QScrollBar* bar = verticalScrollBar(); bar->setValue(bar->value() + numberOfLines); }
void HelpDialog::refreshLog() const { ui->logBrowser->setPlainText(StelLogger::getLog()); QScrollBar *sb = ui->logBrowser->verticalScrollBar(); sb->setValue(sb->maximum()); }
void RPCConsole::scrollToEnd() { QScrollBar *scrollbar = ui->messagesWidget->verticalScrollBar(); scrollbar->setValue(scrollbar->maximum()); }
bool BCI2000Viewer::ChannelDown_Enabled() { QScrollBar* s = ui->verticalScrollBar; return s->isEnabled() && s->sliderPosition() < s->maximum(); }