///Generates renderObjectCollections when required, i.e. ///when re-sized, molecule altered; adjusts the vertical scrollbar, ///and paints all visible renderOjbectCollections void RenderArea::paintEvent(QPaintEvent *) { //First, let's see how big the window is and how many bases we can spanIdRole QFont font("Courier", 14, QFont::Normal); //need fixed width font QPainter painter(viewport()); painter.setFont(font); QFontMetrics fm(font); int charWidth = fm.width("cagtnrlpyt") / 10; //width of each cha int lineHeight = charWidth*3; //fm.height("cagtnrlpyt"); int numberWidth = round(log10(pMol->sequence.length())) * charWidth + charWidth ; int basePerLine = (width()-numberWidth-32)/charWidth; int currentBase = 0; QString number = QString(); QScrollBar* scrollbar = verticalScrollBar(); //we go here and re-virtual-render everything if the window has been re-sized //as well as adjusting the vertical scroll bar if (reSized) { float r = ((float) scrollbar->sliderPosition())/((float) totalHeight); //get relative position of where we are while (!renderObjects.isEmpty()) delete renderObjects.takeFirst(); //clean up previous render Elements totalHeight = 0; //clear cumulative height do { qDebug() << "---------Line----------" << currentBase; RenderObjectContainer* container = pMol->renderSequenceDump(NULL, currentBase,currentBase+basePerLine, charWidth); renderObjects.append(container); currentBase += basePerLine; totalHeight+=container->rect.height(); //measure total height of render } while ((currentBase + basePerLine)<(pMol->sequence.length())); scrollbar->setMinimum(1); //re-set the scrollbar scrollbar->setMaximum(totalHeight-height()+100); //leave a bit of room at the bottom scrollbar->setPageStep(height()); //adjust the page step to the view port's size scrollbar->setSliderPosition(round(r*totalHeight)); //set the slider position correctly from the relative value we had stored scrollbar->setSingleStep(charWidth); reSized = false; //label as reSized! } //This bit paints only the renderObjectContainers above that are visible on this viewport int y = 1; //renderObjects.at(1)->rect.height(); int virtualy = scrollbar->sliderPosition(); for (int i = 0; i < renderObjects.size(); ++i) //ok let's paint what is visible in the view-port { y+= renderObjects.at(i)->rect.height(); if (y>=virtualy) renderObjects.at(i)->Render(&painter, numberWidth, y-virtualy); //only if visible if (y>(virtualy + height())) break; //if over the edge of the view port, stop looping } }
void QConsolePrivate::updateScrollBar (void) { m_scrollBar->setMinimum (0); if (m_bufferSize.height () > m_consoleRect.height ()) m_scrollBar->setMaximum (m_bufferSize.height () - m_consoleRect.height ()); else m_scrollBar->setMaximum (0); m_scrollBar->setSingleStep (1); m_scrollBar->setPageStep (m_consoleRect.height ()); m_scrollBar->setValue (m_consoleRect.top ()); log ("Scrollbar parameters updated: %d/%d/%d/%d\n", m_scrollBar->minimum (), m_scrollBar->maximum (), m_scrollBar->singleStep (), m_scrollBar->pageStep ()); }
void AvatarEditor::RebuildEditView() { if (!avatar_widget_) return; // Activate/deactivate export button based on whether export currently supported QPushButton *button = avatar_widget_->findChild<QPushButton *>("but_export"); if (button) button->setEnabled(rexlogicmodule_->GetAvatarHandler()->AvatarExportSupported()); QWidget* mat_panel = avatar_widget_->findChild<QWidget *>("panel_materials"); QWidget* attachment_panel = avatar_widget_->findChild<QWidget *>("panel_attachments"); if (!mat_panel || !attachment_panel) return; Scene::EntityPtr entity = rexlogicmodule_->GetAvatarHandler()->GetUserAvatar(); if (!entity) return; EC_AvatarAppearance* appearance = entity->GetComponent<EC_AvatarAppearance>().get(); if (!appearance) return; int width = 308-10; int tab_width = 302-10; int itemheight = 20; // Materials ClearPanel(mat_panel); const AvatarMaterialVector& materials = appearance->GetMaterials(); mat_panel->resize(width, itemheight * (materials.size() + 1)); for (uint y = 0; y < materials.size(); ++y) { QPushButton* button = new QPushButton("Change", mat_panel); button->setObjectName(QString::fromStdString(ToString<int>(y))); // Material index button->resize(50, 20); button->move(width - 50, y*itemheight); button->show(); QObject::connect(button, SIGNAL(clicked()), this, SLOT(ChangeTexture())); // If there's a texture name, use it, because it is probably more understandable than material name std::string texname = materials[y].asset_.name_; if (materials[y].textures_.size()) texname = materials[y].textures_[0].name_; QLabel* label = new QLabel(QString::fromStdString(texname), mat_panel); label->resize(200,20); label->move(0, y*itemheight); label->show(); } // Attachments ClearPanel(attachment_panel); const AvatarAttachmentVector& attachments = appearance->GetAttachments(); attachment_panel->resize(width, itemheight * (attachments.size() + 1)); for (uint y = 0; y < attachments.size(); ++y) { QPushButton* button = new QPushButton("Remove", attachment_panel); button->setObjectName(QString::fromStdString(ToString<int>(y))); // Attachment index button->resize(50, 20); button->move(width - 50, y*itemheight); button->show(); QObject::connect(button, SIGNAL(clicked()), this, SLOT(RemoveAttachment())); std::string attachment_name = attachments[y].name_; // Strip away .xml from the attachment name for slightly nicer display std::size_t pos = attachment_name.find(".xml"); if (pos != std::string::npos) attachment_name = attachment_name.substr(0, pos); QLabel* label = new QLabel(QString::fromStdString(attachment_name), attachment_panel); label->resize(200,20); label->move(0, y*itemheight); label->show(); } // Modifiers QTabWidget* tabs = avatar_widget_->findChild<QTabWidget *>("tab_appearance"); if (!tabs) return; for (;;) { QWidget* tab = tabs->widget(0); if (!tab) break; tabs->removeTab(0); delete tab; } const MasterModifierVector& master_modifiers = appearance->GetMasterModifiers(); // If no master modifiers, show the individual morph/bone controls if (!master_modifiers.size()) { QWidget* morph_panel = GetOrCreateTabScrollArea(tabs, "Morphs"); QWidget* bone_panel = GetOrCreateTabScrollArea(tabs, "Bones"); if (!morph_panel || !bone_panel) return; const BoneModifierSetVector& bone_modifiers = appearance->GetBoneModifiers(); const MorphModifierVector& morph_modifiers = appearance->GetMorphModifiers(); morph_panel->resize(tab_width, itemheight * (morph_modifiers.size() + 1)); bone_panel->resize(tab_width, itemheight * (bone_modifiers.size() + 1)); for (uint i = 0; i < bone_modifiers.size(); ++i) { QScrollBar* slider = new QScrollBar(Qt::Horizontal, bone_panel); slider->setObjectName(QString::fromStdString(bone_modifiers[i].name_)); slider->setMinimum(0); slider->setMaximum(100); slider->setPageStep(10); slider->setValue(bone_modifiers[i].value_ * 100.0f); slider->resize(150, 20); slider->move(tab_width - 150, i * itemheight); slider->show(); QObject::connect(slider, SIGNAL(valueChanged(int)), this, SLOT(BoneModifierValueChanged(int))); QLabel* label = new QLabel(QString::fromStdString(bone_modifiers[i].name_), bone_panel); label->resize(100,20); label->move(0, i * itemheight); label->show(); } for (uint i = 0; i < morph_modifiers.size(); ++i) { QScrollBar* slider = new QScrollBar(Qt::Horizontal, morph_panel); slider->setObjectName(QString::fromStdString(morph_modifiers[i].name_)); slider->setMinimum(0); slider->setMaximum(100); slider->setPageStep(10); slider->setValue(morph_modifiers[i].value_ * 100.0f); slider->resize(150, 20); slider->move(tab_width - 150, i * itemheight); slider->show(); QObject::connect(slider, SIGNAL(valueChanged(int)), this, SLOT(MorphModifierValueChanged(int))); QLabel* label = new QLabel(QString::fromStdString(morph_modifiers[i].name_), morph_panel); label->resize(100,20); label->move(0, i * itemheight); label->show(); } }
void QStyleItem::initStyleOption() { QString type = elementType(); if (m_styleoption) m_styleoption->state = 0; switch (m_itemType) { case Button: { if (!m_styleoption) m_styleoption = new QStyleOptionButton(); QStyleOptionButton *opt = qstyleoption_cast<QStyleOptionButton*>(m_styleoption); opt->text = text(); opt->features = (activeControl() == "default") ? QStyleOptionButton::DefaultButton : QStyleOptionButton::None; } break; case ItemRow: { if (!m_styleoption) m_styleoption = new QStyleOptionViewItemV4(); QStyleOptionViewItemV4 *opt = qstyleoption_cast<QStyleOptionViewItemV4*>(m_styleoption); opt->features = 0; if (activeControl() == "alternate") opt->features |= QStyleOptionViewItemV2::Alternate; } break; case Splitter: { if (!m_styleoption) { m_styleoption = new QStyleOption; } } break; case Item: { if (!m_styleoption) { m_styleoption = new QStyleOptionViewItemV4(); } QStyleOptionViewItemV4 *opt = qstyleoption_cast<QStyleOptionViewItemV4*>(m_styleoption); opt->features = QStyleOptionViewItemV4::HasDisplay; opt->text = text(); opt->textElideMode = Qt::ElideRight; QPalette pal = m_styleoption->palette; pal.setBrush(QPalette::Base, Qt::NoBrush); m_styleoption->palette = pal; } break; case Header: { if (!m_styleoption) m_styleoption = new QStyleOptionHeader(); QStyleOptionHeader *opt = qstyleoption_cast<QStyleOptionHeader*>(m_styleoption); opt->text = text(); opt->sortIndicator = activeControl() == "down" ? QStyleOptionHeader::SortDown : activeControl() == "up" ? QStyleOptionHeader::SortUp : QStyleOptionHeader::None; if (activeControl() == QLatin1String("beginning")) opt->position = QStyleOptionHeader::Beginning; else if (activeControl() == QLatin1String("end")) opt->position = QStyleOptionHeader::End; else if (activeControl() == QLatin1String("only")) opt->position = QStyleOptionHeader::OnlyOneSection; else opt->position = QStyleOptionHeader::Middle; } break; case ToolButton :{ if (!m_styleoption) m_styleoption = new QStyleOptionToolButton(); QStyleOptionToolButton *opt = qstyleoption_cast<QStyleOptionToolButton*>(m_styleoption); opt->subControls = QStyle::SC_ToolButton; opt->state |= QStyle::State_AutoRaise; opt->activeSubControls = QStyle::SC_ToolButton; } break; case ToolBar: { if (!m_styleoption) m_styleoption = new QStyleOptionToolBar(); } break; case Tab: { if (!m_styleoption) m_styleoption = new QStyleOptionTabV3(); QStyleOptionTabV3 *opt = qstyleoption_cast<QStyleOptionTabV3*>(m_styleoption); opt->text = text(); opt->shape = info() == "South" ? QTabBar::RoundedSouth : QTabBar::RoundedNorth; if (activeControl() == QLatin1String("beginning")) opt->position = QStyleOptionTabV3::Beginning; else if (activeControl() == QLatin1String("end")) opt->position = QStyleOptionTabV3::End; else if (activeControl() == QLatin1String("only")) opt->position = QStyleOptionTabV3::OnlyOneTab; else opt->position = QStyleOptionTabV3::Middle; } break; case Menu: { if (!m_styleoption) m_styleoption = new QStyleOptionMenuItem(); } break; case Frame: { if (!m_styleoption) m_styleoption = new QStyleOptionFrameV3(); QStyleOptionFrameV3 *opt = qstyleoption_cast<QStyleOptionFrameV3*>(m_styleoption); opt->frameShape = QFrame::StyledPanel; opt->lineWidth = 1; opt->midLineWidth = 1; } break; case TabFrame: { if (!m_styleoption) m_styleoption = new QStyleOptionTabWidgetFrameV2(); QStyleOptionTabWidgetFrameV2 *opt = qstyleoption_cast<QStyleOptionTabWidgetFrameV2*>(m_styleoption); opt->shape = (info() == "South") ? QTabBar::RoundedSouth : QTabBar::RoundedNorth; if (minimum()) opt->selectedTabRect = QRect(value(), 0, minimum(), height()); opt->tabBarSize = QSize(minimum() , height()); // oxygen style needs this hack opt->leftCornerWidgetSize = QSize(value(), 0); } break; case MenuItem: case ComboBoxItem: { if (!m_styleoption) m_styleoption = new QStyleOptionMenuItem(); QStyleOptionMenuItem *opt = qstyleoption_cast<QStyleOptionMenuItem*>(m_styleoption); opt->checked = false; opt->text = text(); opt->palette = widget()->palette(); } break; case CheckBox: case RadioButton: { if (!m_styleoption) m_styleoption = new QStyleOptionButton(); QStyleOptionButton *opt = qstyleoption_cast<QStyleOptionButton*>(m_styleoption); if (!on()) opt->state |= QStyle::State_Off; opt->text = text(); } break; case Edit: { if (!m_styleoption) m_styleoption = new QStyleOptionFrameV3(); QStyleOptionFrameV3 *opt = qstyleoption_cast<QStyleOptionFrameV3*>(m_styleoption); opt->lineWidth = 1; // this must be non-zero } break; case ComboBox :{ if (!m_styleoption) m_styleoption = new QStyleOptionComboBox(); QStyleOptionComboBox *opt = qstyleoption_cast<QStyleOptionComboBox*>(m_styleoption); opt->currentText = text(); } break; case SpinBox: { if (!m_styleoption) m_styleoption = new QStyleOptionSpinBox(); QStyleOptionSpinBox *opt = qstyleoption_cast<QStyleOptionSpinBox*>(m_styleoption); opt->frame = true; if (value() & 0x1) opt->activeSubControls = QStyle::SC_SpinBoxUp; else if (value() & (1<<1)) opt->activeSubControls = QStyle::SC_SpinBoxDown; opt->subControls = QStyle::SC_All; opt->stepEnabled = 0; if (value() & (1<<2)) opt->stepEnabled |= QAbstractSpinBox::StepUpEnabled; if (value() & (1<<3)) opt->stepEnabled |= QAbstractSpinBox::StepDownEnabled; } break; case Slider: case Dial: { if (!m_styleoption) m_styleoption = new QStyleOptionSlider(); QStyleOptionSlider *opt = qstyleoption_cast<QStyleOptionSlider*>(m_styleoption); opt->minimum = minimum(); opt->maximum = maximum(); // ### fixme - workaround for KDE inverted dial opt->sliderPosition = value(); opt->singleStep = step(); if (opt->singleStep) { qreal numOfSteps = (opt->maximum - opt->minimum) / opt->singleStep; // at least 5 pixels between tick marks if (numOfSteps && (width() / numOfSteps < 5)) opt->tickInterval = qRound((5*numOfSteps / width()) + 0.5)*step(); else opt->tickInterval = opt->singleStep; } else // default Qt-components implementation opt->tickInterval = opt->maximum != opt->minimum ? 1200 / (opt->maximum - opt->minimum) : 0; if (style() == QLatin1String("oxygen") && type == QLatin1String("dial")) opt->sliderValue = maximum() - value(); else opt->sliderValue = value(); opt->subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle; opt->tickPosition = (activeControl() == "below") ? QSlider::TicksBelow : (activeControl() == "above" ? QSlider::TicksAbove: QSlider::NoTicks); if (opt->tickPosition != QSlider::NoTicks) opt->subControls |= QStyle::SC_SliderTickmarks; opt->activeSubControls = QStyle::SC_None; } break; case ProgressBar: { if (QProgressBar *bar= qobject_cast<QProgressBar*>(widget())){ bar->setMaximum(maximum()); bar->setMinimum(minimum()); if (maximum() != minimum()) bar->setValue(1); } if (!m_styleoption) m_styleoption = new QStyleOptionProgressBarV2(); QStyleOptionProgressBarV2 *opt = qstyleoption_cast<QStyleOptionProgressBarV2*>(m_styleoption); opt->orientation = horizontal() ? Qt::Horizontal : Qt::Vertical; opt->minimum = minimum(); opt->maximum = maximum(); opt->progress = value(); } break; case GroupBox: { if (!m_styleoption) m_styleoption = new QStyleOptionGroupBox(); QStyleOptionGroupBox *opt = qstyleoption_cast<QStyleOptionGroupBox*>(m_styleoption); opt->text = text(); opt->lineWidth = 1; opt->subControls = QStyle::SC_GroupBoxLabel; if (sunken()) // Qt draws an ugly line here so I ignore it opt->subControls |= QStyle::SC_GroupBoxFrame; else opt->features |= QStyleOptionFrameV2::Flat; if (activeControl() == "checkbox") opt->subControls |= QStyle::SC_GroupBoxCheckBox; if (QGroupBox *group= qobject_cast<QGroupBox*>(widget())) { group->setTitle(text()); group->setCheckable(opt->subControls & QStyle::SC_GroupBoxCheckBox); } } break; case ScrollBar: { if (!m_styleoption) m_styleoption = new QStyleOptionSlider(); QStyleOptionSlider *opt = qstyleoption_cast<QStyleOptionSlider*>(m_styleoption); opt->minimum = minimum(); opt->maximum = maximum(); opt->pageStep = horizontal() ? width() : height(); opt->orientation = horizontal() ? Qt::Horizontal : Qt::Vertical; opt->sliderPosition = value(); opt->sliderValue = value(); opt->activeSubControls = (activeControl() == QLatin1String("up")) ? QStyle::SC_ScrollBarSubLine : (activeControl() == QLatin1String("down")) ? QStyle::SC_ScrollBarAddLine: QStyle::SC_ScrollBarSlider; opt->sliderValue = value(); opt->subControls = QStyle::SC_All; QScrollBar *bar = qobject_cast<QScrollBar *>(widget()); bar->setMaximum(maximum()); bar->setMinimum(minimum()); bar->setValue(value()); } break; default: break; } if (!m_styleoption) m_styleoption = new QStyleOption(); m_styleoption->rect = QRect(m_paintMargins, m_paintMargins, width() - 2* m_paintMargins, height() - 2 * m_paintMargins); if (isEnabled()) m_styleoption->state |= QStyle::State_Enabled; if (m_active) m_styleoption->state |= QStyle::State_Active; if (m_sunken) m_styleoption->state |= QStyle::State_Sunken; if (m_raised) m_styleoption->state |= QStyle::State_Raised; if (m_selected) m_styleoption->state |= QStyle::State_Selected; if (m_focus) m_styleoption->state |= QStyle::State_HasFocus; if (m_on) m_styleoption->state |= QStyle::State_On; if (m_hover) m_styleoption->state |= QStyle::State_MouseOver; if (m_horizontal) m_styleoption->state |= QStyle::State_Horizontal; if (widget()) { widget()->ensurePolished(); if (type == QLatin1String("tab") && style() != QLatin1String("mac")) { // Some styles actually check the beginning and end position // using widget geometry, so we have to trick it widget()->setGeometry(0, 0, width(), height()); if (activeControl() != "beginning") m_styleoption->rect.translate(1, 0); // Don't position at start of widget if (activeControl() != "end") widget()->resize(200, height()); } #ifdef Q_WS_WIN else widget()->resize(width(), height()); #endif widget()->setEnabled(isEnabled()); m_styleoption->fontMetrics = widget()->fontMetrics(); if (!m_styleoption->palette.resolve()) m_styleoption->palette = widget()->palette(); if (m_hint.contains("mac.mini")) { widget()->setAttribute(Qt::WA_MacMiniSize); } else if (m_hint.contains("mac.small")) { widget()->setAttribute(Qt::WA_MacSmallSize); } } }
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); } } }