MyWidget::MyWidget(QWidget *parent) : QWidget(parent) { // QPushButton *quit = new QPushButton(tr("Quit")); QToolButton *quit = new QToolButton(); quit->setText(tr("Quit")); quit->setFont(QFont("Times", 18, QFont::Bold)); quit->setMinimumSize(150, 50); QLCDNumber *lcd = new QLCDNumber(2); lcd->setSegmentStyle(QLCDNumber::Filled); lcd->setMinimumSize(150, 150); QSlider *slider = new QSlider(Qt::Horizontal); slider->setRange(0, 99); slider->setValue(0); connect(quit, SIGNAL(clicked()), qApp, SLOT(quit())); connect(slider, SIGNAL(valueChanged(int)), lcd, SLOT(display(int))); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(lcd); layout->addWidget(slider); layout->addWidget(quit); setLayout(layout); }
foreach (QAction* action, actions) { QToolButton* button = new QToolButton; QFont font = button->font(); font.setPixelSize(14); button->setFont(font); button->setText(action->text()); d->m_flow_layout->addWidget(button); QObject::connect(button, SIGNAL(clicked()), action, SLOT(trigger())); }
void FeatureTreeWidget::assignColorFromSMVTreeWidget(QString featureName) { QTreeWidgetItem *item = getItemFromFeatureName(featureName); if (item!=0) { if (item->childCount()==0){ mainWindow->questionDialog->writeToLog("assignColor<1>"); Feature *f = getCorrespondingFeature(featureName); Color *c = static_cast<MyListWidgetItem*>(listWidget->selectedItems().at(0))->getBGColor(); if (item->backgroundColor(0).isValid()) mainWindow->removeColorAssignment(static_cast<MyTreeWidgetItem*>(item)); colorManager->setColorForFeature(f,c); //X zum Abwählen der Farbe setzen if (itemWidget(item, 1)) itemWidget(item, 1)->show(); else{ QToolButton *deleteButton = new QToolButton(this); deleteButton->setFont(QFont(QString("MS Shell Dlg 2"),9,10,false)); //deleteButton->setFixedSize(15,18); deleteButton->setFixedWidth(16); QIcon icon = QIcon(); icon.addPixmap(QPixmap(QString(":/images/cross.png")),QIcon::Normal,QIcon::On); deleteButton->setIcon(icon); deleteButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); setItemWidget(item,1,deleteButton); connect(deleteButton,SIGNAL(clicked()),this,SLOT(removeColorAssignment())); } //aktualisiere SmvTreeWidget und TextEdit mainWindow->updateSMVTreeTexture(f); redrawListWidget(); //wenn Farbe schon in FeatureTreeWidget vorhanden, setze diese auf weiß/transparent QList <QTreeWidgetItem*> *treeList = new QList <QTreeWidgetItem*>(); findBackGroundColor(c->color,root,treeList); if (treeList->isEmpty()==false) { for (int i = 0;i < treeList->size();i++){ static_cast<MyTreeWidgetItem*>(treeList->at(i))->setBackgroundInvalid(); // treeList->at(i)->background(0).setStyle(Qt::NoBrush); // treeList->at(i)->setBackgroundColor(0,QColor(0,0,0,0)); colorManager->deleteColorForFeature(getCorrespondingFeature(treeList->at(i)->text(0))); } } //setze Farbe im FeatureTreeWidget static_cast<MyTreeWidgetItem*>(item)->setBGColor(c); //item->setBackgroundColor(0,selected->color); } } }
void ItemsWidget::createItems(int categoryId) { // Remove pervious buttons from grid layout this->removeItems(); // Get all items QList<Model::Item> items = Services::Item::getByCategoryId(categoryId); int i=0, col = 0, row = 1; for(QList<Model::Item>::iterator p = items.begin(); p != items.end(); ++p ) { QToolButton* button = new QToolButton; button->setObjectName(QString("%1_itemButton").arg(p->id())); button->setText((Settings::Language::getCurrentLanguage() == Settings::Language::Arabic) ? p->arabicName() : p->englishName()); if ( Settings::Language::getCurrentLanguage() == Settings::Language::English ) { if ( p->id() == 2 || p->id() == 29) button->setFont(QFont("Hacen Liner Screen Bd", 10, QFont::Normal)); else button->setFont(QFont("Hacen Liner Screen Bd", 13, QFont::Normal)); } else button->setFont(QFont("Hacen Liner Screen Bd", 13, QFont::Normal)); button->setIconSize(QSize(128,128)); //button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); button->setToolTip(button->text()); button->setStatusTip(button->text()); connect(button, SIGNAL(clicked()), signalMapper, SLOT(map())); this->signalMapper->setMapping(button, p->id()); layout->addWidget(button, row, col); col++; i++; if ( col % ButtonsPerLine == 0) { row++; col = 0; } } }
foreach (MVAbstractViewFactory* f, factories) { QToolButton* button = new QToolButton; QFont font = button->font(); font.setPixelSize(14); button->setFont(font); button->setText(f->name()); button->setProperty("action_name", f->id()); d->m_flow_layout->addWidget(button); d->m_viewMapper->setMapping(button, f); QObject::connect(button, SIGNAL(clicked()), d->m_viewMapper, SLOT(map())); //QObject::connect(f, SIGNAL(enabledChanged(bool)), button, SLOT(setEnabled(bool))); d->m_buttons[f->name()] = button; }
void FindWidget::constructUI() { QHBoxLayout* layout = new QHBoxLayout();// QBoxLayout::LeftToRight ); layout->setMargin(7); setLayout( layout ); QToolButton* toggleButton = new QToolButton(this); toggleButton->setFont( edbeeApp()->iconFont() ); toggleButton->setText( QChar(icon_repeat) ); toggleButton->setToolTip(tr("Wrap Around")); toggleButton->setCheckable(true); layout->addWidget( toggleButton, 0 ); toggleButton = new QToolButton(this); toggleButton->setFont( edbeeApp()->iconFont() ); toggleButton->setText( QChar(icon_asterisk) ); toggleButton->setToolTip(tr("Regular Expressions")); toggleButton->setCheckable(true); layout->addWidget( toggleButton, 0 ); toggleButton = new QToolButton(this); toggleButton->setFont( edbeeApp()->iconFont() ); toggleButton->setText( QChar(icon_font) ); toggleButton->setToolTip(tr("Case Sensitive")); toggleButton->setCheckable(true); layout->addWidget( toggleButton, 0 ); QLabel* label = new QLabel( tr("Find") ); layout->addWidget( label, 0, Qt::AlignLeft ); lineEditRef_ = new QLineEdit(this); // lineEditRef_->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred); // lineEditRef_->setSizePolicy( QSizePolicy::M); // lineEditRef_->setMaximumWidth( 10000 ); layout->addWidget( lineEditRef_, 1);//, Qt::AlignLeft); // layout->insertStretch(1); // add the action QToolButton* but = new QToolButton( this ); but->setFont( edbeeApp()->iconFont() ); but->setText( QChar(icon_caret_left) ); //< but->setShortcut( editorRef_->controller()->keyMap()->getSequence("find_prev_match") ); but->setToolTip( QString(tr("Find Previous (%1)")).arg(but->shortcut().toString()) ); connect( but, SIGNAL(clicked()), SLOT(findPrevWord()) ); layout->addWidget( but, 0 ); but = new QToolButton( this ); but->setFont( edbeeApp()->iconFont() ); but->setText( QChar(icon_caret_right) ); // > but->setShortcut( editorRef_->controller()->keyMap()->getSequence("find_next_match") ); but->setToolTip( QString(tr("Find Next (%1)")).arg(but->shortcut().toString()) ); connect( but, SIGNAL(clicked()), SLOT(findNextWord()) ); layout->addWidget( but, 0 ); but = new QToolButton( this ); but->setFont( edbeeApp()->iconFont() ); but->setText( QChar(icon_th) ); // > but->setShortcut( editorRef_->controller()->keyMap()->getSequence("sel_all_matches") ); but->setToolTip( QString(tr("Select All (%1)")).arg(but->shortcut().toString()) ); connect( but, SIGNAL(clicked()), SLOT(selectAllWords()) ); layout->addWidget( but, 0 ); // setWindowFlags( Qt::Popup ); }
void QmitkToolSelectionBox::RecreateButtons() { if (m_ToolManager.IsNull()) return; /* // remove all buttons that are there QObjectList *l = Q3ButtonGroup::queryList( "QButton" ); QObjectListIt it( *l ); // iterate over all buttons QObject *obj; while ( (obj = it.current()) != 0 ) { ++it; QButton* button = dynamic_cast<QButton*>(obj); if (button) { Q3ButtonGroup::remove(button); delete button; } } delete l; // delete the list, not the objects */ // mmueller Qt impl QList<QAbstractButton *> l = m_ToolButtonGroup->buttons(); // remove all buttons that are there QList<QAbstractButton *>::iterator it; QAbstractButton * btn; for(it=l.begin(); it!=l.end();++it) { btn = *it; m_ToolButtonGroup->removeButton(btn); //this->removeChild(btn); delete btn; } // end mmueller Qt impl mitk::ToolManager::ToolVectorTypeConst allPossibleTools = m_ToolManager->GetTools(); mitk::ToolManager::ToolVectorTypeConst allTools; typedef std::pair< std::string::size_type, const mitk::Tool* > SortPairType; typedef std::priority_queue< SortPairType > SortedToolQueueType; SortedToolQueueType toolPositions; // clear and sort all tools // step one: find name/group of all tools in m_DisplayedGroups string. remember these positions for all tools. for ( mitk::ToolManager::ToolVectorTypeConst::const_iterator iter = allPossibleTools.begin(); iter != allPossibleTools.end(); ++iter) { const mitk::Tool* tool = *iter; std::string::size_type namePos = m_DisplayedGroups.find( std::string("'") + tool->GetName() + "'" ); std::string::size_type groupPos = m_DisplayedGroups.find( std::string("'") + tool->GetGroup() + "'" ); if ( !m_DisplayedGroups.empty() && namePos == std::string::npos && groupPos == std::string::npos ) continue; // skip if ( m_DisplayedGroups.empty() && std::string(tool->GetName()).length() > 0 ) { namePos = static_cast<std::string::size_type> (tool->GetName()[0]); } SortPairType thisPair = std::make_pair( namePos < groupPos ? namePos : groupPos, *iter ); toolPositions.push( thisPair ); } // step two: sort tools according to previously found positions in m_DisplayedGroups MITK_DEBUG << "Sorting order of tools (lower number --> earlier in button group)"; while ( !toolPositions.empty() ) { SortPairType thisPair = toolPositions.top(); MITK_DEBUG << "Position " << thisPair.first << " : " << thisPair.second->GetName(); allTools.push_back( thisPair.second ); toolPositions.pop(); } std::reverse( allTools.begin(), allTools.end() ); MITK_DEBUG << "Sorted tools:"; for ( mitk::ToolManager::ToolVectorTypeConst::const_iterator iter = allTools.begin(); iter != allTools.end(); ++iter) { MITK_DEBUG << (*iter)->GetName(); } // try to change layout... bad? //Q3GroupBox::setColumnLayout ( m_LayoutColumns, Qt::Horizontal ); // mmueller using gridlayout instead of Q3GroupBox //this->setLayout(0); if(m_ButtonLayout == NULL) m_ButtonLayout = new QGridLayout; /*else delete m_ButtonLayout;*/ int row(0); int column(-1); int currentButtonID(0); m_ButtonIDForToolID.clear(); m_ToolIDForButtonID.clear(); QToolButton* button = 0; MITK_DEBUG << "Creating buttons for tools"; // fill group box with buttons for ( mitk::ToolManager::ToolVectorTypeConst::const_iterator iter = allTools.begin(); iter != allTools.end(); ++iter) { const mitk::Tool* tool = *iter; int currentToolID( m_ToolManager->GetToolID( tool ) ); ++column; // new line if we are at the maximum columns if(column == m_LayoutColumns) { ++row; column = 0; } button = new QToolButton; button->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); // add new button to the group MITK_DEBUG << "Adding button with ID " << currentToolID; m_ToolButtonGroup->addButton(button, currentButtonID); // ... and to the layout MITK_DEBUG << "Adding button in row/column " << row << "/" << column; m_ButtonLayout->addWidget(button, row, column); if (m_LayoutColumns == 1) { //button->setTextPosition( QToolButton::BesideIcon ); // mmueller button->setToolButtonStyle( Qt::ToolButtonTextBesideIcon ); } else { //button->setTextPosition( QToolButton::BelowIcon ); // mmueller button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon ); } //button->setToggleButton( true ); // mmueller button->setCheckable ( true ); if(currentToolID == m_ToolManager->GetActiveToolID()) button->setChecked(true); QString label; if (m_GenerateAccelerators) { label += "&"; } label += tool->GetName(); QString tooltip = tool->GetName(); MITK_DEBUG << tool->GetName() << ", " << label.toLocal8Bit().constData() << ", '" << tooltip.toLocal8Bit().constData(); if ( m_ShowNames ) { /* button->setUsesTextLabel(true); button->setTextLabel( label ); // a label QToolTip::add( button, tooltip ); */ // mmueller Qt button->setText( label ); // a label button->setToolTip( tooltip ); // mmueller QFont currentFont = button->font(); currentFont.setBold(false); button->setFont( currentFont ); } us::ModuleResource iconResource = tool->GetIconResource(); if (!iconResource.IsValid()) { button->setIcon(QIcon(QPixmap(tool->GetXPM()))); } else { us::ModuleResourceStream resourceStream(iconResource, std::ios::binary); resourceStream.seekg(0, std::ios::end); std::ios::pos_type length = resourceStream.tellg(); resourceStream.seekg(0, std::ios::beg); char* data = new char[length]; resourceStream.read(data, length); QPixmap pixmap; pixmap.loadFromData(QByteArray::fromRawData(data, length)); QIcon* icon = new QIcon(pixmap); delete[] data; button->setIcon(*icon); if (m_ShowNames) { if (m_LayoutColumns == 1) button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); else button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); button->setIconSize(QSize(24, 24)); } else { button->setToolButtonStyle(Qt::ToolButtonIconOnly); button->setIconSize(QSize(32,32)); button->setToolTip(tooltip); } } if (m_GenerateAccelerators) { QString firstLetter = QString( tool->GetName() ); firstLetter.truncate( 1 ); button->setShortcut( firstLetter ); // a keyboard shortcut (just the first letter of the given name w/o any CTRL or something) } mitk::DataNode* dataNode = m_ToolManager->GetReferenceData(0); if (dataNode != NULL && !tool->CanHandle(dataNode->GetData())) button->setEnabled(false); m_ButtonIDForToolID[currentToolID] = currentButtonID; m_ToolIDForButtonID[currentButtonID] = currentToolID; MITK_DEBUG << "m_ButtonIDForToolID[" << currentToolID << "] == " << currentButtonID; MITK_DEBUG << "m_ToolIDForButtonID[" << currentButtonID << "] == " << currentToolID; tool->GUIProcessEventsMessage += mitk::MessageDelegate<QmitkToolSelectionBox>( this, &QmitkToolSelectionBox::OnToolGUIProcessEventsMessage ); // will never add a listener twice, so we don't have to check here tool->ErrorMessage += mitk::MessageDelegate1<QmitkToolSelectionBox, std::string>( this, &QmitkToolSelectionBox::OnToolErrorMessage ); // will never add a listener twice, so we don't have to check here tool->GeneralMessage += mitk::MessageDelegate1<QmitkToolSelectionBox, std::string>( this, &QmitkToolSelectionBox::OnGeneralToolMessage ); ++currentButtonID; } // setting grid layout for this groupbox this->setLayout(m_ButtonLayout); //this->update(); }
void FeatureTreeWidget::dropEvent(QDropEvent *event) { //Darstellen des Drag-Bildes QByteArray itemData = event->mimeData()->data("application/x-dnditemdata"); QDataStream dataStream(&itemData, QIODevice::ReadOnly); QPixmap pixmap; QPoint offset; dataStream >> pixmap >> offset; QTreeWidgetItem *item = itemAt(event->pos().x(),event->pos().y()); //wenn auf ein TreeWidgetItem gedropt und dieses ein Blattknoten ist if (item!=0) { if (item->childCount()==0){ mainWindow->questionDialog->writeToLog("assignColor<1>"); Feature *f = getCorrespondingFeature(item->text(0)); //Color *c = new Color (selected->color.convertTo(QColor::Hsv)); Color *c = static_cast<MyListWidgetItem*>(listWidget->selectedItems().at(0))->getBGColor(); if (item->backgroundColor(0).isValid()) mainWindow->removeColorAssignment(static_cast<MyTreeWidgetItem*>(item)); colorManager->setColorForFeature(f,c); //X zum Abwählen der Farbe setzen if (itemWidget(item, 1)) itemWidget(item, 1)->show(); else{ QToolButton *deleteButton = new QToolButton(this); deleteButton->setFont(QFont(QString("MS Shell Dlg 2"),9,10,false)); //deleteButton->setFixedSize(15,18); deleteButton->setFixedWidth(16); QIcon icon = QIcon(); icon.addPixmap(QPixmap(QString(":/images/cross.png")),QIcon::Normal,QIcon::On); deleteButton->setIcon(icon); deleteButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); setItemWidget(item,1,deleteButton); connect(deleteButton,SIGNAL(clicked()),this,SLOT(removeColorAssignment())); } //aktualisiere SmvTreeWidget und TextEdit mainWindow->updateSMVTreeTexture(f); redrawListWidget(); //wenn Farbe schon in FeatureTreeWidget vorhanden, setze diese auf weiß/transparent QList <QTreeWidgetItem*> *treeList = new QList <QTreeWidgetItem*>(); findBackGroundColor(c->color,root,treeList); if (treeList->isEmpty()==false) { for (int i = 0;i < treeList->size();i++){ static_cast<MyTreeWidgetItem*>(treeList->at(i))->setBackgroundInvalid(); // treeList->at(i)->background(0).setStyle(Qt::NoBrush); // treeList->at(i)->setBackgroundColor(0,QColor(0,0,0,0)); colorManager->deleteColorForFeature(getCorrespondingFeature(treeList->at(i)->text(0))); } } //setze Farbe im FeatureTreeWidget static_cast<MyTreeWidgetItem*>(item)->setBGColor(c); //item->setBackgroundColor(0,selected->color); } event->ignore(); } }
void FeatureTreeWidget::assignAutomatically(){ QString size = ""; size = size.setNum(selectedItems().size()); mainWindow->questionDialog->writeToLog("assignColor<" + size + ">"); //schon zugewiesene Farben löschen for (int i = 0; i < selectedItems().size();i++){ MyTreeWidgetItem *item = static_cast<MyTreeWidgetItem*>(selectedItems().at(i)); if (item->backgroundColor(0).isValid()){ MyListWidgetItem *listItem = new MyListWidgetItem(QString("")); listItem->setBGColor(item->getBGColor()); //Icon wichtig, damit Item überhaupt angezeigt wird! QIcon icon = QIcon(); icon.addPixmap(QPixmap(QString(":/images/leer.png")),QIcon::Normal,QIcon::On); listItem->setIcon(icon); listWidget->addItem(listItem); colorManager->deleteColorForFeature(getCorrespondingFeature(item->text(0))); //item->setBackgroundColor(0,QColor(-1,-1,-1,-1)); item->setBackgroundInvalid(); itemWidget(item,1)->hide(); } } int cnt = 0; if (selectedItems().size() <= listWidget->count()) cnt = selectedItems().size(); else cnt = listWidget->count(); //nacheinander jedem ausgewählten Knoten, möglichst unterschiedliche Farben des ListWidgets zuweisen QList <Color*> *colors = new QList<Color*>(); int step = 0; if (cnt >1) //Division durch 0 verhindern step = (listWidget->count()-1)/(cnt-1); else step = 0; //Farben unterschiedlicher wählen if (step < selectedItems().size()/15) step = selectedItems().size()/15; //Farbliste füllen if (cnt > 1){ for (int i = 0;i < cnt;i++){ int add = 0; while (colors->contains(static_cast<MyListWidgetItem*>(listWidget->item((i*step + add)%listWidget->count()))->getBGColor())){ add++; } colors->push_back(static_cast<MyListWidgetItem*>(listWidget->item((i*step + add)%listWidget->count()))->getBGColor()); } }else{ int random = rand() % listWidget->count(); colors->push_back(static_cast<MyListWidgetItem*>(listWidget->item(random))->getBGColor()); } for (int i = 0; i < cnt;i++){ QTreeWidgetItem *item = selectedItems().at(i); Feature *f = getCorrespondingFeature(item->text(0)); //Color *c = static_cast<MyListWidgetItem*>(listWidget->item(0))->getBGColor(); Color *c = colors->at(i); colorManager->setColorForFeature(f,c); //aktualisiere SmvTreeWidget und TextEdit mainWindow->updateSMVTreeTexture(f); //X zum Abwählen der Farbe setzen if (itemWidget(item, 1)) itemWidget(item, 1)->show(); else{ QToolButton *deleteButton = new QToolButton(this); deleteButton->setFont(QFont(QString("MS Shell Dlg 2"),9,10,false)); //deleteButton->setFixedSize(15,18); deleteButton->setFixedWidth(16); QIcon icon = QIcon(); icon.addPixmap(QPixmap(QString(":/images/cross.png")),QIcon::Normal,QIcon::On); deleteButton->setIcon(icon); deleteButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); setItemWidget(item,1,deleteButton); connect(deleteButton,SIGNAL(clicked()),this,SLOT(removeColorAssignment())); } //wenn Farbe schon in FeatureTreeWidget vorhanden, setze diese auf weiß/transparent QList <QTreeWidgetItem*> *treeList = new QList <QTreeWidgetItem*>(); findBackGroundColor(listWidget->item(0)->backgroundColor(),root,treeList); if (treeList->isEmpty()==false) { for (int i = 0;i < treeList->size();i++){ static_cast<MyTreeWidgetItem*>(treeList->at(i))->setBackgroundInvalid(); // treeList->at(i)->background(0).setStyle(Qt::NoBrush); // treeList->at(i)->setBackgroundColor(0,QColor(0,0,0,0)); colorManager->deleteColorForFeature(getCorrespondingFeature(treeList->at(i)->text(0))); } } //setze Farbe im FeatureTreeWidget static_cast<MyTreeWidgetItem*>(item)->setBGColor(c); redrawListWidget(); } }