String PopupContainer::getSelectedItemToolTip() { // We cannot use m_popupClient->selectedIndex() to choose tooltip message, // because the selectedIndex() might return final selected index, not // hovering selection. return listBox()->m_popupClient->itemToolTip(listBox()->m_selectedIndex); }
void ProcessListBoxItem::paint(QPainter *p) { QColor dim, warn, err, back; if (listBox()) { const QColorGroup& group = listBox()->palette().active(); if (isSelected()) { back = group.button(); warn = group.buttonText(); } else { back = group.base(); warn = group.text(); } err = group.linkVisited(); dim = blend(warn, back); } else { warn = Qt::black; dim = Qt::darkBlue; err = Qt::darkRed; if (isSelected()) back = Qt::lightGray; else back = Qt::white; } p->fillRect(p->window(), QBrush(back)); p->setPen((t==Error)? err : (t==Diagnostic)? warn : dim); QListBoxText::paint(p); }
void ConfigChecker::finished(bool ok) { setCursor(KCursor::arrowCursor()); enableButton(Cancel, false); if (ok) { label()->setText(i18n("Finished testing your system...")); QStringList tools = m_tester->testedTools(); QStringList critical, failure; for ( uint i = 0; i < tools.count(); ++i ) { int status = m_tester->statusForTool(tools[i]); if ( status == ConfigTest::Critical ) critical.append(tools[i]); else if ( status == ConfigTest::Failure ) failure.append(tools[i]); new ResultItem(listBox(), tools[i], status, m_tester->resultForTool(tools[i])); } listBox()->sort(); QString cap = i18n("Test Results"); if ( critical.count() > 0 ) KMessageBox::error(this, i18n("<qt>The following tools did not pass all <b>critical</b> tests:<br>%1<br>Your system is not ready to use. Please consult the results to find out what to fix.</qt>").arg(critical.join(", ")), cap); else if ( failure.count() > 0 ) KMessageBox::information(this, i18n("The following tools did not pass all tests:\n %1\nYou will still be able to use Kile; however, not all features are guaranteed to work.").arg(failure.join(", ")), cap); else KMessageBox::information(this, i18n("No problems detected, your system is ready to use."), cap); } else label()->setText(i18n("Tests finished abruptly...")); enableButton(Ok, true); enableButton(User1, true); }
void PopupContainer::showInRect(const FloatQuad& controlPosition, const IntSize& controlSize, FrameView* v, int index) { // The controlSize is the size of the select box. It's usually larger than // we need. Subtract border size so that usually the container will be // displayed exactly the same width as the select box. listBox()->setBaseWidth(max(controlSize.width() - borderSize * 2, 0)); listBox()->updateFromElement(); // We set the selected item in updateFromElement(), and disregard the // index passed into this function (same as Webkit's PopupMenuWin.cpp) // FIXME: make sure this is correct, and add an assertion. // ASSERT(popupWindow(popup)->listBox()->selectedIndex() == index); // Save and convert the controlPosition to main window coords. Each point is converted separately // to window coordinates because the control could be in a transformed webview and then each point // would be transformed by a different delta. m_controlPosition.setP1(v->contentsToWindow(IntPoint(controlPosition.p1().x(), controlPosition.p1().y()))); m_controlPosition.setP2(v->contentsToWindow(IntPoint(controlPosition.p2().x(), controlPosition.p2().y()))); m_controlPosition.setP3(v->contentsToWindow(IntPoint(controlPosition.p3().x(), controlPosition.p3().y()))); m_controlPosition.setP4(v->contentsToWindow(IntPoint(controlPosition.p4().x(), controlPosition.p4().y()))); m_controlSize = controlSize; // Position at (0, 0) since the frameRect().location() is relative to the // parent WebWidget. setFrameRect(IntRect(IntPoint(), controlSize)); showPopup(v); }
void PopupContainer::showInRect(const IntRect& r, FrameView* v, int index) { // The rect is the size of the select box. It's usually larger than we need. // subtract border size so that usually the container will be displayed // exactly the same width as the select box. listBox()->setBaseWidth(max(r.width() - kBorderSize * 2, 0)); listBox()->updateFromElement(); // We set the selected item in updateFromElement(), and disregard the // index passed into this function (same as Webkit's PopupMenuWin.cpp) // FIXME: make sure this is correct, and add an assertion. // ASSERT(popupWindow(popup)->listBox()->selectedIndex() == index); // Convert point to main window coords. IntPoint location = v->contentsToWindow(r.location()); // Move it below the select widget. location.move(0, r.height()); m_originalFrameRect = IntRect(location, r.size()); // Position at (0, 0) since the frameRect().location() is relative to the parent WebWidget. setFrameRect(IntRect(IntPoint(), r.size())); showPopup(v); }
int LanguageComboBox::insertLanguage(const QString &language) { static QString entryDesktop = QString::fromLatin1("/entry.desktop"); KSimpleConfig entry(locate("locale", language + entryDesktop)); entry.setGroup("KCM Locale"); QString name = entry.readEntry("Name"); QString output = QString::fromLatin1("%1 (%2)").arg(name).arg(language); insertItem(QPixmap(locate("locale", language + flagPng)), output); return listBox()->index(listBox()->findItem(output)); }
KTimezoneCombo::KTimezoneCombo(QWidget *parent, const char *name, KstTimezones *db) : KComboBox(parent, name), d(new Private) { bool userDb = db != 0L; if (!userDb) { db = new KstTimezones; } if (listBox()) { listBox()->setVScrollBarMode(QScrollView::AlwaysOn); listBox()->setColumnMode(QListBox::FixedNumber); listBox()->setRowMode(QListBox::Variable); } insertItem("UTC"); const KstTimezones::ZoneMap zones = db->allZones(); d->_offsets.resize(zones.count()+1); d->_offsets[0] = 0; d->_names += "UTC"; int i = 0; for (KstTimezones::ZoneMap::ConstIterator it = zones.begin(); it != zones.end(); ++it) { int offset = (*it)->offset(); d->_offsets[++i] = offset; int hours = offset / 3600; int minutes = 100 * offset / 3600 % 100; bool negative = false; if (hours < 0) { hours *= -1; negative = true; } if (minutes < 0) { minutes *= -1; } QString offnum; if (hours < 10) { offnum += '0'; } offnum += QString::number(hours); if (minutes < 10) { offnum += '0'; } offnum += QString::number(minutes); if ((*it)->name() != "UTC") { insertItem(i18n("%3 (UTC%1%2)").arg(negative ? '-' : '+').arg(offnum).arg((*it)->name())); d->_names += (*it)->name(); } } if (!userDb) { delete db; } }
void ListBoxDevice::paint( QPainter * p ) { if ((ejectable_ || removable_) && mounted_) { p->save(); ListBoxLink::paint(p); p->setBrush(isSelected()?listBox()->colorGroup().highlightedText():listBox()->colorGroup().text()); p->drawPixmap(listBox()->width()-22, 11, ejectable_?eject:locked); p->restore(); } else ListBoxLink::paint(p); }
void ChoiceItem::paint( QPainter* painter ) { int itemHeight = height( listBox() ); QFontMetrics fm = painter->fontMetrics(); int yPos = ( ( itemHeight - fm.height() ) / 2 ) + fm.ascent(); painter->drawText( 3, yPos, item ); //int xPos = fm.width( item ); int xPos = QMAX(fm.width(item), minNameWidth); if( !isSelected() ) painter->setPen( listBox()->palette().disabled().text().dark() ); painter->drawText( 10 + xPos, yPos, desc ); }
void KComboBox::makeCompletion( const QString& text ) { if( d->klineEdit ) d->klineEdit->makeCompletion( text ); else // read-only combo completion { if( text.isNull() || !listBox() ) return; const int index = listBox()->index( listBox()->findItem( text ) ); if( index >= 0 ) setCurrentItem( index ); } }
/*! Returns a (possibly empty) list of indexes of the items selected in the list box. \sa setSelected() clearSelection() */ QVector<int> QAccessibleListBox::selection() const { QVector<int> array; uint size = 0; const uint c = listBox()->count(); array.resize(c); for (uint i = 0; i < c; ++i) { if (listBox()->isSelected(i)) { ++size; array[(int)size-1] = i+1; } } array.resize(size); return array; }
// Returns width of this particular list item's name. int ChoiceItem::nameWidth() const { if(item.isEmpty()) return 0; QFontMetrics fm = listBox()->fontMetrics(); return fm.width( item ); }
/*! \reimp */ QString QAccessibleListBox::text(Text t, int child) const { if (!child || t != Name) return Q3AccessibleScrollView::text(t, child); Q3ListBoxItem *item = listBox()->item(child - 1); if (item) return item->text(); return QString(); }
void MyListBoxItem::paint( QPainter *painter ) { // evil trick: find out whether we are painted onto our listbox bool in_list_box = listBox() && listBox()->viewport() == painter->device(); QRect r ( 0, 0, width( listBox() ), height( listBox() ) ); if ( in_list_box && selected() ) painter->eraseRect( r ); painter->fillRect( 5, 5, width( listBox() ) - 10, height( listBox() ) - 10, Qt::red ); if ( in_list_box && current() ) listBox()->style().drawFocusRect( painter, r, listBox()->colorGroup(), &painter->backgroundColor(), TRUE ); }
void paint( QPainter *painter ) { if ( lastState != isSelected() ) { delete parag; parag = 0; } lastState = isSelected(); if ( !parag ) setupParagraph(); parag->paint( *painter, listBox()->palette() ); }
void ListBoxIDItem::paint(QPainter* p) { QRect rect; rect.setLeft(0); rect.setRight(listBox()->width()); rect.setTop(0); rect.setBottom(QApplication::fontMetrics().height()); p->drawText(rect, Qt::AlignLeft, text()); }
IntRect PopupContainer::refresh(const IntRect& targetControlRect) { listBox()->setBaseWidth(max(m_originalFrameRect.width() - kBorderSize * 2, 0)); listBox()->updateFromElement(); IntPoint locationInWindow = m_frameView->contentsToWindow(targetControlRect.location()); // Move it below the select widget. locationInWindow.move(0, targetControlRect.height()); IntRect widgetRectInScreen = layoutAndCalculateWidgetRect(targetControlRect.height(), locationInWindow); // Reset the size (which can be set to the PopupListBox size in layoutAndGetRTLOffset(), exceeding the available widget rectangle.) if (size() != widgetRectInScreen.size()) resize(widgetRectInScreen.size()); invalidate(); return widgetRectInScreen; }
void paint(QPainter* p) { int w = width(listBox()); int h = height(listBox()); p->drawText(110, 0, w - 110, h, Qt::AlignVCenter, text()); p->setPen(Qt::black); p->setBrush(Qt::NoBrush); p->drawRect(4, 2, 102, h - 4); QRgb* buffer = new QRgb[100]; _gradient.fillGradient(buffer, 100); for (int x = 0; x < 100; x++) { p->setPen(buffer[x]); p->drawLine(5 + x, 3, 5 + x, h - 4); } delete[] buffer; }
/*! \reimp */ QAccessible::State QAccessibleListBox::state(int child) const { State state = Q3AccessibleScrollView::state(child); Q3ListBoxItem *item; if (!child || !(item = listBox()->item(child - 1))) return state; if (item->isSelectable()) { if (listBox()->selectionMode() == Q3ListBox::Multi) state |= MultiSelectable; else if (listBox()->selectionMode() == Q3ListBox::Extended) state |= ExtSelectable; else if (listBox()->selectionMode() == Q3ListBox::Single) state |= Selectable; if (item->isSelected()) state |= Selected; } if (listBox()->focusPolicy() != Qt::NoFocus) { state |= Focusable; if (item->isCurrent()) state |= Focused; } if (!listBox()->itemVisible(item)) state |= Invisible; return state; }
void KColorCombo2::popup() { if (!m_colorArray) setRainbowPreset(); // Compute where to show the popup: QRect desk = KGlobalSettings::desktopGeometry(this); QPoint popupPoint = mapToGlobal(QPoint(0, 0)); int popupHeight = m_popup->sizeHint().height(); if (popupPoint.y() + height() + popupHeight > desk.bottom()) popupPoint.setY(popupPoint.y() - popupHeight); else popupPoint.setY(popupPoint.y() + height()); int popupWidth = m_popup->sizeHint().width(); if (popupPoint.x() + popupWidth > desk.right()) popupPoint.setX(desk.right() - popupWidth); if (popupPoint.x() < desk.left()) popupPoint.setX(desk.left()); if (popupPoint.y() < desk.top()) popupPoint.setY(desk.top()); // Configure the popup: m_popup->move(popupPoint); //m_popup->setColor(m_color); m_popup->doSelection(); m_popup->relayout(); // FIXME: In aboutToShow() ? #if 0 //#ifndef QT_NO_EFFECTS if (QApplication::isEffectEnabled(UI_AnimateCombo)) { if (m_popup->y() < mapToGlobal(QPoint(0,0)).y()) qScrollEffect(m_popup, QEffects::UpScroll); else qScrollEffect(m_popup); } else #endif m_popup->show(); // The combo box is now shown pressed. Make it show not pressed again // by causing its (invisible) list box to emit a 'selected' signal. // Simulate an Enter to unpress it: Q3ListBox *lb = listBox(); if (lb) { lb->setCurrentItem(0); QKeyEvent* keyEvent = new QKeyEvent(QEvent::KeyPress, Qt::Key_Enter, 0, 0); QApplication::postEvent(lb, keyEvent); } }
void PopupContainer::refresh(const IntRect& targetControlRect) { IntPoint location = m_frameView->contentsToWindow(targetControlRect.location()); // Move it below the select widget. location.move(0, targetControlRect.height()); listBox()->setBaseWidth(max(m_originalFrameRect.width() - kBorderSize * 2, 0)); listBox()->updateFromElement(); // Store the original size to check if we need to request the location. IntSize originalSize = size(); IntRect widgetRect = layoutAndCalculateWidgetRect(targetControlRect.height(), location); if (originalSize != widgetRect.size()) { ChromeClientChromium* chromeClient = chromeClientChromium(); if (chromeClient) { IntPoint widgetLocation = chromeClient->screenToRootView(widgetRect.location()); widgetRect.setLocation(widgetLocation); setFrameRect(widgetRect); } } invalidate(); }
void paint(QPainter* p) { int w = listBox()->maxItemWidth(); if (w < listBox()->width()) w = listBox()->width(); int h = height(listBox()); QRect rcItem(0, 0, w, h); p->setBackgroundColor(listBox()->colorGroup().background()); p->eraseRect(rcItem); qDrawShadeLine(p, 4, h / 2, w - 8, h / 2, listBox()->colorGroup(), false, 1, 0); p->setBackgroundMode(Qt::OpaqueMode); p->setPen(listBox()->colorGroup().buttonText()); p->drawText(4, 0, 102, h, Qt::AlignCenter | Qt::AlignVCenter, " " + text() + " "); }
void PopupContainer::showPopup(FrameView* view) { m_frameView = view; listBox()->m_focusedElement = m_frameView->frame().document()->focusedElement(); IntSize transformOffset(m_controlPosition.p4().x() - m_controlPosition.p1().x(), m_controlPosition.p4().y() - m_controlPosition.p1().y() - m_controlSize.height()); popupOpened(layoutAndCalculateWidgetRect(m_controlSize.height(), transformOffset, roundedIntPoint(m_controlPosition.p4()))); m_popupOpen = true; if (!m_listBox->parent()) addChild(m_listBox.get()); // Enable scrollbars after the listbox is inserted into the hierarchy, // so it has a proper WidgetClient. m_listBox->setVerticalScrollbarMode(ScrollbarAuto); m_listBox->scrollToRevealSelection(); invalidate(); }
void PopupContainer::showPopup(FrameView* view) { m_frameView = view; listBox()->m_focusedNode = m_frameView->frame()->document()->focusedNode(); if (ChromeClient* client = chromeClient()) { IntRect popupRect = m_originalFrameRect; client->popupOpened(this, layoutAndCalculateWidgetRect(popupRect.height(), popupRect.location()), false); m_popupOpen = true; } if (!m_listBox->parent()) addChild(m_listBox.get()); // Enable scrollbars after the listbox is inserted into the hierarchy, // so it has a proper WidgetClient. m_listBox->setVerticalScrollbarMode(ScrollbarAuto); m_listBox->scrollToRevealSelection(); invalidate(); }
QSize KURLBarItem::sizeHint() const { int wmin = 0; int hmin = 0; const KURLBarListBox *lb = static_cast< const KURLBarListBox * >(listBox()); if(m_parent->iconSize() < KIcon::SizeMedium) { wmin = QListBoxPixmap::width(lb) + KDialog::spacingHint() * 2; hmin = QListBoxPixmap::height(lb) + KDialog::spacingHint() * 2; } else { wmin = QMAX(lb->fontMetrics().width(text()), pixmap()->width()) + KDialog::spacingHint() * 2; hmin = lb->fontMetrics().lineSpacing() + pixmap()->height() + KDialog::spacingHint() * 2; } if(lb->isVertical()) wmin = QMIN(wmin, lb->viewport()->sizeHint().width()); else hmin = QMIN(hmin, lb->viewport()->sizeHint().height()); return QSize(wmin, hmin); }
/*! Selects the item with index \a child if \a on is true; otherwise unselects it. If \a extend is true and the selection mode is not \c Single and there is an existing selection, the selection is extended to include all the items from the existing selection up to and including the item with index \a child. Returns true if a selection was made or extended; otherwise returns false. \sa selection() clearSelection() */ bool QAccessibleListBox::setSelected(int child, bool on, bool extend) { if (!child || (extend && listBox()->selectionMode() != Q3ListBox::Extended && listBox()->selectionMode() != Q3ListBox::Multi)) return false; Q3ListBoxItem *item = listBox()->item(child -1); if (!item) return false; if (!extend) { listBox()->setSelected(item, on); } else { int current = listBox()->currentItem(); bool down = child > current; for (int i = current; i != child;) { down ? i++ : i--; listBox()->setSelected(i, on); } } return true; }
void TKComboBox::paintEvent(QPaintEvent*) { QRect r; if (editable()){ #ifdef __GNUC__ #warning "Left out for now, lacking a style expert (Werner)" #endif //r = QRect( style().comboButtonRect( 0, 0, width(), height() ) ); r = QRect(4, 2, width()-height()-2, height()-4); } else { r = QRect(4, 2, width()-height()-2, height()-4); } int by = 2; int bx = r.x() + r.width(); int bw = width() - bx - 2; int bh = height()-4; QPainter p( this ); const QColorGroup& g = colorGroup(); QRect fr(2,2,width()-4,height()-4); if ( hasFocus()) { p.fillRect( fr, g.brush( QColorGroup::Highlight ) ); } else { p.fillRect( fr, g.brush( QColorGroup::Base ) ); } QRect r1(1,1,width()-1,height()-1); qDrawShadePanel( &p, r1, g, true, 1 ); static const char* arrow_down[] = { "7 7 2 1", "X c Gray0", " c None", "XXXXXXX", "XXXXXXX", " ", "XXXXXXX", " XXXXX ", " XXX ", " X "}; QPixmap pixmap(arrow_down); style().drawControl( QStyle::CE_PushButton, &p, this, QRect( bx, by, bw, bh ), colorGroup() ); style().drawItem( &p, QRect( bx, by, bw, bh), AlignCenter, colorGroup(), isEnabled(), &pixmap, QString::null ); if ( hasFocus()) { style().drawPrimitive( QStyle::PE_FocusRect, &p, fr, g ); } if (!editable()) { p.setClipRect(r); p.setPen( g.text() ); p.setBackgroundColor( g.background() ); if ( listBox()->item(currentItem()) ) { QListBoxItem * item = listBox()->item(currentItem()); const QPixmap *pix = item->pixmap(); QString text = item->text(); int x = r.x(); if ( pix ) { p.drawPixmap( x, r.y() + ( r.height() - pix->height() ) / 2 +1, *pix ); x += pix->width()+3; } if (!text.isEmpty()) p.drawText( x, r.y(), r.width()-x, r.height(), AlignLeft|AlignVCenter|SingleLine, text ); } } p.end(); }
void PopupContainer::hidePopup() { listBox()->hidePopup(); }
int main(int argc, char *argv[]) { Q_UNUSED(argc) Q_UNUSED(argv) ////////////////////////////////////////////////////////////////// /// Init GraphicSystem singleton GraphicSystem::initialize("GraphicSystemTest", "data/fonts/DejaVuSans.ttf"); ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// /// Get pointers of GraphicSystem sf::RenderWindow *window; window = GraphicSystem::instance()->getWindow(); tgui::Gui *gui; gui = GraphicSystem::instance()->getGUI(); ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// /// Create widgets tgui::Picture::Ptr picture((*gui)); picture->load("data/others/Linux.jpg"); tgui::Button::Ptr button((*gui)); button->load(THEME_CONFIG_FILE); button->setPosition(40, 25); button->setText("Quit"); button->setCallbackId(1); button->bindCallback(tgui::Button::LeftMouseClicked); button->setSize(300, 40); tgui::ChatBox::Ptr chatbox((*gui)); chatbox->load(THEME_CONFIG_FILE); chatbox->setSize(200, 100); chatbox->setTextSize(20); chatbox->setPosition(400, 25); chatbox->addLine("Line 1", sf::Color::Red); chatbox->addLine("Line 2", sf::Color::Blue); chatbox->addLine("Line 3", sf::Color::Green); chatbox->addLine("Line 4", sf::Color::Yellow); chatbox->addLine("Line 5", sf::Color::Cyan); chatbox->addLine("Line 6", sf::Color::Magenta); tgui::Checkbox::Ptr checkbox((*gui)); checkbox->load(THEME_CONFIG_FILE); checkbox->setPosition(40, 80); checkbox->setText("Checkbox"); checkbox->setSize(32, 32); tgui::ChildWindow::Ptr child((*gui)); child->load(THEME_CONFIG_FILE); child->setSize(200, 100); child->setBackgroundColor(sf::Color(80, 80, 80)); child->setPosition(400, 460); child->setTitle("Child window"); child->setIcon("data/others/icon.jpg"); tgui::ComboBox::Ptr comboBox((*gui)); comboBox->load(THEME_CONFIG_FILE); comboBox->setSize(120, 21); comboBox->setPosition(210, 440); comboBox->addItem("Item 1"); comboBox->addItem("Item 2"); comboBox->addItem("Item 3"); comboBox->setSelectedItem("Item 2"); tgui::EditBox::Ptr editBox((*gui)); editBox->load(THEME_CONFIG_FILE); editBox->setPosition(40, 200); editBox->setSize(300, 30); tgui::Label::Ptr label((*gui)); label->load(THEME_CONFIG_FILE); label->setText("Label"); label->setPosition(40, 160); label->setTextColor(sf::Color(200, 200, 200)); label->setTextSize(24); tgui::ListBox::Ptr listBox((*gui)); listBox->load(THEME_CONFIG_FILE); listBox->setSize(150, 120); listBox->setItemHeight(20); listBox->setPosition(40, 440); listBox->addItem("Item 1"); listBox->addItem("Item 2"); listBox->addItem("Item 3"); tgui::LoadingBar::Ptr loadingbar((*gui)); loadingbar->load(THEME_CONFIG_FILE); loadingbar->setPosition(40, 330); loadingbar->setSize(300, 30); loadingbar->setValue(35); tgui::MenuBar::Ptr menu((*gui)); menu->load(THEME_CONFIG_FILE); menu->setSize(window->getSize().x, 20); menu->addMenu("File"); menu->addMenuItem("File", "Load"); menu->addMenuItem("File", "Save"); menu->addMenuItem("File", "Exit"); menu->bindCallback(tgui::MenuBar::MenuItemClicked); menu->setCallbackId(2); sf::Texture texture; texture.loadFromFile("data/others/ThinkLinux.jpg"); tgui::Panel::Ptr panel((*gui)); panel->setSize(200, 140); panel->setPosition(400, 150); panel->setBackgroundTexture(&texture); tgui::RadioButton::Ptr radioButton((*gui)); radioButton->load(THEME_CONFIG_FILE); radioButton->setPosition(40, 120); radioButton->setText("Radio Button"); radioButton->setSize(32, 32); tgui::Slider::Ptr slider((*gui)); slider->load(THEME_CONFIG_FILE); slider->setVerticalScroll(false); slider->setPosition(40, 250); slider->setSize(300, 25); slider->setValue(2); tgui::Scrollbar::Ptr scrollbar((*gui)); scrollbar->load(THEME_CONFIG_FILE); scrollbar->setVerticalScroll(false); scrollbar->setPosition(40, 290); scrollbar->setSize(300, 25); scrollbar->setMaximum(5); scrollbar->setLowValue(3); tgui::Slider2d::Ptr slider2d((*gui)); slider2d->load("data/widgets/Slider2d/Black.conf"); slider2d->setPosition(400, 300); slider2d->setSize(200, 150); tgui::SpinButton::Ptr spinButton((*gui)); spinButton->load(THEME_CONFIG_FILE); spinButton->setPosition(40, 410); spinButton->setVerticalScroll(false); spinButton->setSize(40, 20); tgui::SpriteSheet::Ptr spritesheet((*gui)); spritesheet->load("data/others/ThinkLinux.jpg"); spritesheet->setCells(4, 4); spritesheet->setVisibleCell(2, 3); spritesheet->setSize(160, 120); spritesheet->setPosition(620, 25); tgui::Tab::Ptr tab((*gui)); tab->load(THEME_CONFIG_FILE); tab->setPosition(40, 370); tab->add("Item 1"); tab->add("Item 2"); tab->add("Item 3"); tgui::TextBox::Ptr textBox((*gui)); textBox->load(THEME_CONFIG_FILE); textBox->setPosition(210, 470); textBox->setSize(180, 120); textBox->setTextSize(16); comboBox->moveToFront(); ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// /// Start main loop while(window->isOpen()) { GraphicSystem::instance()->injectPreUpdate(0); sf::Event event; while(GraphicSystem::instance()->pollWindowEvent(event)) { if(event.type == sf::Event::Closed) window->close(); GraphicSystem::instance()->handleGUIEvent(event); } tgui::Callback callback; while(GraphicSystem::instance()->pollGUICallback(callback)) { if(callback.id == 1) window->close(); else if(callback.id == 2) { if(callback.text == "Exit") window->close(); } } GraphicSystem::instance()->injectPostUpdate(0); } ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// /// Destroy GraphicSystem GraphicSystem::shutdown(); ////////////////////////////////////////////////////////////////// return 0; }
IntRect PopupContainer::layoutAndCalculateWidgetRect(int targetControlHeight, const IntPoint& popupInitialCoordinate) { // Reset the max width and height to their default values, they will be recomputed below // if necessary. m_listBox->setMaxHeight(kMaxHeight); m_listBox->setMaxWidth(std::numeric_limits<int>::max()); // Lay everything out to figure out our preferred size, then tell the view's // WidgetClient about it. It should assign us a client. int rtlOffset = layoutAndGetRTLOffset(); bool isRTL = this->isRTL(); int rightOffset = isRTL ? rtlOffset : 0; // Assume m_listBox size is already calculated. IntSize targetSize(m_listBox->width() + kBorderSize * 2, m_listBox->height() + kBorderSize * 2); IntRect widgetRect; ChromeClientChromium* chromeClient = chromeClientChromium(); if (chromeClient) { // If the popup would extend past the bottom of the screen, open upwards // instead. FloatRect screen = screenAvailableRect(m_frameView.get()); // Use popupInitialCoordinate.x() + rightOffset because RTL position // needs to be considered. widgetRect = chromeClient->rootViewToScreen(IntRect(popupInitialCoordinate.x() + rightOffset, popupInitialCoordinate.y(), targetSize.width(), targetSize.height())); // If we have multiple screens and the browser rect is in one screen, we have // to clip the window width to the screen width. // When clipping, we also need to set a maximum width for the list box. FloatRect windowRect = chromeClient->windowRect(); if (windowRect.x() >= screen.x() && windowRect.maxX() <= screen.maxX() && (widgetRect.x() < screen.x() || widgetRect.maxX() > screen.maxX())) { // First, inverse the popup alignment if it does not fit the screen - this might fix things (or make them better). IntRect inverseWidgetRect = chromeClient->rootViewToScreen(IntRect(popupInitialCoordinate.x() + (isRTL ? 0 : rtlOffset), popupInitialCoordinate.y(), targetSize.width(), targetSize.height())); IntRect enclosingScreen = enclosingIntRect(screen); unsigned originalCutoff = max(enclosingScreen.x() - widgetRect.x(), 0) + max(widgetRect.maxX() - enclosingScreen.maxX(), 0); unsigned inverseCutoff = max(enclosingScreen.x() - inverseWidgetRect.x(), 0) + max(inverseWidgetRect.maxX() - enclosingScreen.maxX(), 0); // Accept the inverse popup alignment if the trimmed content gets shorter than that in the original alignment case. if (inverseCutoff < originalCutoff) widgetRect = inverseWidgetRect; if (widgetRect.x() < screen.x()) { unsigned widgetRight = widgetRect.maxX(); widgetRect.setWidth(widgetRect.maxX() - screen.x()); widgetRect.setX(widgetRight - widgetRect.width()); listBox()->setMaxWidthAndLayout(max(widgetRect.width() - kBorderSize * 2, 0)); } else if (widgetRect.maxX() > screen.maxX()) { widgetRect.setWidth(screen.maxX() - widgetRect.x()); listBox()->setMaxWidthAndLayout(max(widgetRect.width() - kBorderSize * 2, 0)); } } // Calculate Y axis size. if (widgetRect.maxY() > static_cast<int>(screen.maxY())) { if (widgetRect.y() - widgetRect.height() - targetControlHeight > 0) { // There is enough room to open upwards. widgetRect.move(0, -(widgetRect.height() + targetControlHeight)); } else { // Figure whether upwards or downwards has more room and set the // maximum number of items. int spaceAbove = widgetRect.y() - targetControlHeight; int spaceBelow = screen.maxY() - widgetRect.y(); if (spaceAbove > spaceBelow) m_listBox->setMaxHeight(spaceAbove); else m_listBox->setMaxHeight(spaceBelow); layoutAndGetRTLOffset(); // Our height has changed, so recompute only Y axis of widgetRect. // We don't have to recompute X axis, so we only replace Y axis // in widgetRect. IntRect frameInScreen = chromeClient->rootViewToScreen(frameRect()); widgetRect.setY(frameInScreen.y()); widgetRect.setHeight(frameInScreen.height()); // And move upwards if necessary. if (spaceAbove > spaceBelow) widgetRect.move(0, -(widgetRect.height() + targetControlHeight)); } } } return widgetRect; }