Пример #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
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();
}
Пример #3
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;
        }
    }
}