double FrameWidget::heightIn(QWidget *w, Unit unit) { double dpi = (double)w->logicalDpiY(); double val = 0.0; switch(unit){ case Pixel: val = (double)w->height(); break; case Inch: val = (double)w->height()/dpi; break; case Millimeter: val = 25.4*w->height()/dpi; break; case Centimeter: val = 2.54*w->height()/dpi; break; case Point: val = 72.0*w->height()/dpi; break; case Scale: FrameWidget *fw = qobject_cast<FrameWidget *>(w); if (fw) val = fabs(fw->bottom() - fw->yValue()); break; } return val; }
void EnrichmentDialog::apply() { if (tabWidget->currentPage() == editPage) fetchImage(); else if (tabWidget->currentPage() == framePage) frameApplyTo(); else if (imagePage && tabWidget->currentPage() == imagePage) chooseImageFile(imagePathBox->text()); else if (tabWidget->currentPage() == geometryPage){ setCoordinates(unitBox->currentIndex()); FrameWidget *fw = qobject_cast<FrameWidget *>(d_widget); if (fw) fw->setAttachPolicy((FrameWidget::AttachPolicy)attachToBox->currentIndex()); if (d_app) d_app->d_keep_aspect_ration = keepAspectBox->isChecked(); } else if (patternPage && tabWidget->currentPage() == patternPage) patternApplyTo(); else if (textPage && tabWidget->currentPage() == textPage){ LegendWidget *l = qobject_cast<LegendWidget *>(d_widget); if (l) l->setText(textEditBox->text()); textFormatApplyTo(); if (d_app) d_app->setFormatBarFont(textFont); } }
void EnrichmentDialog::setCoordinates(int unit) { if (!d_widget) return; if (unit == FrameWidget::Scale){//ScaleCoordinates double left = xBox->value(); double top = yBox->value(); FrameWidget *fw = qobject_cast<FrameWidget *>(d_widget); if (fw) fw->setCoordinates(left, top, left + widthBox->value(), top - heightBox->value()); } else FrameWidget::setRect(d_widget, xBox->value(), yBox->value(), widthBox->value(), heightBox->value(), (FrameWidget::Unit)unit); if (d_plot) d_plot->multiLayer()->notifyChanges(); if (d_app) d_app->d_frame_geometry_unit = unit; }
foreach(QWidget *i, d_widgets){ LegendWidget *l = qobject_cast<LegendWidget *>(i); if (!l){ QRect r = operateOn(i->geometry()); i->setGeometry(r); FrameWidget *f = qobject_cast<FrameWidget *>(i); if (f) f->updateCoordinates(); continue; } QRect new_rect = operateOn(l->geometry()); l->move(new_rect.topLeft()); if (!l->text().isEmpty()){ QFont f = l->font(); f.setPointSize(f.pointSize() * new_rect.width() * new_rect.height()/(l->rect().width() * l->rect().height())); l->setFont(f); l->plot()->notifyFontChange(f); } }
void FrameWidget::setRect(QWidget *widget, double x, double y, double w, double h, Unit unit) { if (!widget) return; int dpiX = widget->logicalDpiX(); int dpiY = widget->logicalDpiY(); FrameWidget *fw = qobject_cast<FrameWidget *>(widget); if (fw){ switch(unit){ case Pixel: fw->setRect(qRound(x), qRound(y), qRound(w), qRound(h)); break; case Inch: fw->setRect(qRound(x*dpiX), qRound(y*dpiY), qRound(w*dpiX), qRound(h*dpiY)); break; case Millimeter: fw->setRect(qRound(x*dpiX/25.4), qRound(y*dpiY/25.4), qRound(w*dpiX/25.4), qRound(h*dpiY/25.4)); break; case Centimeter: fw->setRect(qRound(x*dpiX/2.54), qRound(y*dpiY/2.54), qRound(w*dpiX/2.54), qRound(h*dpiY/2.54)); break; case Point: fw->setRect(qRound(x*dpiX/72.0), qRound(y*dpiY/72.0), qRound(w*dpiX/72.0), qRound(h*dpiY/72.0)); break; case Scale: fw->setCoordinates(x, y, x + w, y + h); break; } return; } switch(unit){ case Pixel: widget->setGeometry(qRound(x), qRound(y), qRound(w), qRound(h)); break; case Inch: widget->setGeometry(qRound(x*dpiX), qRound(y*dpiY), qRound(w*dpiX), qRound(h*dpiY)); break; case Millimeter: widget->setGeometry(qRound(x*dpiX/25.4), qRound(y*dpiY/25.4), qRound(w*dpiX/25.4), qRound(h*dpiY/25.4)); break; case Centimeter: widget->setGeometry(qRound(x*dpiX/2.54), qRound(y*dpiY/2.54), qRound(w*dpiX/2.54), qRound(h*dpiY/2.54)); break; case Point: widget->setGeometry(qRound(x*dpiX/72.0), qRound(y*dpiY/72.0), qRound(w*dpiX/72.0), qRound(h*dpiY/72.0)); break; default: break; } }
void EnrichmentDialog::setWidget(QWidget *w) { if (!w || !d_app) return; d_widget = w; FrameWidget *fw = qobject_cast<FrameWidget *>(d_widget); if (fw){ #ifndef QT_MAC_USE_COCOA if (d_plot) d_plot->deselectMarker(); #endif frameBox->blockSignals(true); frameBox->setCurrentIndex(fw->frameStyle()); frameBox->blockSignals(false); frameColorBtn->blockSignals(true); frameColorBtn->setColor(fw->frameColor()); frameColorBtn->blockSignals(false); boxFrameLineStyle->blockSignals(true); boxFrameLineStyle->setStyle(fw->framePen().style()); boxFrameLineStyle->blockSignals(false); boxFrameWidth->blockSignals(true); if (d_widget_type == Ellipse) boxFrameWidth->setValue(fw->framePen().widthF()); else boxFrameWidth->setValue(fw->framePen().width()); boxFrameWidth->blockSignals(false); unitBox->setCurrentIndex(d_app->d_frame_geometry_unit); attachToBox->setCurrentIndex((int)fw->attachPolicy()); displayCoordinates(d_app->d_frame_geometry_unit); } else { unitBox->setCurrentIndex(FrameWidget::Pixel); displayCoordinates(FrameWidget::Pixel); } if (d_widget_type == Text){ LegendWidget *l = qobject_cast<LegendWidget *>(d_widget); if (l){ setText(textEditBox, l->text()); textFont = l->font(); QFont fnt = textFont; fnt.setPointSize(QFont().pointSize() + 2); textEditBox->setFont(fnt); textColorBtn->blockSignals(true); textColorBtn->setColor(l->textColor()); textColorBtn->blockSignals(false); QColor bc = l->backgroundColor(); boxBackgroundTransparency->blockSignals(true); boxBackgroundTransparency->setValue(100*bc.alphaF()); boxBackgroundTransparency->blockSignals(false); transparencySlider->blockSignals(true); transparencySlider->setValue(boxBackgroundTransparency->value()); transparencySlider->blockSignals(false); textBackgroundBtn->blockSignals(true); textBackgroundBtn->setEnabled(bc.alpha()); bc.setAlpha(255); textBackgroundBtn->setColor(bc); textBackgroundBtn->blockSignals(false); boxTextAngle->blockSignals(true); boxTextAngle->setValue(l->angle()); boxTextAngle->blockSignals(false); autoUpdateTextBox->setChecked(l->isAutoUpdateEnabled()); texOutputBox->setChecked(l->hasTeXOutput()); updateButtons(); } } else if (d_widget_type == Tex){ TexWidget *tw = qobject_cast<TexWidget *>(d_widget); if (tw){ setText(equationEditor, tw->formula()); outputLabel->setPixmap(tw->pixmap()); bestSizeButton->show(); } return; } else if (d_widget_type == Image){ ImageWidget *i = qobject_cast<ImageWidget *>(d_widget); if (i){ imagePathBox->setText(i->fileName()); boxSaveImagesInternally->blockSignals(true); boxSaveImagesInternally->setChecked(i->saveInternally()); boxSaveImagesInternally->blockSignals(false); bestSizeButton->show(); } } else if (d_widget_type == Frame || d_widget_type == Ellipse){ QColor bc = fw->backgroundColor(); boxTransparency->blockSignals(true); boxTransparency->setValue(100.0*bc.alphaF()); boxTransparency->blockSignals(false); fillTransparencySlider->blockSignals(true); fillTransparencySlider->setValue(boxTransparency->value()); fillTransparencySlider->blockSignals(false); bc.setAlpha(255); backgroundColorBtn->blockSignals(true); backgroundColorBtn->setColor(bc); backgroundColorBtn->blockSignals(false); patternBox->blockSignals(true); patternBox->setPattern(fw->brush().style()); patternBox->blockSignals(false); patternColorBtn->blockSignals(true); patternColorBtn->setColor(fw->brush().color()); patternColorBtn->blockSignals(false); } }
void EnrichmentDialog::setWidget(QWidget *w) { if (!w) return; ApplicationWindow *app = (ApplicationWindow *)parent(); if (!app) return; d_widget = w; FrameWidget *fw = qobject_cast<FrameWidget *>(d_widget); if (fw){ frameBox->blockSignals(true); frameBox->setCurrentIndex(fw->frameStyle()); frameBox->blockSignals(false); frameColorBtn->blockSignals(true); frameColorBtn->setColor(fw->frameColor()); frameColorBtn->blockSignals(false); boxFrameLineStyle->blockSignals(true); boxFrameLineStyle->setStyle(fw->framePen().style()); boxFrameLineStyle->blockSignals(false); boxFrameWidth->blockSignals(true); if (d_widget_type == Ellipse) boxFrameWidth->setValue(fw->framePen().widthF()); else boxFrameWidth->setValue(fw->framePen().width()); boxFrameWidth->blockSignals(false); unitBox->setCurrentIndex(app->d_frame_geometry_unit); attachToBox->setCurrentIndex((int)fw->attachPolicy()); displayCoordinates(app->d_frame_geometry_unit); } else { unitBox->setCurrentIndex(FrameWidget::Pixel); displayCoordinates(FrameWidget::Pixel); } if (d_widget_type == Text){ LegendWidget *l = qobject_cast<LegendWidget *>(d_widget); if (l){ setText(textEditBox, l->text()); textFont = l->font(); QFont fnt = textFont; fnt.setPointSize(QFont().pointSize() + 2); textEditBox->setFont(fnt); textColorBtn->blockSignals(true); textColorBtn->setColor(l->textColor()); textColorBtn->blockSignals(false); QColor bc = l->backgroundColor(); boxBackgroundTransparency->blockSignals(true); boxBackgroundTransparency->setValue(bc.alpha()); boxBackgroundTransparency->blockSignals(false); textBackgroundBtn->blockSignals(true); textBackgroundBtn->setEnabled(bc.alpha()); textBackgroundBtn->setColor(bc); textBackgroundBtn->blockSignals(false); boxTextAngle->blockSignals(true); boxTextAngle->setValue(l->angle()); boxTextAngle->blockSignals(false); autoUpdateTextBox->setChecked(l->isAutoUpdateEnabled()); texOutputBox->setChecked(l->hasTeXOutput()); } } else if (d_widget_type == Tex){ TexWidget *tw = qobject_cast<TexWidget *>(d_widget); if (tw){ setText(equationEditor, tw->formula()); outputLabel->setPixmap(tw->pixmap()); bestSizeButton->show(); } return; } else if (d_widget_type == Image){ ImageWidget *i = qobject_cast<ImageWidget *>(d_widget); if (i){ imagePathBox->setText(i->fileName()); boxSaveImagesInternally->blockSignals(true); boxSaveImagesInternally->setChecked(i->saveInternally()); boxSaveImagesInternally->blockSignals(false); } } else if (d_widget_type == Frame){ RectangleWidget *r = qobject_cast<RectangleWidget *>(d_widget); if (r){ backgroundColorBtn->blockSignals(true); backgroundColorBtn->setColor(r->backgroundColor()); backgroundColorBtn->blockSignals(false); boxTransparency->blockSignals(true); boxTransparency->setValue(r->backgroundColor().alpha()); boxTransparency->blockSignals(false); patternBox->blockSignals(true); patternBox->setPattern(r->brush().style()); patternBox->blockSignals(false); patternColorBtn->blockSignals(true); patternColorBtn->setColor(r->brush().color()); patternColorBtn->blockSignals(false); } } else if (d_widget_type == Ellipse){ EllipseWidget *r = qobject_cast<EllipseWidget *>(d_widget); if (r){ backgroundColorBtn->blockSignals(true); backgroundColorBtn->setColor(r->backgroundColor()); backgroundColorBtn->blockSignals(false); boxTransparency->blockSignals(true); boxTransparency->setValue(r->backgroundColor().alpha()); boxTransparency->blockSignals(false); patternBox->blockSignals(true); patternBox->setPattern(r->brush().style()); patternBox->blockSignals(false); patternColorBtn->blockSignals(true); patternColorBtn->setColor(r->brush().color()); patternColorBtn->blockSignals(false); } } }
MainWindow::MainWindow( QWidget* parent ) : QWidget( parent ) { setupUi( this ); QHBoxLayout* chartLayout = new QHBoxLayout( chartFrame ); #ifdef USE_FRAME_WIDGET FrameWidget* chartFrameWidget = new FrameWidget(); chartLayout->addWidget( chartFrameWidget ); #endif hSBar->setVisible( false ); vSBar->setVisible( false ); m_model.loadFromCSV( ":/empty" ); // Set up the diagram m_lines = new LineDiagram(); m_lines->setModel( &m_model ); CartesianAxis *xAxis = new CartesianAxis( m_lines ); CartesianAxis *yAxis = new CartesianAxis ( m_lines ); CartesianAxis *axisTop = new CartesianAxis ( m_lines ); CartesianAxis *axisRight = new CartesianAxis ( m_lines ); xAxis->setPosition ( KChart::CartesianAxis::Bottom ); yAxis->setPosition ( KChart::CartesianAxis::Left ); axisTop->setPosition( KChart::CartesianAxis::Top ); axisRight->setPosition( KChart::CartesianAxis::Right ); m_lines->addAxis( xAxis ); m_lines->addAxis( yAxis ); m_lines->addAxis( axisTop ); m_lines->addAxis( axisRight ); m_chart = new Chart(); //m_chart->setGlobalLeading(10,10,10,10); // by default there is no leading #ifdef USE_FRAME_WIDGET chartFrameWidget->setChart( m_chart ); // make sure, we re-draw after changing one of the chart's properties connect( m_chart, SIGNAL( propertiesChanged() ), chartFrameWidget, SLOT( update() ) ) ; #else chartLayout->addWidget( m_chart ); #endif m_chart->coordinatePlane()->replaceDiagram( m_lines ); for ( int iColumn = 0; iColumn<m_lines->model()->columnCount(); ++iColumn ) { QPen pen(m_lines->pen( iColumn )); pen.setWidth(4); m_lines->setPen( iColumn, pen ); } FrameAttributes faChart( m_chart->frameAttributes() ); faChart.setVisible( true ); faChart.setPen( QPen(QColor(0x60,0x60,0xb0), 8) ); m_chart->setFrameAttributes( faChart ); BackgroundAttributes baChart( m_chart->backgroundAttributes() ); baChart.setVisible( true ); baChart.setBrush( QColor(0xd0,0xd0,0xff) ); m_chart->setBackgroundAttributes( baChart ); // Set up the legend m_legend = new Legend( m_lines, m_chart ); m_legend->setPosition( Position::South ); m_legend->setAlignment( Qt::AlignRight ); m_legend->setShowLines( false ); m_legend->setTitleText( tr( "Legend" ) ); m_legend->setOrientation( Qt::Horizontal ); // setting the legend frame and background to the same color: const QColor legendColor(0xff,0xe0,0x80); FrameAttributes faLegend( m_legend->frameAttributes() ); faLegend.setVisible( true ); faLegend.setPen( QPen(legendColor, 1) ); m_legend->setFrameAttributes( faLegend ); BackgroundAttributes baLegend( m_legend->backgroundAttributes() ); baLegend.setVisible( true ); baLegend.setBrush( legendColor ); m_legend->setBackgroundAttributes( baLegend ); m_chart->addLegend( m_legend ); // for illustration we paint the same chart at different sizes: QSize size1 = QSize( 200, 200 ); QSize size2 = QSize( 800, 800 ); m_pix1 = drawIntoPixmap( size1, m_chart ); m_pix2 = drawIntoPixmap( size2, m_chart ); m_pix2 = m_pix2.scaled( size1 ); m_smallChart1 = new QLabel( this ); m_smallChart1->setWindowTitle( "200x200" ); m_smallChart1->setPixmap( m_pix1 ); m_smallChart1->setFixedSize( m_pix1.size() ); m_smallChart1->move( width() - m_pix1.width()*2, height()/2 - m_pix1.height()-5 ); m_smallChart1->show(); m_smallChart2 = new QLabel( this ); m_smallChart2->setWindowTitle( "800x800 scaled down" ); m_smallChart2->setPixmap( m_pix2 ); m_smallChart2->setFixedSize( m_pix2.size() ); m_smallChart2->move( width() - m_pix2.width()*2, height()/2 + 5 ); m_smallChart2->show(); faChart.setPen( QPen(QColor(0xb0,0xb0,0xff), 8) ); m_chart->setFrameAttributes( faChart ); // initialize attributes; this is necessary because we need to enable data value attributes before // any of them (e.g. only markers) can be displayed. but if we enable data value attributs, a default // data value text is included, even if we only wanted to set markers. so we enable DVA and then // individually disable the parts we don't want. on_paintValuesCB_toggled( false ); on_paintMarkersCB_toggled( false ); }