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