Plasma::IconWidget* Context::Applet::addAction( QGraphicsItem *parent, QAction *action, const int size ) { if( !action ) return 0; Plasma::IconWidget *tool = new Plasma::IconWidget( parent ); tool->setAction( action ); tool->setText( QString() ); tool->setToolTip( action->text() ); tool->setDrawBackground( false ); tool->setOrientation( Qt::Horizontal ); const QSizeF iconSize = tool->sizeFromIconSize( size ); tool->setMinimumSize( iconSize ); tool->setMaximumSize( iconSize ); tool->resize( iconSize ); tool->setZValue( zValue() + 1 ); return tool; }
void TitleWidget::setTitleType( TitleType titleType, bool validDepartureData, bool validJourneyData ) { // Remove old additional widgets clearWidgets(); // New type m_type = titleType; switch ( titleType ) { case ShowDepartureArrivalListTitle: // Default state, a departure/arrival board is shown setIcon( validDepartureData ? DepartureListOkIcon : DepartureListErrorIcon ); m_icon->setToolTip( i18nc("@info:tooltip", "Show available actions in the applet") ); setTitle( titleText() ); // Show a title (with the stop name) and the filter and quick journey search widgets addWidget( m_title, WidgetTitle ); if ( m_journeysSupported ) { addWidget( m_journeysWidget, WidgetQuickJourneySearch ); } addWidget( m_filterWidget, WidgetFilter ); break; case ShowIntermediateDepartureListTitle: // An intermediate deparure list is shown setIcon( GoBackIcon ); m_icon->setToolTip( i18nc("@info:tooltip", "Go back to original stop") ); setTitle( titleText() ); // Same as for normal departure/arrival boards addWidget( m_title, WidgetTitle ); if ( m_journeysSupported ) { addWidget( m_journeysWidget, WidgetQuickJourneySearch ); } addWidget( m_filterWidget, WidgetFilter ); break; case ShowSearchJourneyLineEdit: { // The journey search UI is shown setIcon( AbortJourneySearchIcon ); m_icon->setToolTip( i18nc("@info:tooltip", "Abort search for journeys " "to or from the home stop" ) ); // Add widgets addJourneySearchWidgets(); Plasma::LineEdit *journeySearchLine = castedWidget<Plasma::LineEdit>(WidgetJourneySearchLine); journeySearchLine->setEnabled( true ); journeySearchLine->setFocus(); journeySearchLine->nativeWidget()->selectAll(); break; } case ShowSearchJourneyLineEditDisabled: // The journey search UI is shown, // but the currently used service provider does not support journeys setIcon( AbortJourneySearchIcon ); m_icon->setToolTip( i18nc("@info:tooltip", "Abort search for journeys " "to or from the home stop") ); // Add widgets addJourneySearchWidgets(); // Disable all widgets, because journeys are not supported by the currently used // service provider castedWidget<Plasma::LineEdit>(WidgetJourneySearchLine)->setEnabled( false ); castedWidget<Plasma::LineEdit>(WidgetFillJourneySearchLineButton)->setEnabled( false ); castedWidget<Plasma::LineEdit>(WidgetStartJourneySearchButton)->setEnabled( false ); break; case ShowJourneyListTitle: { // A list of journeys is shown setIcon( validJourneyData ? JourneyListOkIcon : JourneyListErrorIcon ); m_icon->setToolTip( i18nc("@info:tooltip", "Show available actions in the applet") ); // Add a close icon to close the journey view int iconExtend = 26 * m_settings->sizeFactor(); Plasma::IconWidget *closeIcon = new Plasma::IconWidget; closeIcon->setIcon( "window-close" ); closeIcon->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); closeIcon->setMinimumSize( iconExtend, iconExtend ); closeIcon->setMaximumSize( iconExtend, iconExtend ); closeIcon->setToolTip( i18nc("@info:tooltip", "Show departures / arrivals") ); connect( closeIcon, SIGNAL(clicked()), this, SIGNAL(closeIconClicked()) ); addWidget( closeIcon, WidgetCloseIcon ); // Add a title label addWidget( m_title, WidgetTitle ); break; } } }
void UserWidget::buildDialog() { updateColors(); int m = 64; // size of the image int actionSize = KIconLoader::SizeSmallMedium; m_layout = new QGraphicsGridLayout(this); m_layout->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_layout->setColumnFixedWidth(0, m); // This could probably be a bit more dynamic m_layout->setColumnMinimumWidth(1, 60); m_layout->setHorizontalSpacing(4); m_image = new ContactImage(m_engine, this); m_image->setPreferredWidth(m); m_image->setPreferredHeight(m); m_image->setMinimumHeight(m); m_image->setMinimumWidth(m); m_layout->addItem(m_image, 0, 0, 1, 1, Qt::AlignTop); m_nameLabel = new Label(this); m_nameLabel->nativeWidget()->setWordWrap(true); m_nameLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); m_nameLabel->setMinimumWidth(60); m_nameLabel->setMaximumHeight(40); m_layout->addItem(m_nameLabel, 0, 1, 1, 1, Qt::AlignTop); m_infoView = new WebView(this); m_infoView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); //m_infoView->nativeWidget()->setFont(KGlobalSettings::smallestReadableFont()); //m_infoView->nativeWidget()->setWordWrap(true); m_layout->addItem(m_infoView, 1, 0, 1, 2, Qt::AlignTop); Plasma::IconWidget* back = new Plasma::IconWidget; back->setIcon("go-previous-view"); back->setToolTip(i18n("Back")); back->setMinimumHeight(actionSize); back->setMaximumHeight(actionSize); back->setMinimumWidth(actionSize); back->setMaximumWidth(actionSize); m_addFriend = new Plasma::IconWidget; m_addFriend->setIcon("list-add-user"); m_addFriend->setToolTip(i18n("Add friend")); m_addFriend->setMinimumHeight(actionSize); m_addFriend->setMaximumHeight(actionSize); m_addFriend->setMinimumWidth(actionSize); m_addFriend->setMaximumWidth(actionSize); m_sendMessage = new Plasma::IconWidget; m_sendMessage->setIcon("mail-send"); m_sendMessage->setToolTip(i18n("Send message")); m_sendMessage->setMinimumHeight(actionSize); m_sendMessage->setMaximumHeight(actionSize); m_sendMessage->setMinimumWidth(actionSize); m_sendMessage->setMaximumWidth(actionSize); QGraphicsLinearLayout* actionLayout = new QGraphicsLinearLayout(Qt::Horizontal); actionLayout->addItem(back); actionLayout->addStretch(); actionLayout->addItem(m_addFriend); actionLayout->addItem(m_sendMessage); m_layout->addItem(actionLayout, 2, 0, 1, 2); setLayout(m_layout); m_mapper = new QSignalMapper(this); connect(back, SIGNAL(clicked()), SIGNAL(done())); connect(m_sendMessage, SIGNAL(clicked()), m_mapper, SLOT(map())); connect(m_addFriend, SIGNAL(clicked()), m_mapper, SLOT(map())); connect(m_mapper, SIGNAL(mapped(QString)), this, SIGNAL(sendMessage(QString))); updateColors(); connect(&m_personWatch, SIGNAL(updated()), SLOT(dataUpdated())); }
SendMessageWidget::SendMessageWidget(DataEngine* engine, QGraphicsWidget* parent) : Frame(parent), m_engine(engine), m_personWatch(engine) { m_updateTimer.setInterval(1000); m_updateTimer.setSingleShot(true); int avatarSize = KIconLoader::SizeMedium; int actionSize = KIconLoader::SizeSmallMedium; Label* title = new Label; title->setText(i18n("<b>Send message</b>")); // Recipient m_image = new ContactImage(m_engine); m_image->setMinimumHeight(avatarSize); m_image->setMinimumWidth(avatarSize); m_image->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); m_toLabel = new Label; m_toEdit = new LineEdit; QGraphicsGridLayout* toLayout = new QGraphicsGridLayout; toLayout->setColumnFixedWidth(0, avatarSize * 1.2); toLayout->addItem(m_image, 0, 0, 2, 1); toLayout->addItem(m_toLabel, 0, 1); toLayout->addItem(m_toEdit, 1, 1); Label* subjectLabel = new Label; subjectLabel->setText(i18n("Subject:")); m_subject = new LineEdit; Label* bodyLabel = new Label; bodyLabel->setText(i18n("Message:")); Frame* bodyFrame = new Frame(this); bodyFrame->setFrameShadow(Sunken); bodyFrame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_body = new TextEdit; (new QGraphicsLinearLayout(bodyFrame))->addItem(m_body); Plasma::IconWidget* cancel = new Plasma::IconWidget; cancel->setIcon("go-previous-view"); cancel->setToolTip(i18n("Back")); cancel->setMinimumHeight(actionSize); cancel->setMaximumHeight(actionSize); cancel->setMinimumWidth(actionSize); cancel->setMaximumWidth(actionSize); m_submit = new Plasma::IconWidget; m_submit->setIcon("mail-send"); m_submit->setToolTip(i18n("Send")); m_submit->setMinimumHeight(actionSize); m_submit->setMaximumHeight(actionSize); m_submit->setMinimumWidth(actionSize); m_submit->setMaximumWidth(actionSize); m_submit->setEnabled(false); QGraphicsLinearLayout* buttonLayout = new QGraphicsLinearLayout(Qt::Horizontal); buttonLayout->addItem(cancel); buttonLayout->addStretch(); buttonLayout->addItem(m_submit); QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical, this); layout->addItem(title); layout->addItem(toLayout); layout->addItem(subjectLabel); layout->addItem(m_subject); layout->addItem(bodyLabel); layout->addItem(bodyFrame); layout->addItem(buttonLayout); connect(m_submit, SIGNAL(clicked()), SLOT(send())); connect(cancel, SIGNAL(clicked()), SIGNAL(done())); connect(&m_updateTimer, SIGNAL(timeout()), SLOT(updateTo())); connect(m_toEdit, SIGNAL(editingFinished()), SLOT(updateTo())); connect(m_toEdit, SIGNAL(textEdited(QString)), SLOT(updateSendAction())); connect(m_toEdit, SIGNAL(textEdited(QString)), SLOT(toChanged(QString))); connect(m_toEdit, SIGNAL(returnPressed()), SLOT(switchToSubject())); connect(&m_personWatch, SIGNAL(updated()), SLOT(personUpdated())); connect(m_subject, SIGNAL(textEdited(QString)), SLOT(updateSendAction())); connect(m_subject, SIGNAL(returnPressed()), SLOT(switchToBody())); connect(m_body, SIGNAL(textChanged()), SLOT(updateSendAction())); }