SourcePortItem::SourcePortItem(QString itemName, bool isInApp, bool editOnStart, Application *app, BuilderItem *parent) : BuilderItem(parent) { itemType = SourcePortItemType; this->itemName = itemName; portAvailable = false; errorState = false; sigHandler = new ItemSignalHandler((QGraphicsItem*)this,SourcePortItemType,nullptr); pressed = false; moved = false; this->nestedInApp = isInApp; this->parent = parent; this->app = app; QFontMetrics fontMetric(font); int textWidth = fontMetric.width(itemName); prepareGeometryChange(); mainRect = QRectF(-((2*PORT_TEXT_WIDTH) + textWidth)/2,-16,(2*PORT_TEXT_WIDTH) + textWidth,32); boundingR = QRectF(mainRect); setToolTip(itemName); setFlag(ItemIsMovable,!isInApp); setFlag(ItemIsSelectable,true); setFlag(ItemSendsGeometryChanges,true); if(!isInApp){ QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect(); effect->setColor(QColor(80,80,80,80)); effect->setBlurRadius(5); setGraphicsEffect(effect); } allowInputs = false; allowOutputs = true; lineEditWidget = new QGraphicsProxyWidget(this); QLineEdit *lineEdit = new QLineEdit(); QObject::connect(lineEdit,SIGNAL(editingFinished()),signalHandler(),SLOT(onEditingFinished())); QObject::connect(lineEdit,SIGNAL(returnPressed()),signalHandler(),SLOT(onEditingFinished())); lineEdit->setText(itemName); lineEditWidget->setWidget(lineEdit); if(editOnStart){ lineEditWidget->setVisible(true); }else{ lineEditWidget->setVisible(false); } QRectF geo = lineEditWidget->geometry(); geo.setWidth(textWidth); lineEditWidget->setGeometry(geo); lineEditWidget->setPos(-textWidth/2,-lineEditWidget->geometry().height()/2); }
void EntitiesTreeWidget::mouseMoveEvent(QMouseEvent *event) { if(selectedItems().count() <= 0){ return; } QTreeWidgetItem *selectedItem = selectedItems().at(0); if (selectedItem ){ if(!selectedItem->data(0,Qt::UserRole).isValid()){ QTreeWidget::mousePressEvent(event); return; } qlonglong pointer = selectedItem->data(0,Qt::UserRole + 1).toLongLong(); QMimeData *mimeData = new QMimeData; QByteArray strPointer = QString("%1").arg(pointer).toLatin1(); mimeData->setData("pointer",strPointer); if(selectedItem->data(0,Qt::UserRole).toInt() == (int)yarp::manager::MODULE){ mimeData->setText("module"); } if(selectedItem->data(0,Qt::UserRole).toInt() == (int)yarp::manager::APPLICATION){ mimeData->setText("application"); } QFontMetrics fontMetric(font()); int textWidth = fontMetric.width(selectedItem->text(0)); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); // QPixmap pix(textWidth + 40,18); // QPainter painter(&pix); // QPen pen(QBrush(QColor((Qt::blue))),1); // painter.setPen(pen); // painter.fillRect(0,0,textWidth + 40,18,QBrush(QColor((Qt::lightGray)))); // painter.drawRect(0,0,textWidth- + 39,17); // painter.drawImage(QRectF(1,1,16,16),QImage(":/module22.svg")); // painter.drawText(QRectF(16,1,textWidth + 20,16),Qt::AlignCenter,selectedItem->text(0)); // //pix.fill(QColor(Qt::red)); // drag->setPixmap(pix); drag->exec(Qt::CopyAction); } QTreeWidget::mouseMoveEvent(event); }
SGMPluginsLocationView::SGMPluginsLocationView(QWidget *parent) : QGroupBox("Plugin Locations", parent) { unsavedChanges_ = false; AMDatabase *dbSGM = AMDatabase::database("SGMBeamline"); SGMPluginsLocation *tempFileLoaderLocation = new SGMPluginsLocation(); QList<int> matchIDs = dbSGM->objectsMatching(AMDbObjectSupport::s()->tableNameForClass<SGMPluginsLocation>(), "name", "FileLoaders"); if(matchIDs.count() > 0) tempFileLoaderLocation->loadFromDb(dbSGM, matchIDs.at(0)); SGMPluginsLocation *tempAnalysisBlockLocation = new SGMPluginsLocation(); matchIDs = dbSGM->objectsMatching(AMDbObjectSupport::s()->tableNameForClass<SGMPluginsLocation>(), "name", "AnalysisBlocks"); if(matchIDs.count() > 0) tempAnalysisBlockLocation->loadFromDb(dbSGM, matchIDs.at(0)); fileLoaderPluginsFolderLineEdit_ = new QLineEdit(); if(tempFileLoaderLocation) fileLoaderPluginsFolderLineEdit_->setText(tempFileLoaderLocation->pluginFolderPath()); else fileLoaderPluginsFolderLineEdit_->setText("Load Fail"); analysisBlockPluginsFolderLineEdit_ = new QLineEdit(); if(tempAnalysisBlockLocation) analysisBlockPluginsFolderLineEdit_->setText(tempAnalysisBlockLocation->pluginFolderPath()); else analysisBlockPluginsFolderLineEdit_->setText("Load Fail"); connect(fileLoaderPluginsFolderLineEdit_, SIGNAL(textEdited(QString)), this, SLOT(onLineEditsChanged())); connect(analysisBlockPluginsFolderLineEdit_, SIGNAL(textEdited(QString)), this, SLOT(onLineEditsChanged())); fl_ = new QFormLayout(); fl_->addRow("File Loaders Folder", fileLoaderPluginsFolderLineEdit_); fl_->addRow("Analysis Blocks Folder", analysisBlockPluginsFolderLineEdit_); int maxFontWidth = 0; QFontMetrics fontMetric(fileLoaderPluginsFolderLineEdit_->font()); for(int x = 0; x < fl_->rowCount(); x++){ QLineEdit *lineEdit = qobject_cast<QLineEdit*>(fl_->itemAt(x, QFormLayout::FieldRole)->widget()); if(lineEdit && (fontMetric.width(lineEdit->text()) > maxFontWidth)) maxFontWidth = fontMetric.width(lineEdit->text()); } if(maxFontWidth > 400) maxFontWidth = 400; for(int x = 0; x < fl_->rowCount(); x++) fl_->itemAt(x, QFormLayout::FieldRole)->widget()->setMinimumWidth(maxFontWidth); setLayout(fl_); }
MultilineTextEdit::MultilineTextEdit(QWidget *parent) : QPlainTextEdit(parent), minLineCount_(2), maxLineCount_(10), showContextMenu_(false) { QFontMetrics fontMetric(font()); lineHeight_ = fontMetric.lineSpacing(); // enable focus switch by tab (leaving the editor and committing the changes) setTabChangesFocus(true); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); #if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)) // need to enable the scrollbar for adjusting to its contents setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); #endif // make the text edit show at least n lines of text setMinimumHeight(minLineCount_ * lineHeight_); setMaximumHeight(maxLineCount_ * lineHeight_); }
void SourcePortItem::editingFinished() { QString text = ((QLineEdit*)lineEditWidget->widget())->text(); for (int i=0;i<scene()->items().count();i++){ QGraphicsItem *it = scene()->items().at(i); if((it->type() == QGraphicsItem::UserType + DestinationPortItemType || it->type() == QGraphicsItem::UserType + SourcePortItemType) && (it != this)){ if(((SourcePortItem*)it)->getItemName() == text){ ((QLineEdit*)lineEditWidget->widget())->setStyleSheet("QLineEdit { background-color: red;}"); ((QLineEdit*)lineEditWidget->widget())->setToolTip(tr("Duplicate Entry")); allowOutputs = false; errorState = true; return; } } } errorState = false; allowOutputs = true; ((QLineEdit*)lineEditWidget->widget())->setStyleSheet("QLineEdit {background-color: white;}"); ((QLineEdit*)lineEditWidget->widget())->setToolTip(""); this->itemName = text; lineEditWidget->setVisible(false); QFontMetrics fontMetric(font); int textWidth = fontMetric.width(itemName); prepareGeometryChange(); mainRect = QRectF(-((2*PORT_TEXT_WIDTH) + textWidth)/2,-15,(2*PORT_TEXT_WIDTH) + textWidth,30); boundingR = QRectF(mainRect); setToolTip(itemName); QRectF geo = lineEditWidget->geometry(); geo.setWidth(textWidth); lineEditWidget->setGeometry(geo); lineEditWidget->setPos(-textWidth/2,-lineEditWidget->geometry().height()/2); emit signalHandler()->modified(); update(); updateConnections(); updateConnectionsFrom(this->itemName); }
void Arrow::setConnection(Connection conn) { connection = conn; QString label = conn.carrier(); if(!label.isEmpty()){ textLbl.setText(label); } QFontMetrics fontMetric(font); textWidth = fontMetric.width(label); GraphicModel mod = connection.getModelBase(); if(mod.points.size() > 0){ GyPoint p = mod.points[0]; if(p.x >= 0 && p.y >= 0){ textLbl.setHasMoved(true); textLbl.setPos(p.x,p.y); } if(mod.points.size() > 3){ // Handles startP = mapFromItem(myStartItem,myStartItem->connectionPoint()); endP = mapFromItem(myEndItem,myEndItem->connectionPoint()); polyline.clear(); polyline.prepend(startP); for(unsigned int i=2; i<mod.points.size() - 1;i++){ GyPoint p = mod.points[i]; QPointF point(p.x,p.y); LineHandle *handle = new LineHandle(point,this); handleList.append(handle); polyline.append(point); qDebug() << "APPENDING " << handle; } polyline.append(endP); boundingPolyline = polyline; } } update(); }
GcScopeBar::GcScopeBar(Context *context, QWidget *traintool) : QWidget(context->mainWindow), context(context) { setFixedHeight(23); setContentsMargins(10,0,10,0); layout = new QHBoxLayout(this); layout->setSpacing(2); layout->setContentsMargins(0,0,0,0); searchLabel = new GcLabel(tr("Search/Filter:")); searchLabel->setYOff(1); searchLabel->setFixedHeight(20); searchLabel->setHighlighted(true); QFont font; #ifdef Q_OS_MAC font.setFamily("Lucida Grande"); #else font.setFamily("Helvetica"); #endif #ifdef WIN32 font.setPointSize(8); #else font.setPointSize(10); #endif font.setWeight(QFont::Black); searchLabel->setFont(font); layout->addWidget(searchLabel); searchLabel->hide(); #ifdef GC_HAVE_LUCENE connect(context->mainWindow, SIGNAL(filterChanged(QStringList&)), this, SLOT(setHighlighted())); #endif // Mac uses QtMacButton - recessed etc #ifdef Q_OS_MAC home = new QtMacButton(this, QtMacButton::Recessed); #ifdef GC_HAVE_ICAL diary = new QtMacButton(this, QtMacButton::Recessed); #endif anal = new QtMacButton(this, QtMacButton::Recessed); train = new QtMacButton(this, QtMacButton::Recessed); #else // Windows / Linux uses GcScopeButton - pushbutton home = new GcScopeButton(this); #ifdef GC_HAVE_ICAL diary = new GcScopeButton(this); #endif anal = new GcScopeButton(this); train = new GcScopeButton(this); #endif // now set the text for each one home->setText(tr("Home")); layout->addWidget(home); connect(home, SIGNAL(clicked(bool)), this, SLOT(clickedHome())); #ifdef GC_HAVE_ICAL diary->setText(tr("Diary")); layout->addWidget(diary); connect(diary, SIGNAL(clicked(bool)), this, SLOT(clickedDiary())); #endif anal->setText(tr("Analysis")); anal->setWidth(70); anal->setChecked(true); layout->addWidget(anal); connect(anal, SIGNAL(clicked(bool)), this, SLOT(clickedAnal())); train->setText(tr("Train")); layout->addWidget(train); connect(train, SIGNAL(clicked(bool)), this, SLOT(clickedTrain())); layout->addStretch(); layout->addWidget(traintool); layout->addStretch(); // we now need to adjust the buttons according to their text size // this is particularly bad for German's who, as a nation, must // suffer from RSI from typing and writing more than any other nation ;) QFontMetrics fontMetric(font); int width = fontMetric.width(tr("Home")); home->setWidth(width+20); width = fontMetric.width(tr("Analysis")); anal->setWidth(width+20); width = fontMetric.width(tr("Train")); train->setWidth(width+20); #ifdef GC_HAVE_ICAL width = fontMetric.width(tr("Diary")); diary->setWidth(width+20); #endif }
void SaagharItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { // if (parent()->objectName()=="searchTable") // { // qDebug() << keywordList; // } bool flagRightToLeft = true; if (parentWidget) { flagRightToLeft = parentWidget->layoutDirection() == Qt::RightToLeft; } int textHMargin = 0; if (tableStyle) { textHMargin = tableStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, &option) + 1 ; } QBrush itemBrush = painter->brush(); itemBrush.setColor(SaagharWidget::matchedTextColor); itemBrush.setStyle(Qt::SolidPattern); QString text = ""; QString cleanedText = ""; int lastX, x; QFontMetrics fontMetric(index.data(Qt::FontRole).value<QFont>()); const QString tatweel = QString(0x0640); int iconWidth = 0; if (index.data().isValid()) { text = index.data().toString(); if (index.data(Qt::DecorationRole).isValid()) { QIcon icon = index.data(Qt::DecorationRole).value<QIcon>(); iconWidth = icon.pixmap(100, 100).width() + 5; } cleanedText = QGanjoorDbBrowser::cleanString(text); // if (text.contains( QString::fromLocal8Bit( // "پسر چون ز مادر بران گونه زاد" //// "پرپر شد ..." // /*"وَز ســوری و نــعــمـان وزد، هـر دم شـمـیـم عـنـبـریـن"*/))) // { // qDebug() << "textt="<<text; // qDebug() << "clean="<<cleanedText; // } text = QGanjoorDbBrowser::cleanString(text, QStringList() << " " << QGanjoorDbBrowser::someSymbols); } //qDebug() << "text="<<index.data().toString()<<"W="<<fontMetric.width(index.data().toString())<<"cleanedText="<<cleanedText<<"W="<<fontMetric.width(cleanedText); Qt::Alignment itemAlignment = 0; QVariant alignValue = index.data(Qt::TextAlignmentRole); if (alignValue.isValid() && !alignValue.isNull()) { itemAlignment = Qt::Alignment(alignValue.toInt()); } int keywordsCount = keywordList.size(); for (int i = 0; i < keywordsCount; ++i) { lastX = x = option.rect.x() + textHMargin; //QString keyword = keywordList.isEmpty() ? "" : keywordList.at(0); QString keyword = keywordList.at(i); keyword.replace(QChar(0x200C), "", Qt::CaseInsensitive);//replace ZWNJ by "" //qDebug() << "keyword1="<<keyword; keyword = keyword.split("", QString::SkipEmptyParts).join(tatweel + "*"); //qDebug() << "keyword2="<<keyword; keyword.replace("@" + tatweel + "*", "\\S*", Qt::CaseInsensitive); //replace wildcard by word chars //qDebug() << "keyword3="<<keyword; QRegExp maybeTatweel(keyword, Qt::CaseInsensitive); maybeTatweel.indexIn(text); //qDebug() << text<<"count=" << maybeTatweel.captureCount()<<maybeTatweel.capturedTexts(); //qDebug() << "Match: "<<maybeTatweel.cap(0); keyword = maybeTatweel.cap(0); if (!(keyword.isEmpty() || text.indexOf(keyword) == -1)) { QString txt = text; while (txt.size() > 0) { int index = txt.indexOf(keyword); QString thisPart; if (index == -1) { thisPart = txt; txt = QString(); } else { if (index == 0) { thisPart = txt.mid(0, keyword.size()); if (txt == keyword) { txt = QString(); } else { txt = txt.mid(keyword.size(), txt.size() - keyword.size()); } } else { thisPart = txt.mid(0, index); txt = txt.mid(index); } } QSize sz = fontMetric.boundingRect(thisPart).size(); if (index == 0) { if (flagRightToLeft) { switch (itemAlignment ^ Qt::AlignVCenter) { case Qt::AlignRight: lastX = option.rect.left() + textHMargin + fontMetric.boundingRect(text).width() - (lastX - option.rect.x() + sz.width() - textHMargin); break; case Qt::AlignHCenter: lastX = option.rect.left() + textHMargin + fontMetric.boundingRect(text).width() - (lastX - option.rect.x() + sz.width() - textHMargin) + ((option.rect.width() - fontMetric.boundingRect(text).width() - textHMargin) / 2); break; case Qt::AlignLeft: default: lastX = option.rect.right() + textHMargin - 1 - (lastX - option.rect.x() + sz.width()); break; } } else { if ((itemAlignment ^ Qt::AlignVCenter) == Qt::AlignHCenter) { lastX = option.rect.left() + textHMargin + fontMetric.boundingRect(text).width() - (lastX - option.rect.x() + sz.width() - textHMargin) + ((option.rect.width() - fontMetric.boundingRect(text).width() - textHMargin) / 2); } } QRect rectf(lastX , option.rect.y() + ((option.rect.height() - qMin(option.rect.height(), fontMetric.height())) / 2), sz.width(), fontMetric.height()); if (!flagRightToLeft && ((itemAlignment ^ Qt::AlignVCenter) == Qt::AlignHCenter)) { rectf = QStyle::visualRect(Qt::RightToLeft, option.rect, rectf); } qreal oldOpacity = painter->opacity(); painter->setOpacity(opacity); rectf.adjust(-iconWidth, 0, -iconWidth, 0); QPainterPath roundedRect; roundedRect.addRoundRect(rectf, 50, 50); QPen defaultPen(painter->pen()); painter->setPen(SaagharWidget::matchedTextColor.darker(150)); painter->drawPath(roundedRect); painter->fillPath(roundedRect, itemBrush); painter->setOpacity(oldOpacity); painter->setPen(defaultPen); //painter->fillRect( rectf, itemBrush ); } x += fontMetric.width(thisPart); lastX = x; } } else if (!(keyword.isEmpty() || cleanedText.indexOf(keyword) == -1)) { qreal oldOpacity = painter->opacity(); painter->setOpacity(0.35); painter->fillRect(option.rect, itemBrush); painter->setOpacity(oldOpacity); //painter->fillRect( rectf, itemBrush ); } } QItemDelegate::paint(painter, option, index); }
void MAutocompleteWidget::addText(const QString &text) { insertHtml(text); QFontMetrics fontMetric(currentFont()); int height = fontMetric.height()*(toPlainText().count("\n")+3); setMaximumHeight(height); }
GcScopeBar::GcScopeBar(Context *context) : QWidget(context->mainWindow), context(context) { setFixedHeight(23); setContentsMargins(10,0,10,0); layout = new QHBoxLayout(this); layout->setSpacing(2); layout->setContentsMargins(0,0,0,0); searchLabel = new GcLabel(tr("Search/Filter:")); searchLabel->setYOff(1); searchLabel->setFixedHeight(20); searchLabel->setHighlighted(true); QFont font; font.setPointSize(10); font.setWeight(QFont::Black); searchLabel->setFont(font); layout->addWidget(searchLabel); searchLabel->hide(); connect(context, SIGNAL(filterChanged()), this, SLOT(setHighlighted())); connect(context, SIGNAL(compareIntervalsStateChanged(bool)), this, SLOT(setCompare())); connect(context, SIGNAL(compareDateRangesStateChanged(bool)), this, SLOT(setCompare())); // Mac uses QtMacButton - recessed etc #ifdef Q_OS_MAC home = new QtMacButton(this, QtMacButton::Recessed); #ifdef GC_HAVE_ICAL diary = new QtMacButton(this, QtMacButton::Recessed); #endif anal = new QtMacButton(this, QtMacButton::Recessed); train = new QtMacButton(this, QtMacButton::Recessed); #else // Windows / Linux uses GcScopeButton - pushbutton home = new GcScopeButton(this); #ifdef GC_HAVE_ICAL diary = new GcScopeButton(this); #endif anal = new GcScopeButton(this); train = new GcScopeButton(this); #endif // now set the text for each one home->setText(tr("Trends")); layout->addWidget(home); connect(home, SIGNAL(clicked(bool)), this, SLOT(clickedHome())); HelpWhatsThis *helpHome = new HelpWhatsThis(home); home->setWhatsThis(helpHome->getWhatsThisText(HelpWhatsThis::ScopeBar_Trends)); #ifdef GC_HAVE_ICAL diary->setText(tr("Diary")); layout->addWidget(diary); connect(diary, SIGNAL(clicked(bool)), this, SLOT(clickedDiary())); HelpWhatsThis *helpDiary = new HelpWhatsThis(diary); diary->setWhatsThis(helpDiary->getWhatsThisText(HelpWhatsThis::ScopeBar_Diary)); #endif anal->setText(tr("Activities")); anal->setWidth(70); anal->setChecked(true); layout->addWidget(anal); connect(anal, SIGNAL(clicked(bool)), this, SLOT(clickedAnal())); HelpWhatsThis *helpAnal = new HelpWhatsThis(anal); anal->setWhatsThis(helpAnal->getWhatsThisText(HelpWhatsThis::ScopeBar_Rides)); train->setText(tr("Train")); layout->addWidget(train); connect(train, SIGNAL(clicked(bool)), this, SLOT(clickedTrain())); HelpWhatsThis *helpTrain = new HelpWhatsThis(train); train->setWhatsThis(helpTrain->getWhatsThisText(HelpWhatsThis::ScopeBar_Train)); //layout->addWidget(traintool); //XXX!!! eek // we now need to adjust the buttons according to their text size // this is particularly bad for German's who, as a nation, must // suffer from RSI from typing and writing more than any other nation ;) QFontMetrics fontMetric(font); int width = fontMetric.width(tr("Trends")); home->setWidth(width+30); width = fontMetric.width(tr("Activities")); anal->setWidth(width+30); width = fontMetric.width(tr("Train")); train->setWidth(width+30); #ifdef GC_HAVE_ICAL width = fontMetric.width(tr("Diary")); diary->setWidth(width+30); #endif }