예제 #1
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()));
}
예제 #2
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()));
}