void ItemDelegate::setIndexWidget(const QModelIndex &index, ItemWidget *w) { reset(&m_cache[index.row()], w); if (w == NULL) return; QWidget *ww = w->widget(); if (!m_antialiasing) { QFont f = ww->font(); f.setStyleStrategy(QFont::NoAntialias); ww->setFont(f); foreach (QWidget *child, ww->findChildren<QWidget *>("item_child")) child->setFont(f); } // Try to get proper size by showing item momentarily. ww->show(); w->updateSize(m_maxSize, m_idealWidth); ww->hide(); ww->installEventFilter(this); w->setCurrent(m_view->currentIndex() == index); emit rowSizeChanged(); }
void csFontResizer::resizeFont(QObject *watched, const int size, const int increment) { if( (size == 0 && increment == 0) || (size != 0 && increment != 0) ) { return; } QWidget *widget = dynamic_cast<QWidget*>(watched); if( widget == 0 ) { return; } QFont font = widget->font(); if( !defSize.contains(widget) ) { defSize.insert(widget, font.pointSize()); } int newSize(0); if( size != 0 ) { newSize = qBound(minSize, size, maxSize); } else if( increment != 0 ) { newSize = qBound(minSize, font.pointSize() + increment, maxSize); } if( newSize > 0 ) { font.setPointSize(newSize); } widget->setFont(font); }
QgsVertexEditorModel::QgsVertexEditorModel( QgsVectorLayer *layer, QgsSelectedFeature *selectedFeature, QgsMapCanvas *canvas, QObject *parent ) : QAbstractTableModel( parent ) , mLayer( layer ) , mSelectedFeature( selectedFeature ) , mCanvas( canvas ) , mHasZ( false ) , mHasM( false ) , mHasR( true ) //always show for now - avoids scanning whole feature for curves TODO - avoid this , mZCol( -1 ) , mMCol( -1 ) , mRCol( -1 ) { QgsWkbTypes::Type layerWKBType = mLayer->wkbType(); mHasZ = QgsWkbTypes::hasZ( layerWKBType ); mHasM = QgsWkbTypes::hasM( layerWKBType ); if ( mHasZ ) mZCol = 2; if ( mHasM ) mMCol = 2 + ( mHasZ ? 1 : 0 ); if ( mHasR ) mRCol = 2 + ( mHasZ ? 1 : 0 ) + ( mHasM ? 1 : 0 ); QWidget *parentWidget = dynamic_cast< QWidget * >( parent ); if ( parentWidget ) { mWidgetFont = parentWidget->font(); } }
QgsVertexEditorModel::QgsVertexEditorModel( QgsMapCanvas *canvas, QObject *parent ) : QAbstractTableModel( parent ) , mCanvas( canvas ) { QWidget *parentWidget = dynamic_cast< QWidget * >( parent ); if ( parentWidget ) mWidgetFont = parentWidget->font(); }
void NWidgetPrototype::setFontSize(int size) { QWidget *widget = qscriptvalue_cast<QWidget *>(thisObject()); if (widget) { QFont font = widget->font(); font.setPixelSize(size); widget->setFont(font); } }
void DocumentBrowser::resetFontSize() { int fontSize = m_liteApp->settings()->value(DOCUMENT_FONTSIZE,12).toInt(); m_liteApp->settings()->setValue(DOCUMENT_FONTZOOM,100); QWidget *widget = m_htmlWidget->widget(); QFont font = widget->font(); font.setPointSize(fontSize); widget->setFont(font); }
void DocumentBrowser::requestFontZoom(int zoom) { int fontSize = m_liteApp->settings()->value(DOCUMENT_FONTSIZE,12).toInt(); int fontZoom = m_liteApp->settings()->value(DOCUMENT_FONTZOOM,100).toInt(); fontZoom += zoom; if (fontZoom <= 10) { return; } m_liteApp->settings()->setValue(DOCUMENT_FONTZOOM,fontZoom); QWidget *widget = m_htmlWidget->widget(); QFont font = widget->font(); font.setPointSize(fontSize*fontZoom/100.0); widget->setFont(font); }
void View::zoomFontSizeSub(int zoom, const QList<QWidget*>& widgets) { int n = widgets.size(); for(int i=0; i < n; ++i){ QWidget* widget = widgets[i]; QFont font = widget->font(); font.setPointSize(font.pointSize() + zoom); widget->setFont(font); // The following recursive iteration is disabled because // it makes doubled zooming for some composite widgets // zoomFontSizeSub(zoom, widget->findChildren<QWidget*>()); } }
void ContactItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(index); /* Container is the full size of the index */ editor->setGeometry(option.rect); QWidget *widget = editor->focusProxy(); if (widget) { QFontMetrics fm(widget->font()); widget->setGeometry(QRect(46, 5, option.rect.width()-70, fm.height())); } }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QStringList args = app.arguments(); (void) args.takeFirst(); QWidget *widget = 0; QString title; bool usePlainTextEdit = args.size() < 2; if (usePlainTextEdit) { widget = new QPlainTextEdit; title = "PlainTextEdit"; } else { widget = new QTextEdit; title = "TextEdit"; } widget->resize(450, 350); widget->setFocus(); FakeVimHandler fakeVim; QMainWindow mw; mw.setWindowTitle("Fakevim (" + title + ")"); mw.setCentralWidget(widget); mw.resize(500, 650); mw.move(0, 0); mw.show(); QFont font = widget->font(); //: -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1 //font.setFamily("Misc"); font.setFamily("Monospace"); //font.setStretch(QFont::SemiCondensed); widget->setFont(font); mw.statusBar()->setFont(font); QObject::connect(&fakeVim, SIGNAL(commandBufferChanged(QString)), mw.statusBar(), SLOT(showMessage(QString))); QObject::connect(&fakeVim, SIGNAL(quitRequested(QWidget *)), &app, SLOT(quit())); fakeVim.addWidget(widget); if (args.size() >= 1) fakeVim.handleCommand(widget, "r " + args.at(0)); return app.exec(); }
QSize KxMenuItemWidget::sizeHint() const { // Do not give invisible menu items any space if(!fMenuItem->isVisible()) return QSize(0,0); QSize sz; QWidget *q = parentWidget(); QStyleOptionMenuItem opt = getStyleOption(); KxMenuItem *action = fMenuItem; const int hmargin = q->style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, q), iconWidth = q->style()->pixelMetric(QStyle::PM_SmallIconSize, 0, q); QFontMetrics fm(action->font().resolve(q->font())); if (action->isSeparator()) { sz = QSize(2, 2); } else { // Text QString s = action->text(); int w = fm.width(s); QKeySequence shortcutSeq = fMenuItem->shortcut(); sz.setWidth(w); sz.setHeight(fm.height()); // Keyboard shortcut if(!shortcutSeq.isEmpty()) { QString shortcut = shortcutSeq.toString(QKeySequence::NativeText); w = fm.width(shortcut); sz.rwidth() += w + kShortcutRightMargin; } // Checkbox if(action->isCheckable()) { sz.rwidth() += iconWidth; } // option boxes sz.rwidth() += iconWidth; // Margins sz.rwidth() += 2 * hmargin; } opt.rect = q->rect(); sz = q->style()->sizeFromContents(QStyle::CT_MenuItem, &opt, sz, q); return sz; }
void VCLabel_Test::loadXML() { QLCFixtureDefCache fdc; Doc doc(this, fdc); OutputMap om(this, 4); InputMap im(this, 4); MasterTimer mt(this, &om); QWidget w; QDomDocument xmldoc; QDomElement root = xmldoc.createElement("Label"); xmldoc.appendChild(root); QDomElement wstate = xmldoc.createElement("WindowState"); wstate.setAttribute("Width", "42"); wstate.setAttribute("Height", "69"); wstate.setAttribute("X", "3"); wstate.setAttribute("Y", "4"); wstate.setAttribute("Visible", "True"); root.appendChild(wstate); QDomElement appearance = xmldoc.createElement("Appearance"); QFont f(w.font()); f.setPointSize(f.pointSize() + 3); QDomElement font = xmldoc.createElement("Font"); QDomText fontText = xmldoc.createTextNode(f.toString()); font.appendChild(fontText); appearance.appendChild(font); root.appendChild(appearance); QDomElement foobar = xmldoc.createElement("Foobar"); root.appendChild(foobar); VCLabel label(&w, &doc, &om, &im, &mt); QVERIFY(label.loadXML(&root) == true); QCOMPARE(label.geometry().width(), 42); QCOMPARE(label.geometry().height(), 69); QCOMPARE(label.geometry().x(), 3); QCOMPARE(label.geometry().y(), 4); QCOMPARE(label.font(), f); root.setTagName("Lable"); QVERIFY(label.loadXML(&root) == false); }
void WidgetSizeHelper::setDefaultFontSize(QWidget* pWidget) { // we get all of pWidget's children QObjectList children = pWidget->children(); // for each child for ( int i = 0; i < children.length(); i++ ) { /* * we change its font size if it is of one of those types * * - QLabel * - QLineEdit * - QRadioButton * - QGroupBox * - QCheckBox * - QStatusBar */ QWidget* pChild = static_cast<QWidget*> ( children.at(i) ); if ( qobject_cast<QLabel*>(pChild) != NULL || qobject_cast<QLineEdit*>(pChild) != NULL || qobject_cast<QRadioButton*>(pChild) != NULL || qobject_cast<QGroupBox*>(pChild) != NULL || qobject_cast<QCheckBox*>(pChild) != NULL || qobject_cast<QStatusBar*>(pChild) != NULL ) { QFont lFont = pChild->font(); lFont.setPointSize(Constants::MAC_FONT_SIZE); pChild->setFont(lFont); } // and scan it, if it has children if ( ! pChild->children().isEmpty() ) { setDefaultFontSize( pChild ); } } }
QgsNodeEditorModel::QgsNodeEditorModel( QgsVectorLayer* layer, QgsSelectedFeature* selectedFeature, QgsMapCanvas* canvas, QObject* parent ) : QAbstractTableModel( parent ) , mLayer( layer ) , mSelectedFeature( selectedFeature ) , mCanvas( canvas ) , mHasZ( false ) , mHasM( false ) , mHasR( true ) //always show for now - avoids scanning whole feature for curves TODO - avoid this , mZCol( -1 ) , mMCol( -1 ) , mRCol( -1 ) { if ( !mSelectedFeature->vertexMap().isEmpty() ) { mHasZ = mSelectedFeature->vertexMap().at( 0 )->point().is3D(); mHasM = mSelectedFeature->vertexMap().at( 0 )->point().isMeasure(); if ( mHasZ ) mZCol = 2; if ( mHasM ) mMCol = 2 + ( mHasZ ? 1 : 0 ); if ( mHasR ) mRCol = 2 + ( mHasZ ? 1 : 0 ) + ( mHasM ? 1 : 0 ); } QWidget* parentWidget = dynamic_cast< QWidget* >( parent ); if ( parentWidget ) { mWidgetFont = parentWidget->font(); } connect( mSelectedFeature, SIGNAL( vertexMapChanged() ), this, SLOT( featureChanged() ) ); }
void tst_QFont::resetFont() { QWidget parent; QFont parentFont = parent.font(); parentFont.setPointSize(parentFont.pointSize() + 2); parent.setFont(parentFont); QWidget *child = new QWidget(&parent); QFont childFont = child->font(); childFont.setBold(!childFont.bold()); child->setFont(childFont); QVERIFY(parentFont.resolve() != 0); QVERIFY(childFont.resolve() != 0); QVERIFY(childFont != parentFont); child->setFont(QFont()); // reset font QVERIFY(child->font().resolve() == 0); QVERIFY(child->font().pointSize() == parent.font().pointSize()); QVERIFY(parent.font().resolve() != 0); }
void VCXYPad_Test::loadXML() { QWidget w; QDomDocument xmldoc; QDomElement root = xmldoc.createElement("XYPad"); xmldoc.appendChild(root); QDomElement pos = xmldoc.createElement("Position"); pos.setAttribute("X", "10"); pos.setAttribute("Y", "20"); root.appendChild(pos); QDomElement fxi = xmldoc.createElement("Fixture"); fxi.setAttribute("ID", "69"); fxi.setAttribute("Head", "96"); root.appendChild(fxi); QDomElement x = xmldoc.createElement("Axis"); x.setAttribute("ID", "X"); x.setAttribute("LowLimit", "0.1"); x.setAttribute("HighLimit", "0.5"); x.setAttribute("Reverse", "True"); fxi.appendChild(x); QDomElement y = xmldoc.createElement("Axis"); y.setAttribute("ID", "Y"); y.setAttribute("LowLimit", "0.2"); y.setAttribute("HighLimit", "0.6"); y.setAttribute("Reverse", "True"); fxi.appendChild(y); QDomElement fxi2 = xmldoc.createElement("Fixture"); fxi2.setAttribute("ID", "50"); fxi2.setAttribute("Head", "55"); root.appendChild(fxi2); QDomElement x2 = xmldoc.createElement("Axis"); x2.setAttribute("ID", "X"); x2.setAttribute("LowLimit", "0.0"); x2.setAttribute("HighLimit", "1.0"); x2.setAttribute("Reverse", "False"); fxi2.appendChild(x2); QDomElement y2 = xmldoc.createElement("Axis"); y2.setAttribute("ID", "Y"); y2.setAttribute("LowLimit", "0.0"); y2.setAttribute("HighLimit", "1.0"); y2.setAttribute("Reverse", "False"); fxi2.appendChild(y2); QDomElement wstate = xmldoc.createElement("WindowState"); wstate.setAttribute("Width", "42"); wstate.setAttribute("Height", "69"); wstate.setAttribute("X", "3"); wstate.setAttribute("Y", "4"); wstate.setAttribute("Visible", "True"); root.appendChild(wstate); QDomElement appearance = xmldoc.createElement("Appearance"); QFont f(w.font()); f.setPointSize(f.pointSize() + 3); QDomElement font = xmldoc.createElement("Font"); QDomText fontText = xmldoc.createTextNode(f.toString()); font.appendChild(fontText); appearance.appendChild(font); root.appendChild(appearance); QDomElement foobar = xmldoc.createElement("Foobar"); root.appendChild(foobar); VCXYPad pad(&w, m_doc); QVERIFY(pad.loadXML(&root) == true); QCOMPARE(pad.m_fixtures.size(), 2); QCOMPARE(pad.pos(), QPoint(3, 4)); QCOMPARE(pad.size(), QSize(42, 69)); QCOMPARE(pad.m_area->position(), QPointF(10, 20)); VCXYPadFixture fixture(m_doc); fixture.setHead(GroupHead(69, 96)); QVERIFY(pad.m_fixtures.contains(fixture) == true); fixture.setHead(GroupHead(50, 55)); QVERIFY(pad.m_fixtures.contains(fixture) == true); root.setTagName("YXPad"); QVERIFY(pad.loadXML(&root) == false); }
void MENU_KERNEL::SET_WIDGET_DEFAULTS ( QObject * obj, int index ) { if ( QAction::staticMetaObject.className() EQ obj->metaObject()->className() ) { QAction * action = ( QAction * ) obj; if ( M_KERNEL_MENU_SECENEGI [index].icon_path.isEmpty() EQ false ) { action->setIcon ( QIcon(M_KERNEL_MENU_SECENEGI[index].icon_path ) ); } action->setEnabled ( M_KERNEL_MENU_SECENEGI[index].is_enable ); action->setVisible ( M_KERNEL_MENU_SECENEGI[index].is_visible ); return; } QWidget * widget = ( QWidget * ) obj; widget->setEnabled ( M_KERNEL_MENU_SECENEGI[index].is_enable ); widget->setVisible ( M_KERNEL_MENU_SECENEGI[index].is_visible ); if ( m_default_style_sheet.isEmpty() EQ false ) { widget->setStyleSheet ( m_default_style_sheet + "margin:0; padding:0;" ); } if ( QToolButton::staticMetaObject.className() EQ widget->metaObject()->className() ) { QToolButton * tool_button = ( QToolButton * ) widget; if ( tool_button->objectName() NE "NO_ICON" ) { tool_button->setIconSize ( m_default_icon_size ); for ( int i = 0 ; i < m_icon_sizes.size() ; i++ ) { QStringList icon_info = m_icon_sizes.at(i).split ( "//t//" ); if ( icon_info.at(0).toInt() EQ M_KERNEL_MENU_SECENEGI[index].parent_enum_id OR icon_info.at(0).toInt() EQ M_KERNEL_MENU_SECENEGI[index].enum_id) { tool_button->setIconSize ( QSize ( icon_info.at(1).toInt(),icon_info.at(2).toInt() ) ); } } } tool_button->setShortcut ( QKeySequence ( M_KERNEL_MENU_SECENEGI[index].shortcut ) ); tool_button->installEventFilter(this); tool_button->setToolTip ( M_KERNEL_MENU_SECENEGI[index].shortcut ); if ( M_KERNEL_MENU_SECENEGI[index].icon_path.isEmpty() EQ false ) { tool_button->setIcon ( QIcon ( M_KERNEL_MENU_SECENEGI[index].icon_path ) ); } } else if ( QPushButton::staticMetaObject.className() EQ widget->metaObject()->className() ) { QPushButton * push_button = ( QPushButton * ) widget; push_button->setShortcut ( QKeySequence ( M_KERNEL_MENU_SECENEGI[index].shortcut ) ); push_button->installEventFilter(this); push_button->setToolTip ( M_KERNEL_MENU_SECENEGI[index].shortcut ); if ( M_KERNEL_MENU_SECENEGI[index].icon_path.isEmpty() EQ false ) { push_button->setIcon ( QIcon ( M_KERNEL_MENU_SECENEGI[index].icon_path ) ); } } for ( int i = 0 ; i < m_style_sheets.size() ; i++ ) { QStringList style_sheet_info = m_style_sheets.at(i).split ( "//t//" ); if ( style_sheet_info.at(0).toInt() EQ M_KERNEL_MENU_SECENEGI[index].parent_enum_id OR style_sheet_info.at(0).toInt() EQ M_KERNEL_MENU_SECENEGI[index].enum_id) { widget->setStyleSheet ( style_sheet_info.at(1) + "margin:0; padding:0;" ); } } QFont font = widget->font(); if ( font.pointSize() EQ - 1 ) { font.setPixelSize(15); } else { font.setPixelSize(font.pointSize() + 5); } }
int drv_widget(int drvid, void *a0, void* a1, void* a2, void* a3, void* a4, void* a5, void* a6, void* a7, void* a8, void* a9) { handle_head* head = (handle_head*)a0; QWidget *self = (QWidget*)head->native; switch (drvid) { case WIDGET_INIT: { drvNewObj(a0,new QWidget); break; } case WIDGET_DESTROY: { drvDelObj(a0,self); break; } case WIDGET_SETAUTODESTROY: { self->setAttribute(Qt::WA_DeleteOnClose,drvGetBool(a1)); break; } case WIDGET_AUTODESTROY: { drvSetBool(a1,self->testAttribute(Qt::WA_DeleteOnClose)); break; } case WIDGET_SETLAYOUT: { self->setLayout(drvGetLayout(a1)); break; } case WIDGET_LAYOUT: { drvSetHandle(a1,self->layout()); break; } case WIDGET_SETPARENT: { self->setParent(drvGetWidget(a1)); break; } case WIDGET_PARENT: { drvSetHandle(a1,self->parent()); break; } case WIDGET_SETVISIBLE: { self->setVisible(drvGetBool(a1)); break; } case WIDGET_ISVISIBLE: { drvSetBool(a1,self->isVisible()); break; } case WIDGET_SETWINDOWTITLE: { self->setWindowTitle(drvGetString(a1)); break; } case WIDGET_WINDOWTITLE: { drvSetString(a1,self->windowTitle()); break; } case WIDGET_SETPOS: { self->move(drvGetPoint(a1)); break; } case WIDGET_POS: { drvSetPoint(a1,self->pos()); break; } case WIDGET_SETSIZE: { self->resize(drvGetSize(a1)); break; } case WIDGET_SIZE: { drvSetSize(a1,self->size()); break; } case WIDGET_SETGEOMETRY: { self->setGeometry(drvGetRect(a1)); break; } case WIDGET_GEOMETRY: { drvSetRect(a1,self->geometry()); break; } case WIDGET_SETFONT: { self->setFont(drvGetFont(a1)); break; } case WIDGET_FONT: { drvSetFont(a1,self->font()); break; } case WIDGET_CLOSE: { self->close(); break; } case WIDGET_UPDATE: { self->update(); break; } case WIDGET_REPAINT: { self->repaint(); break; } case WIDGET_ONSHOWEVENT: { drvNewEvent(QEvent::Show,a0,a1,a2); break; } case WIDGET_ONHIDEEVENT: { drvNewEvent(QEvent::Hide,a0,a1,a2); break; } case WIDGET_ONCLOSEEVENT: { drvNewEvent(QEvent::Close,a0,a1,a2); break; } case WIDGET_ONKEYPRESSEVENT: { drvNewEvent(QEvent::KeyPress,a0,a1,a2); break; } case WIDGET_ONKEYRELEASEEVENT: { drvNewEvent(QEvent::KeyRelease,a0,a1,a2); break; } case WIDGET_ONMOUSEPRESSEVENT: { drvNewEvent(QEvent::MouseButtonPress,a0,a1,a2); break; } case WIDGET_ONMOUSERELEASEEVENT: { drvNewEvent(QEvent::MouseButtonRelease,a0,a1,a2); break; } case WIDGET_ONMOUSEMOVEEVENT: { drvNewEvent(QEvent::MouseMove,a0,a1,a2); break; } case WIDGET_ONMOUSEDOUBLECLICKEVENT: { drvNewEvent(QEvent::MouseButtonDblClick,a0,a1,a2); break; } case WIDGET_ONMOVEEVENT: { drvNewEvent(QEvent::Move,a0,a1,a2); break; } case WIDGET_ONPAINTEVENT: { drvNewEvent(QEvent::Paint,a0,a1,a2); break; } case WIDGET_ONRESIZEEVENT: { drvNewEvent(QEvent::Resize,a0,a1,a2); break; } case WIDGET_ONENTEREVENT: { drvNewEvent(QEvent::Enter,a0,a1,a2); break; } case WIDGET_ONLEAVEEVENT: { drvNewEvent(QEvent::Leave,a0,a1,a2); break; } case WIDGET_ONFOCUSINEVENT: { drvNewEvent(QEvent::FocusIn,a0,a1,a2); break; } case WIDGET_ONFOCUSOUTEVENT: { drvNewEvent(QEvent::FocusOut,a0,a1,a2); break; } default: return 0; } return 1; }
void QTextBrowser::popupDetail( const QString& contents, const QPoint& pos ) { const int shadowWidth = 6; // also used as '5' and '6' and even '8' below const int vMargin = 8; const int hMargin = 12; QWidget* popup = new QTextDetailPopup; popup->setBackgroundMode( QWidget::NoBackground ); QSimpleRichText* doc = new QSimpleRichText( contents, popup->font() ); doc->adjustSize(); QRect r( 0, 0, doc->width(), doc->height() ); int w = r.width() + 2*hMargin; int h = r.height() + 2*vMargin; popup->resize( w + shadowWidth, h + shadowWidth ); // okay, now to find a suitable location //###### we need a global fancy popup positioning somewhere popup->move(pos - popup->rect().center()); if (popup->geometry().right() > QApplication::desktop()->width()) popup->move( QApplication::desktop()->width() - popup->width(), popup->y() ); if (popup->geometry().bottom() > QApplication::desktop()->height()) popup->move( popup->x(), QApplication::desktop()->height() - popup->height() ); if ( popup->x() < 0 ) popup->move( 0, popup->y() ); if ( popup->y() < 0 ) popup->move( popup->x(), 0 ); popup->show(); // now for super-clever shadow stuff. super-clever mostly in // how many window system problems it skirts around. QPainter p( popup ); p.setPen( QApplication::palette().active().foreground() ); p.drawRect( 0, 0, w, h ); p.setPen( QApplication::palette().active().mid() ); p.setBrush( QColor( 255, 255, 240 ) ); p.drawRect( 1, 1, w-2, h-2 ); p.setPen( black ); doc->draw( &p, hMargin, vMargin, r, popup->colorGroup(), 0 ); delete doc; p.drawPoint( w + 5, 6 ); p.drawLine( w + 3, 6, w + 5, 8 ); p.drawLine( w + 1, 6, w + 5, 10 ); int i; for( i=7; i < h; i += 2 ) p.drawLine( w, i, w + 5, i + 5 ); for( i = w - i + h; i > 6; i -= 2 ) p.drawLine( i, h, i + 5, h + 5 ); for( ; i > 0 ; i -= 2 ) p.drawLine( 6, h + 6 - i, i + 5, h + 5 ); }
void VCCueList_Test::loadXML() { QWidget w; Scene* s1 = new Scene(m_doc); s1->setName("The first"); m_doc->addFunction(s1); Scene* s2 = new Scene(m_doc); s2->setName("Another one"); m_doc->addFunction(s2); Scene* s3 = new Scene(m_doc); s3->setName("The third one"); m_doc->addFunction(s3); Chaser* c4 = new Chaser(m_doc); c4->setName("The defiant one"); m_doc->addFunction(c4); QBuffer buffer; buffer.open(QIODevice::WriteOnly | QIODevice::Text); QXmlStreamWriter xmlWriter(&buffer); xmlWriter.writeStartElement("CueList"); xmlWriter.writeAttribute("Caption", "Test list"); xmlWriter.writeStartElement("WindowState"); xmlWriter.writeAttribute("Width", "42"); xmlWriter.writeAttribute("Height", "69"); xmlWriter.writeAttribute("X", "3"); xmlWriter.writeAttribute("Y", "4"); xmlWriter.writeAttribute("Visible", "True"); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Appearance"); QFont f(w.font()); f.setPointSize(f.pointSize() + 3); xmlWriter.writeTextElement("Font", f.toString()); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Next"); xmlWriter.writeStartElement("Input"); xmlWriter.writeAttribute("Universe", "0"); xmlWriter.writeAttribute("Channel", "1"); xmlWriter.writeEndElement(); xmlWriter.writeTextElement("Key", QKeySequence(keySequenceD).toString()); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Foo"); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Previous"); xmlWriter.writeStartElement("Input"); xmlWriter.writeAttribute("Universe", "2"); xmlWriter.writeAttribute("Channel", "3"); xmlWriter.writeEndElement(); xmlWriter.writeTextElement("Key", QKeySequence(keySequenceC).toString()); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Foo"); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Playback"); xmlWriter.writeStartElement("Input"); xmlWriter.writeAttribute("Universe", "4"); xmlWriter.writeAttribute("Channel", "5"); xmlWriter.writeEndElement(); xmlWriter.writeTextElement("Key", QKeySequence(keySequenceA).toString()); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Stop"); xmlWriter.writeStartElement("Input"); xmlWriter.writeAttribute("Universe", "0"); xmlWriter.writeAttribute("Channel", "6"); xmlWriter.writeEndElement(); xmlWriter.writeTextElement("Key", QKeySequence(keySequenceB).toString()); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Foo"); xmlWriter.writeEndElement(); xmlWriter.writeTextElement("Function", QString::number(s1->id())); xmlWriter.writeTextElement("Function", QString::number(s2->id())); xmlWriter.writeTextElement("Function", QString::number(s3->id())); xmlWriter.writeTextElement("Function", QString::number(c4->id())); xmlWriter.writeTextElement("Function", QString::number(INT_MAX - 1)); // Make sure that nonexistent (id:31337) functions don't appear in the list xmlWriter.writeTextElement("Function", QString::number(31337)); xmlWriter.writeStartElement("Foobar"); xmlWriter.writeEndElement(); xmlWriter.writeEndDocument(); xmlWriter.setDevice(NULL); buffer.close(); buffer.open(QIODevice::ReadOnly | QIODevice::Text); QXmlStreamReader xmlReader(&buffer); xmlReader.readNextStartElement(); VCCueList cl(&w, m_doc); QVERIFY(cl.loadXML(xmlReader) == true); QCOMPARE(cl.m_tree->topLevelItemCount(), 4); QCOMPARE(cl.m_tree->topLevelItem(0)->text(0).toInt(), 1); QCOMPARE(cl.m_tree->topLevelItem(1)->text(0).toInt(), 2); QCOMPARE(cl.m_tree->topLevelItem(2)->text(0).toInt(), 3); QCOMPARE(cl.m_tree->topLevelItem(3)->text(0).toInt(), 4); QCOMPARE(cl.m_tree->topLevelItem(0)->text(1), s1->name()); QCOMPARE(cl.m_tree->topLevelItem(1)->text(1), s2->name()); QCOMPARE(cl.m_tree->topLevelItem(2)->text(1), s3->name()); QCOMPARE(cl.m_tree->topLevelItem(3)->text(1), c4->name()); QSharedPointer<QLCInputSource> const& ni = cl.inputSource(VCCueList::nextInputSourceId); QCOMPARE(ni->universe(), quint32(0)); QCOMPARE(ni->channel(), quint32(1)); QCOMPARE(cl.nextKeySequence(), QKeySequence(keySequenceD)); QSharedPointer<QLCInputSource> const& pi = cl.inputSource(VCCueList::previousInputSourceId); QCOMPARE(pi->universe(), quint32(2)); QCOMPARE(pi->channel(), quint32(3)); QCOMPARE(cl.previousKeySequence(), QKeySequence(keySequenceC)); QSharedPointer<QLCInputSource> const& pli = cl.inputSource(VCCueList::playbackInputSourceId); QCOMPARE(pli->universe(), quint32(4)); QCOMPARE(pli->channel(), quint32(5)); QCOMPARE(cl.playbackKeySequence(), QKeySequence(keySequenceA)); QSharedPointer<QLCInputSource> const& si = cl.inputSource(VCCueList::stopInputSourceId); QCOMPARE(si->universe(), quint32(0)); QCOMPARE(si->channel(), quint32(6)); QCOMPARE(cl.stopKeySequence(), QKeySequence(keySequenceB)); QCOMPARE(cl.pos(), QPoint(3, 4)); QCOMPARE(cl.size(), QSize(42, 69)); QCOMPARE(cl.font(), f); cl.postLoad(); QCOMPARE(cl.m_tree->topLevelItemCount(), 4); QCOMPARE(cl.m_tree->topLevelItem(0)->text(0).toInt(), 1); QCOMPARE(cl.m_tree->topLevelItem(1)->text(0).toInt(), 2); QCOMPARE(cl.m_tree->topLevelItem(2)->text(0).toInt(), 3); QCOMPARE(cl.m_tree->topLevelItem(0)->text(1), s1->name()); QCOMPARE(cl.m_tree->topLevelItem(1)->text(1), s2->name()); QCOMPARE(cl.m_tree->topLevelItem(2)->text(1), s3->name()); QCOMPARE(cl.m_tree->topLevelItem(3)->text(1), c4->name()); buffer.close(); QByteArray bData = buffer.data(); bData.replace("<CueList", "<CueLits"); buffer.setData(bData); buffer.open(QIODevice::ReadOnly | QIODevice::Text); buffer.seek(0); xmlReader.setDevice(&buffer); xmlReader.readNextStartElement(); QVERIFY(cl.loadXML(xmlReader) == false); }
QFileInfo saveWidgetAsImage(QObject* wid, const QRect& r, const QString& dialogTitle, const QString& defaultPath, const AppSettings & appSetting) { QFileInfo fileInfo; QGraphicsScene* scene = 0; QWidget* widget = dynamic_cast<QWidget*>(wid); GraphView* mGraph = dynamic_cast<GraphView*>(wid); if(!mGraph && !widget) { scene = dynamic_cast<QGraphicsScene*>(wid); if(!scene) return fileInfo; } QString filter = QObject::tr("Image (*.png);;Photo (*.jpg);; Windows Bitmap (*.bmp);;Scalable Vector Graphics (*.svg)"); QString fileName = QFileDialog::getSaveFileName(qApp->activeWindow(), dialogTitle, defaultPath, filter); if(!fileName.isEmpty()) { fileInfo = QFileInfo(fileName); QString fileExtension = fileInfo.suffix(); //QString fileExtension = fileName.(".svg"); // bool asSvg = fileName.endsWith(".svg"); // if(asSvg) //QFontMetrics fm((scene ? qApp->font() : widget->font())); float heightText = r.height()/50; //fm.height() + 30; /*if (heightText<10) { heightText = 10; }*/ if(fileExtension == "svg") { if(mGraph) { mGraph->saveAsSVG(fileName, "Title", "Description",true); } else if(scene) { QSvgGenerator svgGen; svgGen.setFileName(fileName); svgGen.setSize(r.size()); svgGen.setViewBox(QRect(0, 0, r.width(), r.height())); svgGen.setDescription(QObject::tr("SVG scene drawing ")); //qDebug()<<"export scene as SVG"; QPainter p; p.begin(&svgGen); scene->render(&p, r, r); p.end(); } else if(widget) { saveWidgetAsSVG(widget, r, fileName); } } else { // save PNG //int versionHeight = 20; //qreal pr = 1;//qApp->devicePixelRatio(); /* qreal prh= 32000. / ( r.height() + versionHeight) ; // QImage axes are limited to 32767x32767 pixels qreal prw= 32000. / r.width() ; qreal pr = (prh<prw)? prh : prw; if (pr>4) { pr=4; } */ // ------------------------------- // Get preferences // ------------------------------- short pr = appSetting.mPixelRatio; short dpm = appSetting.mDpm; short quality = appSetting.mImageQuality; // ------------------------------- // Create the image // ------------------------------- QImage image(r.width() * pr, (r.height() + heightText) * pr , QImage::Format_ARGB32_Premultiplied); if(image.isNull()){ qDebug() << "Cannot export null image!"; return fileInfo; } // ------------------------------- // Set image properties // ------------------------------- image.setDotsPerMeterX(dpm * 11811.024 / 300.); image.setDotsPerMeterY(dpm * 11811.024 / 300.); image.setDevicePixelRatio(pr); // ------------------------------- // Fill background // ------------------------------- if (fileExtension == "jpg") { image.fill(Qt::white); } else { image.fill(Qt::transparent); } // ------------------------------- // Create painter // ------------------------------- QPainter p; p.begin(&image); p.setRenderHint(QPainter::Antialiasing); // ------------------------------- // If widget, draw with or without axis // ------------------------------- if(widget){ //p.setFont(widget->font()); widget->render(&p, QPoint(0, 0), QRegion(r.x(), r.y(), r.width(), r.height())); } // ------------------------------- // If scene... // ------------------------------- else if(scene){ QRectF srcRect = r; srcRect.setX(r.x()); srcRect.setY(r.y()); srcRect.setWidth(r.width() * pr); srcRect.setHeight(r.height() * pr); QRectF tgtRect = image.rect(); tgtRect.adjust(0, 0, 0, -heightText * pr); scene->render(&p, tgtRect, srcRect); } // ------------------------------- // Write application and version // ------------------------------- QFont ft = scene ? qApp->font() : widget->font(); ft.setPixelSize(heightText); p.setFont(ft); p.setPen(Qt::black); p.drawText(0, r.height(), r.width(), heightText, Qt::AlignCenter, qApp->applicationName() + " " + qApp->applicationVersion()); p.end(); // ------------------------------- // Save file // ------------------------------- image.save(fileName, fileExtension.toUtf8(), quality); //image.save(fileName, formatExt); /*QImageWriter writer; writer.setFormat("jpg"); writer.setQuality(100); writer.setFileName(fileName+"_jpg"); writer.write(image);*/ } } return fileInfo; }
int FONTSIZE(const QWidget &w) { w.ensurePolished(); return w.font().pointSize(); }
/*! Traverse QObject based items. */ void TasQtTraverse::traverseObject(TasObject* objectInfo, QObject* object, TasCommand* command) { // Embedded apps must use coordinates for operations, as the parent has no knowledge of the // Actual items bool embeddedApp = false; if (command && command->parameter("embedded") == "true") { embeddedApp = true; } //TasLogger::logger()->debug("TasQtTraverse::traverseObject in"); mTraverseUtils->addObjectDetails(objectInfo, object); QGraphicsObject* graphicsObject = qobject_cast<QGraphicsObject*>(object); if(graphicsObject){ objectInfo->addAttribute("objectType", embeddedApp? TYPE_WEB : TYPE_GRAPHICS_VIEW); mTraverseUtils->addGraphicsItemCoordinates(objectInfo, graphicsObject, command); mTraverseUtils->printGraphicsItemProperties(objectInfo, graphicsObject); //add details only for graphicsitems QGraphicsWidget* graphicsWidget = qobject_cast<QGraphicsWidget*>(object); if(graphicsWidget){ mTraverseUtils->addFont(objectInfo, graphicsWidget->font()); // Elided format "this is a text" -> "this is a..." text for // items that have the "text" property. QVariant text = graphicsWidget->property("text"); if (text.isValid()) { mTraverseUtils->addTextInfo(objectInfo, text.toString(), graphicsWidget->font(), graphicsWidget->size().width()); } QVariant plainText = graphicsWidget->property("plainText"); if (plainText.isValid()) { mTraverseUtils->addTextInfo(objectInfo, plainText.toString(), graphicsWidget->font(), graphicsWidget->size().width()); } } } else{ QQuickItem* quickObject = qobject_cast<QQuickItem*>(object); if (quickObject) { objectInfo->addAttribute("objectType", TYPE_QSCENEGRAPH ); } //make sure that we are dealing with a widget else if (object->isWidgetType()){ QWidget* widget = qobject_cast<QWidget*>(object); objectInfo->addAttribute("objectType", TYPE_STANDARD_VIEW ); addWidgetCoordinates(objectInfo, widget,command); mTraverseUtils->addFont(objectInfo, widget->font()); //check is the widget a viewport to graphicsscene QWidget* parentWidget = widget->parentWidget(); bool isViewPort = false; if(parentWidget && parentWidget->inherits("QGraphicsView")){ QGraphicsView* view = qobject_cast<QGraphicsView*>(parentWidget); if(view->viewport() == widget){ isViewPort = true; } } //add transformation details QGraphicsView* graphicsView = qobject_cast<QGraphicsView*>(object); if(graphicsView){ objectInfo->addBooleanAttribute("isTransformed", graphicsView->isTransformed()); if(graphicsView->isTransformed()){ QTransform tr = graphicsView->transform(); objectInfo->addAttribute("transformM11",tr.m11()); objectInfo->addAttribute("transformM12",tr.m12()); objectInfo->addAttribute("transformM13",tr.m13()); objectInfo->addAttribute("transformM21",tr.m21()); objectInfo->addAttribute("transformM22",tr.m22()); objectInfo->addAttribute("transformM23",tr.m23()); objectInfo->addAttribute("transformM31",tr.m31()); objectInfo->addAttribute("transformM32",tr.m32()); objectInfo->addAttribute("transformM33",tr.m33()); } } objectInfo->addBooleanAttribute("isViewPort", isViewPort); // Add special window id attribute into qwidget atttributes #if defined(Q_WS_X11) unsigned long wid = static_cast<unsigned long>(widget->effectiveWinId()); objectInfo->addAttribute("xWindow", (int)wid); // can this fail due to precision? #endif } else if(object->isWindowType()) { objectInfo->addAttribute("objectType", TYPE_WINDOW_VIEW); } else { if(object != qApp){ objectInfo->addAttribute("objectType", embeddedApp? TYPE_WEB : TYPE_STANDARD_VIEW ); } } } }
void VCCueList_Test::loadXML() { QWidget w; Scene* s1 = new Scene(m_doc); s1->setName("The first"); m_doc->addFunction(s1); Scene* s2 = new Scene(m_doc); s2->setName("Another one"); m_doc->addFunction(s2); Scene* s3 = new Scene(m_doc); s3->setName("The third one"); m_doc->addFunction(s3); Chaser* c4 = new Chaser(m_doc); c4->setName("The defiant one"); m_doc->addFunction(c4); QDomDocument xmldoc; QDomElement root = xmldoc.createElement("CueList"); root.setAttribute("Caption", "Test list"); xmldoc.appendChild(root); QDomElement wstate = xmldoc.createElement("WindowState"); wstate.setAttribute("Width", "42"); wstate.setAttribute("Height", "69"); wstate.setAttribute("X", "3"); wstate.setAttribute("Y", "4"); wstate.setAttribute("Visible", "True"); root.appendChild(wstate); QDomElement appearance = xmldoc.createElement("Appearance"); QFont f(w.font()); f.setPointSize(f.pointSize() + 3); QDomElement font = xmldoc.createElement("Font"); QDomText fontText = xmldoc.createTextNode(f.toString()); font.appendChild(fontText); appearance.appendChild(font); root.appendChild(appearance); QDomElement next = xmldoc.createElement("Next"); QDomElement nextInput = xmldoc.createElement("Input"); nextInput.setAttribute("Universe", "0"); nextInput.setAttribute("Channel", "1"); next.appendChild(nextInput); QDomElement nextKey = xmldoc.createElement("Key"); QDomText nextKeyText = xmldoc.createTextNode(QKeySequence(keySequenceD).toString()); nextKey.appendChild(nextKeyText); next.appendChild(nextKey); QDomElement nextFoo = xmldoc.createElement("Foo"); next.appendChild(nextFoo); root.appendChild(next); QDomElement previous = xmldoc.createElement("Previous"); QDomElement previousInput = xmldoc.createElement("Input"); previousInput.setAttribute("Universe", "2"); previousInput.setAttribute("Channel", "3"); previous.appendChild(previousInput); QDomElement previousKey = xmldoc.createElement("Key"); QDomText previousKeyText = xmldoc.createTextNode(QKeySequence(keySequenceC).toString()); previousKey.appendChild(previousKeyText); previous.appendChild(previousKey); QDomElement previousFoo = xmldoc.createElement("Foo"); previous.appendChild(previousFoo); root.appendChild(previous); QDomElement playback = xmldoc.createElement("Playback"); QDomElement playbackInput = xmldoc.createElement("Input"); playbackInput.setAttribute("Universe", "4"); playbackInput.setAttribute("Channel", "5"); playback.appendChild(playbackInput); QDomElement playbackKey = xmldoc.createElement("Key"); QDomText playbackKeyText = xmldoc.createTextNode(QKeySequence(keySequenceA).toString()); playbackKey.appendChild(playbackKeyText); playback.appendChild(playbackKey); QDomElement playbackFoo = xmldoc.createElement("Foo"); playback.appendChild(playbackFoo); root.appendChild(playback); QDomElement f1 = xmldoc.createElement("Function"); QDomText f1Text = xmldoc.createTextNode(QString::number(s1->id())); f1.appendChild(f1Text); root.appendChild(f1); QDomElement f2 = xmldoc.createElement("Function"); QDomText f2Text = xmldoc.createTextNode(QString::number(s2->id())); f2.appendChild(f2Text); root.appendChild(f2); QDomElement f3 = xmldoc.createElement("Function"); QDomText f3Text = xmldoc.createTextNode(QString::number(s3->id())); f3.appendChild(f3Text); root.appendChild(f3); QDomElement f4 = xmldoc.createElement("Function"); QDomText f4Text = xmldoc.createTextNode(QString::number(c4->id())); f4.appendChild(f4Text); root.appendChild(f4); QDomElement f5 = xmldoc.createElement("Function"); QDomText f5Text = xmldoc.createTextNode(QString::number(INT_MAX - 1)); f5.appendChild(f5Text); root.appendChild(f5); // Make sure that nonexistent (id:31337) functions don't appear in the list QDomElement f6 = xmldoc.createElement("Function"); QDomText f6Text = xmldoc.createTextNode(QString::number(31337)); f6.appendChild(f6Text); root.appendChild(f6); QDomElement foo = xmldoc.createElement("Foobar"); root.appendChild(foo); VCCueList cl(&w, m_doc); QVERIFY(cl.loadXML(&root) == true); QCOMPARE(cl.m_tree->topLevelItemCount(), 4); QCOMPARE(cl.m_tree->topLevelItem(0)->text(0).toInt(), 1); QCOMPARE(cl.m_tree->topLevelItem(1)->text(0).toInt(), 2); QCOMPARE(cl.m_tree->topLevelItem(2)->text(0).toInt(), 3); QCOMPARE(cl.m_tree->topLevelItem(3)->text(0).toInt(), 4); QCOMPARE(cl.m_tree->topLevelItem(0)->text(1), s1->name()); QCOMPARE(cl.m_tree->topLevelItem(1)->text(1), s2->name()); QCOMPARE(cl.m_tree->topLevelItem(2)->text(1), s3->name()); QCOMPARE(cl.m_tree->topLevelItem(3)->text(1), c4->name()); QCOMPARE(cl.inputSource(VCCueList::nextInputSourceId), QLCInputSource(0, 1)); QCOMPARE(cl.nextKeySequence(), QKeySequence(keySequenceD)); QCOMPARE(cl.inputSource(VCCueList::previousInputSourceId), QLCInputSource(2, 3)); QCOMPARE(cl.previousKeySequence(), QKeySequence(keySequenceC)); QCOMPARE(cl.inputSource(VCCueList::playbackInputSourceId), QLCInputSource(4, 5)); QCOMPARE(cl.playbackKeySequence(), QKeySequence(keySequenceA)); QCOMPARE(cl.pos(), QPoint(3, 4)); QCOMPARE(cl.size(), QSize(42, 69)); QCOMPARE(cl.font(), f); cl.postLoad(); QCOMPARE(cl.m_tree->topLevelItemCount(), 4); QCOMPARE(cl.m_tree->topLevelItem(0)->text(0).toInt(), 1); QCOMPARE(cl.m_tree->topLevelItem(1)->text(0).toInt(), 2); QCOMPARE(cl.m_tree->topLevelItem(2)->text(0).toInt(), 3); QCOMPARE(cl.m_tree->topLevelItem(0)->text(1), s1->name()); QCOMPARE(cl.m_tree->topLevelItem(1)->text(1), s2->name()); QCOMPARE(cl.m_tree->topLevelItem(2)->text(1), s3->name()); QCOMPARE(cl.m_tree->topLevelItem(3)->text(1), c4->name()); root.setTagName("CueLits"); QVERIFY(cl.loadXML(&root) == false); }
QWidget *PoitemTableDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/*style*/, const QModelIndex &index) const { const QAbstractItemModel *model = index.model(); QWidget *editor = 0; switch (index.column()) { case ITEM_NUMBER_COL: { ItemLineEdit *item = new ItemLineEdit(parent); item->setType(ItemLineEdit::cGeneralPurchased | ItemLineEdit::cActive); if ((qobject_cast<const PoitemTableModel*>(model))->_vendrestrictpurch) { int vendid = (qobject_cast<const PoitemTableModel*>(model))->_vendid; // TODO: put queries in ItemLineEdit, trigger them with a setVendId() item->setQuery( QString("SELECT DISTINCT item_id, item_number, item_descrip1, item_descrip2," " uom_name, item_type, item_config " "FROM item, itemsite, itemsrc, uom " "WHERE ( (itemsite_item_id=item_id)" " AND (itemsrc_item_id=item_id)" " AND (item_inv_uom_id=uom_id)" " AND (itemsite_active)" " AND (item_active)" " AND (itemsrc_active)" " AND (itemsrc_vend_id=%1) ) " "ORDER BY item_number;" ) .arg(vendid) ); item->setValidationQuery( QString("SELECT DISTINCT item_id, item_number, item_descrip1, item_descrip2," " uom_name, item_type, item_config " "FROM item, itemsite, itemsrc, uom " "WHERE ( (itemsite_item_id=item_id)" " AND (itemsrc_item_id=item_id)" " AND (item_inv_uom_id=uom_id)" " AND (itemsite_active)" " AND (item_active)" " AND (itemsrc_active)" " AND (itemsrc_vend_id=%1) " " AND (itemsite_item_id=:item_id) ) " "ORDER BY item_number;" ) .arg(vendid) ); } else item->setType(ItemLineEdit::cGeneralPurchased | ItemLineEdit::cActive); editor = item; break; } case WAREHOUS_CODE_COL: { int itemid = model->data(model->index(index.row(), ITEM_ID_COL)).toInt(); if (itemid <= 0) // probably non-inventory item so don't pick a whs break; WComboBox *whs = new WComboBox(parent); whs->setType(WComboBox::Supply); whs->findItemsites(itemid); editor = whs; break; } case POITEM_VEND_ITEM_NUMBER_COL: { editor = new QLineEdit(parent); editor->setObjectName("poitem_vend_item_number"); break; } case POITEM_QTY_ORDERED_COL: { QLineEdit *qty = new QLineEdit(parent); qty->setValidator(omfgThis->qtyVal()); editor = qty; break; } case POITEM_UNITPRICE_COL: case POITEM_FREIGHT_COL: { QLineEdit *price = new QLineEdit(parent); price->setValidator(omfgThis->priceVal()); editor = price; break; } case POITEM_DUEDATE_COL: { DLineEdit *duedate = new DLineEdit(parent); editor = duedate; editor->setObjectName("poitem_duedate"); break; } #ifdef QE_PROJECT case PRJ_NUMBER_COL: { ProjectLineEdit *prj = new ProjectLineEdit(parent); prj->setType(ProjectLineEdit::PurchaseOrder); editor = prj; editor->setObjectName("prj_number"); break; } #endif #ifdef QE_NONINVENTORY case EXPCAT_CODE_COL: { ExpenseLineEdit *expcat = new ExpenseLineEdit(parent); editor = expcat; break; } #endif default: { editor = 0; break; } } if (editor) { #ifdef Q_WS_MAC // compensate for many custom widgets making themselves smaller on OS X QFont f = editor->font(); f.setPointSize(f.pointSize() + 2); editor->setFont(f); #endif editor->installEventFilter(const_cast<PoitemTableDelegate*>(this)); } return editor; }
/*! Change color and fonts of a plot \sa QwtPlotPrintFilter::apply */ void QwtPlotPrintFilter::apply(QwtPlot *plot) const { QwtPlotPrintFilter *that = (QwtPlotPrintFilter *)this; delete that->d_cache; that->d_cache = new QwtPlotPrintFilterCache; QwtPlotPrintFilterCache &cache = *that->d_cache; if ( plot->d_lblTitle ) { QPalette palette = plot->d_lblTitle->palette(); cache.titleColor = palette.color( QPalette::Active, QColorGroup::Foreground); palette.setColor(QPalette::Active, QColorGroup::Foreground, color(cache.titleColor, Title)); plot->d_lblTitle->setPalette(palette); cache.titleFont = plot->d_lblTitle->font(); plot->d_lblTitle->setFont(font(cache.titleFont, Title)); } if ( plot->d_legend ) { QIntDictIterator<QWidget> it = plot->d_legend->itemIterator(); for ( QWidget *w = it.toFirst(); w != 0; w = ++it) { const int key = it.currentKey(); cache.legendFonts.insert(it.currentKey(), new QFont(w->font())); w->setFont(font(w->font(), Legend, key)); if ( w->inherits("QwtLegendButton") ) { QwtLegendButton *btn = (QwtLegendButton *)w; QwtSymbol symbol = btn->symbol(); QPen pen = symbol.pen(); QBrush brush = symbol.brush(); pen.setColor(color(pen.color(), CurveSymbol, key)); brush.setColor(color(brush.color(), CurveSymbol, key)); symbol.setPen(pen); symbol.setBrush(brush); btn->setSymbol(symbol); pen = btn->curvePen(); pen.setColor(color(pen.color(), Curve, key)); btn->setCurvePen(pen); } } } for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { QwtScale *scale = plot->d_scale[axis]; if ( scale ) { cache.scaleColor[axis] = scale->palette().color( QPalette::Active, QColorGroup::Foreground); QPalette palette = scale->palette(); palette.setColor(QPalette::Active, QColorGroup::Foreground, color(cache.scaleColor[axis], AxisScale, axis)); scale->setPalette(palette); cache.scaleFont[axis] = scale->font(); scale->setFont(font(cache.scaleFont[axis], AxisScale, axis)); cache.scaleTitleColor[axis] = scale->titleColor(); scale->setTitleColor( color(cache.scaleTitleColor[axis], AxisTitle, axis)); cache.scaleTitleFont[axis] = scale->titleFont(); scale->setTitleFont( font(cache.scaleTitleFont[axis], AxisTitle, axis)); int startDist, endDist; scale->minBorderDist(startDist, endDist); scale->setBorderDist(startDist, endDist); } } cache.widgetBackground = plot->backgroundColor(); plot->setBackgroundColor(color(cache.widgetBackground, WidgetBackground)); cache.canvasBackground = plot->canvasBackground(); plot->setCanvasBackground(color(cache.canvasBackground, CanvasBackground)); QPen pen = plot->d_grid->majPen(); cache.gridColors[0] = pen.color(); pen.setColor(color(pen.color(), MajorGrid)); plot->d_grid->setMajPen(pen); pen = plot->d_grid->minPen(); cache.gridColors[1] = pen.color(); pen.setColor(color(pen.color(), MinorGrid)); plot->d_grid->setMinPen(pen); QIntDictIterator<QwtPlotCurve> itc(*plot->d_curves); for (QwtPlotCurve *c = itc.toFirst(); c != 0; c = ++itc ) { const int key = itc.currentKey(); QwtSymbol symbol = c->symbol(); QPen pen = symbol.pen(); cache.curveSymbolPenColors.insert(key, new QColor(pen.color())); pen.setColor(color(pen.color(), CurveSymbol, key)); symbol.setPen(pen); QBrush brush = symbol.brush(); cache.curveSymbolBrushColors.insert(key, new QColor(brush.color())); brush.setColor(color(brush.color(), CurveSymbol, key)); symbol.setBrush(brush); c->setSymbol(symbol); pen = c->pen(); cache.curveColors.insert(key, new QColor(pen.color())); pen.setColor(color(pen.color(), Curve, key)); c->setPen(pen); } QIntDictIterator<QwtPlotMarker> itm(*plot->d_markers); for (QwtPlotMarker *m = itm.toFirst(); m != 0; m = ++itm ) { const int key = itm.currentKey(); cache.markerFonts.insert(key, new QFont(m->font())); m->setFont(font(m->font(), Marker, key)); QPen pen = m->labelPen(); cache.markerLabelColors.insert(key, new QColor(pen.color())); pen.setColor(color(pen.color(), Marker, key)); m->setLabelPen(pen); pen = m->linePen(); cache.markerLineColors.insert(key, new QColor(pen.color())); pen.setColor(color(pen.color(), Marker, key)); m->setLinePen(pen); QwtSymbol symbol = m->symbol(); pen = symbol.pen(); cache.markerSymbolPenColors.insert(key, new QColor(pen.color())); pen.setColor(color(pen.color(), MarkerSymbol, key)); symbol.setPen(pen); QBrush brush = symbol.brush(); cache.markerSymbolBrushColors.insert(key, new QColor(brush.color())); brush.setColor(color(brush.color(), MarkerSymbol, key)); symbol.setBrush(brush); m->setSymbol(symbol); } }
/*! Change color and fonts of a plot \sa apply() */ void QwtPlotPrintFilter::apply(QwtPlot *plot) const { const bool doAutoReplot = plot->autoReplot(); plot->setAutoReplot(false); delete d_data->cache; d_data->cache = new PrivateData::Cache; PrivateData::Cache &cache = *d_data->cache; if ( plot->titleLabel() ) { QPalette palette = plot->titleLabel()->palette(); cache.titleColor = palette.color( QPalette::Active, Palette::Text); palette.setColor(QPalette::Active, Palette::Text, color(cache.titleColor, Title)); plot->titleLabel()->setPalette(palette); cache.titleFont = plot->titleLabel()->font(); plot->titleLabel()->setFont(font(cache.titleFont, Title)); } if ( plot->legend() ) { #if QT_VERSION < 0x040000 QValueList<QWidget *> list = plot->legend()->legendItems(); for ( QValueListIterator<QWidget *> it = list.begin(); it != list.end(); ++it ) #else QList<QWidget *> list = plot->legend()->legendItems(); for ( QList<QWidget*>::iterator it = list.begin(); it != list.end(); ++it ) #endif { QWidget *w = *it; cache.legendFonts.insert(w, w->font()); w->setFont(font(w->font(), Legend)); if ( w->inherits("QwtLegendItem") ) { QwtLegendItem *label = (QwtLegendItem *)w; QwtSymbol symbol = label->symbol(); QPen pen = symbol.pen(); QBrush brush = symbol.brush(); pen.setColor(color(pen.color(), CurveSymbol)); brush.setColor(color(brush.color(), CurveSymbol)); symbol.setPen(pen); symbol.setBrush(brush); label->setSymbol(symbol); pen = label->curvePen(); pen.setColor(color(pen.color(), Curve)); label->setCurvePen(pen); } } } for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { QwtScaleWidget *scaleWidget = plot->axisWidget(axis); if ( scaleWidget ) { cache.scaleColor[axis] = scaleWidget->palette().color( QPalette::Active, Palette::Foreground); QPalette palette = scaleWidget->palette(); palette.setColor(QPalette::Active, Palette::Foreground, color(cache.scaleColor[axis], AxisScale)); scaleWidget->setPalette(palette); cache.scaleFont[axis] = scaleWidget->font(); scaleWidget->setFont(font(cache.scaleFont[axis], AxisScale)); cache.scaleTitle[axis] = scaleWidget->title(); QwtText scaleTitle = scaleWidget->title(); if ( scaleTitle.testPaintAttribute(QwtText::PaintUsingTextColor) ) { cache.scaleTitleColor[axis] = scaleTitle.color(); scaleTitle.setColor( color(cache.scaleTitleColor[axis], AxisTitle)); } if ( scaleTitle.testPaintAttribute(QwtText::PaintUsingTextFont) ) { cache.scaleTitleFont[axis] = scaleTitle.font(); scaleTitle.setFont( font(cache.scaleTitleFont[axis], AxisTitle)); } scaleWidget->setTitle(scaleTitle); int startDist, endDist; scaleWidget->getBorderDistHint(startDist, endDist); scaleWidget->setBorderDist(startDist, endDist); } } if ( hasBackgroundColor(plot) ) { QPalette p = plot->palette(); cache.widgetBackground = plot->palette().color( QPalette::Active, Palette::Background); p.setColor(QPalette::Active, Palette::Background, color(cache.widgetBackground, WidgetBackground)); plot->setPalette(p); } if ( hasBackgroundColor(plot->canvas())) { cache.canvasBackground = plot->canvasBackground(); plot->setCanvasBackground(color(cache.canvasBackground, CanvasBackground)); } const QwtPlotItemList& itmList = plot->itemList(); for ( QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); ++it ) { apply(*it); } plot->setAutoReplot(doAutoReplot); }
QWidget *ToitemTableDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/*style*/, const QModelIndex &index) const { const ToitemTableModel *model = (ToitemTableModel*)(index.model()); QWidget *editor = 0; switch (index.column()) { case ITEM_NUMBER_COL: { ItemLineEdit *item = new ItemLineEdit(parent); item->setType(ItemLineEdit::cActive); item->addExtraClause(QString("(item_id IN (" " SELECT itemsite_item_id" " FROM itemsite" " WHERE itemsite_warehous_id=%1))") .arg(model->srcWhsId())); editor = item; break; } case TOITEM_QTY_ORDERED_COL: { QLineEdit *qty = new QLineEdit(parent); qty->setValidator(omfgThis->qtyVal()); editor = qty; break; } case TOITEM_FREIGHT_COL: { QLineEdit *price = new QLineEdit(parent); price->setValidator(omfgThis->priceVal()); editor = price; break; } case TOITEM_DUEDATE_COL: { DLineEdit *duedate = new DLineEdit(parent); editor = duedate; editor->setObjectName("toitem_duedate"); break; } #ifdef QE_PROJECT case PRJ_NUMBER_COL: { ProjectLineEdit *prj = new ProjectLineEdit(parent); prj->setType(ProjectLineEdit::PurchaseOrder); editor = prj; editor->setObjectName("prj_number"); break; } #endif default: { editor = 0; break; } } if (editor) { #ifdef Q_WS_MAC // compensate for many custom widgets making themselves smaller on OS X QFont f = editor->font(); f.setPointSize(f.pointSize() + 2); editor->setFont(f); #endif editor->installEventFilter(const_cast<ToitemTableDelegate*>(this)); } return editor; }
QWidget* GCF::ActionContainerWidget::createWidget(QAction* action, int rowSpan, int colSpan) { QWidget* ret = 0; int gSize=int((fontMetrics().height()+fontMetrics().ascent())*1.2); int minWidth = gSize*colSpan; QWidgetAction* wAction = qobject_cast<QWidgetAction*>(action); if(wAction) ret = wAction->requestWidget(this); else { QToolButton* tb = new QToolButton(this); tb->setDefaultAction(action); tb->setAutoRaise(true); /*if(action->menu()) tb->setMenu(action->menu());*/ tb->setIconSize(QSize(gSize-4,gSize-4)); if(action->icon().isNull()) tb->setToolButtonStyle(Qt::ToolButtonTextOnly); else if(colSpan == rowSpan && colSpan >= 2) tb->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); else if(colSpan == rowSpan && colSpan == 1) tb->setToolButtonStyle(Qt::ToolButtonIconOnly); else if(colSpan >= 2 || rowSpan == 1) tb->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); else if(rowSpan >= 3) tb->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); int mw = 0; if(tb->toolButtonStyle() != Qt::ToolButtonIconOnly) mw += fontMetrics().width(action->iconText())+2*fontMetrics().width("_"); if(!action->icon().isNull()) { switch(tb->toolButtonStyle()) { case Qt::ToolButtonTextUnderIcon: if(mw < gSize-4) mw = gSize-4; break; case Qt::ToolButtonTextBesideIcon: mw += gSize-4; break; } } if(minWidth < mw) minWidth = mw; if(action->menu()) { // Connect the default action object to the tool button. This way // when the toolbutton with menu is clicked, the default action is // shown. QList<QAction*> actions = action->menu()->actions(); QAction* defAction = 0; for(int i=0; i<actions.count(); i++) { QAction* action = actions[i]; QList<QByteArray> propNames = action->dynamicPropertyNames(); if(propNames.contains("_default_")) { bool val = action->property("_default_").toBool(); if(val) { defAction = action; break; } } } if(defAction) { if(defAction->isCheckable()) connect(tb, SIGNAL(clicked()), defAction, SLOT(toggle())); else connect(tb, SIGNAL(clicked()), defAction, SLOT(trigger())); QFont font = defAction->font(); font.setBold(true); defAction->setFont(font); } } ret = tb; } ret->setMinimumSize(minWidth, gSize*rowSpan); if(!action->icon().isNull()) { QFont font = ret->font(); // font.setPointSize(font.pointSize()-1); ret->setFont(font); } /*static QPlastiqueStyle Style; ret->setStyle(&Style);*/ return ret; }