예제 #1
0
static Plasma::IconWidget *createButton(QGraphicsWidget *parent)
{
    Plasma::IconWidget *button = new Plasma::IconWidget(parent);
    button->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
    button->setOrientation(Qt::Horizontal);
    button->setDrawBackground(true);
    button->setTextBackgroundColor(QColor(Qt::transparent));
    return button;
}
예제 #2
0
Plasma::IconWidget *WebBrowser::addTool(const QString &iconString, QGraphicsLinearLayout *layout)
{
    Plasma::IconWidget *icon = new Plasma::IconWidget(this);
    QAction *action = new QAction(KIcon(iconString), QString(), this);
    icon->setAction(action);
    icon->setPreferredSize(icon->sizeFromIconSize(IconSize(KIconLoader::Toolbar)));
    layout->addItem(icon);

    return icon;
}
예제 #3
0
void NetToolBox::removeTool(QAction *action)
{
    if (m_actionButtons.contains(action)) {
        Plasma::IconWidget *button = m_actionButtons.value(action);
        m_toolContainerLayout->removeItem(button);
        m_actionButtons.remove(action);
        button->deleteLater();
        if (action != m_containment->action("remove") ||
            action != m_containment->action("add page")) {
            --m_newToolsPosition;
        }
    }
}
예제 #4
0
SessionWidget::SessionWidget( QGraphicsItem * parent, Qt::WindowFlags wFlags)
  : QGraphicsWidget ( parent, wFlags)
{
  this->setFocusPolicy(Qt::ClickFocus);

   m_signalMapper = new QSignalMapper(this);

  QGraphicsLinearLayout* mainLayout = new QGraphicsLinearLayout(Qt::Vertical);
  mainLayout->setSpacing(0);
  mainLayout->addStretch();
  this->setLayout(mainLayout);

  connect( m_signalMapper, SIGNAL(mapped(int)),
           this, SLOT(slotSwitchSession(int)));

  Q_ASSERT(mainLayout->count() == 0);

  //Cache the icon pixmaps
  QSize iconSize = QSize(KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium);

  SessList sessions;
  KDisplayManager manager;
  manager.localSessions(sessions);

  QList<QGraphicsWidget*> entries;

  foreach(SessEnt session, sessions) {
    QPixmap pixmap;
    KUser user (session.user);
    if (!user.isValid())
      continue;

    if (session.tty)
      continue;

    Plasma::IconWidget* entry = createButton(this);
    pixmap = getUserIcon(user);

    entry->setIcon(pixmap);

    QString username = getUsername(false, user);
    entry->setText(username);

    connect(entry, SIGNAL(clicked()), m_signalMapper, SLOT(map()));
    m_signalMapper->setMapping(entry, session.vt);

    if (session.self)
      entry->setEnabled(false);

    entries << entry;
  }
예제 #5
0
void KBItemWidget::setDetailsShown(const bool show)
{
    if (show == (m_detailsWidget != 0)) {
        return;
    }

    if (show) {
        m_detailsWidget = new QGraphicsWidget(this);
        QGraphicsGridLayout *lay = new QGraphicsGridLayout(m_detailsWidget);

        Plasma::IconWidget *avatar = new Plasma::IconWidget(m_detailsWidget);
        lay->addItem(avatar, 0,0);
        if (!m_pixmap.isNull()) {
            avatar->setIcon(m_pixmap);
        } else {
            avatar->setIcon(KIcon("system-users"));
        }
        connect(avatar, SIGNAL(clicked()), this, SLOT(openProfile()));

        Plasma::TextBrowser *question = new Plasma::TextBrowser(m_detailsWidget);
        question->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
        question->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        lay->addItem(question, 0, 1);
        question->setText(i18n("<body><b>Question:</b> %1</body>" ,m_ocsData["Description"].toString()));
        question->nativeWidget()->document()->setDefaultStyleSheet(Plasma::Theme::defaultTheme()->styleSheet());
        question->setText(i18n("<body><b>Question:</b> %1</body>" ,m_ocsData["Description"].toString()));
        question->nativeWidget()->setTextInteractionFlags(Qt::NoTextInteraction);

        Plasma::TextBrowser *answer = new Plasma::TextBrowser(m_detailsWidget);
        answer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
        answer->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        lay->addItem(answer, 1, 0, 1, 2);
        answer->nativeWidget()->document()->setDefaultStyleSheet(Plasma::Theme::defaultTheme()->styleSheet());
        QString answerText = m_ocsData["Answer"].toString();
        if (answerText.length() > 0) {
            answer->setText(i18n("<body><b>Answer:</b> %1</body>", answerText));
        } else {
            answer->setText(i18n("<body><b>Not answered yet</b> </body>"));
        }
        answer->nativeWidget()->setTextInteractionFlags(Qt::NoTextInteraction);

        m_layout->addItem(m_detailsWidget);
    } else {
        m_layout->removeItem(m_detailsWidget);
        m_detailsWidget->deleteLater();
        m_detailsWidget = 0;
    }

    emit detailsVisibilityChanged(this, show);
}
예제 #6
0
 bool eventFilter(QObject *watched, QEvent *event)
 {
     Plasma::IconWidget *icon = qobject_cast<Plasma::IconWidget *>(watched);
     if (icon) {
        if (event->type() == QEvent::GraphicsSceneHoverEnter) {
            m_itemBackground->setTargetItem(icon);
        } else if (event->type() == QEvent::Show) {
            //force the newly shown icon to have a sensible size
            icon->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
            layout()->invalidate();
        } else if (event->type() == QEvent::Hide) {
            if (m_location == Plasma::TopEdge || m_location == Plasma::BottomEdge) {
                icon->setMaximumWidth(0);
            } else {
                icon->setMaximumHeight(0);
            }
            layout()->invalidate();
        }
     }
     return false;
 }
예제 #7
0
TitleWidget::TitleWidget( TitleType titleType, Settings *settings, bool journeysSupported,
                          QGraphicsItem *parent )
        : QGraphicsWidget(parent), m_icon(0), m_filterWidget(0), m_journeysWidget(0),
            m_layout(new QGraphicsLinearLayout(Qt::Horizontal, this)), m_settings(settings),
            m_journeysSupported(journeysSupported), m_journeysAction(0), m_filtersAction(0)
{
    m_type = titleType;
    m_layout->setContentsMargins( 1, 1, 0, 0 );
    m_layout->setSpacing( 1 );
    m_layout->setItemSpacing( 0, 4 );

    // Initialize icon widget
    int iconExtend = 26 * settings->sizeFactor();
    Plasma::IconWidget *icon = new Plasma::IconWidget;
    icon->setIcon( "public-transport-stop" );
    icon->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
    icon->setMinimumSize( iconExtend, iconExtend );
    icon->setMaximumSize( iconExtend, iconExtend );
    setIcon( icon );

    // Add a title label
    Plasma::Label *title = new Plasma::Label( this );
    title->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
    title->setWordWrap( false );
    title->setMinimumWidth( 75 );
    QLabel *_title = title->nativeWidget();
    _title->setTextInteractionFlags( Qt::LinksAccessibleByMouse );
    addWidget( title, WidgetTitle );

    if ( m_journeysSupported ) {
        // Add a quick journey search widget
        createAndAddWidget( WidgetQuickJourneySearch );
    }

    // Add a filter widget
    createAndAddWidget( WidgetFilter );

    // Adjust to settings
    settingsChanged();
}
예제 #8
0
void SpellCheck::init()
{
    Plasma::IconWidget *icon = new Plasma::IconWidget(KIcon("tools-check-spelling"), QString(), this);

    registerAsDragHandle(icon);

    QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(this);
    layout->setContentsMargins(0, 0, 0, 0);
    layout->setSpacing(0);
    layout->addItem(icon);

    Plasma::ToolTipManager::self()->setContent(this, Plasma::ToolTipContent(i18n("Spell Checking"), i18n("Check spelling of clipboard contents."), icon->icon().pixmap(IconSize(KIconLoader::Desktop))));

    connect(this, SIGNAL(activate()), this, SLOT(toggleDialog()));
    connect(icon, SIGNAL(clicked()), this, SLOT(toggleDialog()));
}
예제 #9
0
void NetToolBox::addTool(QAction *action)
{
    Plasma::IconWidget *button = new Plasma::IconWidget(this);
    button->setOrientation(Qt::Horizontal);
    button->setTextBackgroundColor(QColor());
    button->installEventFilter(m_toolContainer);
    button->setAction(action);

    qreal left, top, right, bottom;
    m_toolContainer->itemBackground()->getContentsMargins(&left, &top, &right, &bottom);
    button->setContentsMargins(left, top, right, bottom);

    if (m_location == Plasma::LeftEdge || m_location == Plasma::RightEdge) {
        button->setOrientation(Qt::Vertical);
    } else {
        button->setOrientation(Qt::Horizontal);
    }

    m_actionButtons[action] = button;

    if (action == m_containment->action("remove")) {
        m_toolContainerLayout->addItem(button);
        --m_newToolsPosition;
    } else if (action == m_containment->action("add page")) {
        m_toolContainerLayout->insertItem(m_newToolsPosition+1, button);
        --m_newToolsPosition;
    } else if (action == m_containment->action("add applications")) {
        m_toolContainerLayout->insertItem(1, button);
        --m_newToolsPosition;
    } else {
        m_toolContainerLayout->insertItem(m_newToolsPosition, button);
    }
    ++m_newToolsPosition;

    if (m_toolContainerLayout->count() == 1) {
        m_toolContainer->itemBackground()->setTargetItem(button);
    }
}
예제 #10
0
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;
        }
    }
}
예제 #11
0
파일: Applet.cpp 프로젝트: cancamilo/amarok
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;
}
예제 #12
0
 foreach( QAction* action, actions )
 {
     Plasma::IconWidget *icon = addAction( this, action, 24 );
     icon->setText( QString() );
     m_actionsLayout->addItem( icon );
 }
예제 #13
0
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()));
}
예제 #14
0
bool operator <(const Plasma::IconWidget& a, const Plasma::IconWidget& b)
{
  return (a.text() < b.text());
}
예제 #15
0
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()));
}