Exemplo n.º 1
0
ClockPhotoDialog::ClockPhotoDialog(KIPI::Interface* interface, QWidget* parent)
                : KDialog(parent), d(new ClockPhotoDialogPrivate)
{
    d->interface     = interface;

    // Initialize the variables.
    d->image         = new QPixmap();
    d->photoDateTime = new QDateTime();
    deltaNegative    = false;
    deltaDays        = 0;
    deltaHours       = 0;
    deltaMinutes     = 0;
    deltaSeconds     = 0;

    // This dialog should be modal with three buttons: Ok, Cancel, and load
    // photo. For this third button, the User1 button from KDialog is used.
    // The Ok button is only enable when a photo is loaded.
    setCaption(i18n("Determine time difference with clock photo"));
    setButtons(User1 | Ok | Cancel);
    button(User1)->setText(i18n("Load different photo"));
    button(User1)->setIcon(KIcon("document-open"));
    button(Ok)->setEnabled(false);

    // Everything else is stacked in a vertical box.
    setMainWidget(new QWidget(this));
    QVBoxLayout *vBox = new QVBoxLayout(mainWidget());

    // Some explanation.
    QLabel *explanationLabel =
            new QLabel(i18n("If you have a photo in your set with a clock or "
                            "another external time source on it, you can load "
                            "it here and set the indicator to the (date and) "
                            "time displayed. The difference of your internal "
                            "camera clock will be determined from this "
                            "setting."));
    explanationLabel->setWordWrap(true);
    vBox->addWidget(explanationLabel);

    // The image is displayed by loading an ImageDisplay in the scroll area,
    // which is an overloaded QLabel. See the Image Viewer Example from the Qt
    // documentation (http://doc.trolltech.com/4.5/widgets-imageviewer.html).
    d->scrollArea = new QScrollArea(this);
    d->scrollArea->setBackgroundRole(QPalette::Window);
    d->scrollArea->setAlignment(Qt::AlignCenter);
    vBox->addWidget(d->scrollArea);

    d->imageLabel = new ImageDisplay(d->scrollArea);
    d->imageLabel->setBackgroundRole(QPalette::Base);
    d->imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    d->imageLabel->setScaledContents(true);

    // The label is also used to display text (warning and waiting messages).
    d->imageLabel->setWordWrap(true);
    d->imageLabel->setAlignment(Qt::AlignCenter);
    d->scrollArea->setWidget(d->imageLabel);

    // For zooming support, a scale is displayed beneath the image with zoom out
    // and zoom in buttons.
    QLabel *scale_label = new QLabel(i18n("Scale:"));
    d->zoomOutButton    = new QPushButton(KIcon("zoom-out"), "");
    d->zoomInButton     = new QPushButton(KIcon("zoom-in"), "");
    d->zoomInButton->setFlat(true);
    d->zoomOutButton->setFlat(true);
    d->zoomSlider = new QSlider(Qt::Horizontal);
    d->zoomSlider->setRange(10, 150);
    QHBoxLayout *hBox1 = new QHBoxLayout(mainWidget());
    hBox1->addWidget(scale_label);
    hBox1->addWidget(d->zoomOutButton);
    hBox1->addWidget(d->zoomSlider);
    hBox1->addWidget(d->zoomInButton);
    vBox->addLayout(hBox1);
    d->zoomSlider->setEnabled(false);
    d->zoomOutButton->setEnabled(false);
    d->zoomInButton->setEnabled(false);

    // The date and time entry widget allows the user to enter the date and time
    // displayed in the image. The format is explicitly set, otherwise seconds
    // might not get displayed.
    QLabel *dtLabel = new QLabel(i18n("The clock date and time:"));
    d->calendar     = new QDateTimeEdit();
    d->calendar->setDisplayFormat("d MMMM yyyy, hh:mm:ss");
    d->calendar->setCalendarPopup(true);
    d->calendar->setEnabled(false);
    QHBoxLayout *hBox2 = new QHBoxLayout(mainWidget());
    hBox2->addStretch();
    hBox2->addWidget(dtLabel);
    hBox2->addWidget(d->calendar);
    vBox->addLayout(hBox2);

    // Setup the signals and slots.
    connect(this, SIGNAL(user1Clicked()),
            this, SLOT(slotLoadPhoto()));

    connect(d->zoomSlider, SIGNAL(sliderMoved(int)),
            this, SLOT(slotAdjustZoom(int)));

    connect(d->zoomOutButton, SIGNAL(clicked()),
            this, SLOT(slotZoomOut()));

    connect(d->zoomInButton, SIGNAL(clicked()),
            this, SLOT(slotZoomIn()));

    connect(this, SIGNAL(okClicked()),
            this, SLOT(slotOk()));

    connect(this, SIGNAL(cancelClicked()),
            this, SLOT(slotCancel()));

    // Show the window.
    KConfig config("kipirc");
    KConfigGroup group = config.group(QString("Clock Photo Dialog"));
    restoreDialogSize(group);
    show();

    // Upon initialization, present the user with a photo loading dialog. This
    // is done before the main dialog is drawn.
    slotLoadPhoto();
}
Exemplo n.º 2
0
ClockPhotoDialog::ClockPhotoDialog(QWidget* const parent)
    : KDialog(parent), d(new Private)
{
    // This dialog should be modal with three buttons: Ok, Cancel, and load
    // photo. For this third button, the User1 button from KDialog is used.
    // The Ok button is only enable when a photo is loaded.
    setCaption(i18n("Determine time difference with clock photo"));
    setButtons(User1 | Ok | Cancel);
    setMinimumWidth(500);
    setMinimumHeight(500);
    button(User1)->setText(i18n("Load different photo"));
    button(User1)->setIcon(KIcon("document-open"));
    button(Ok)->setEnabled(false);

    // Everything else is stacked in a vertical box.
    setMainWidget(new QWidget(this));
    QVBoxLayout* vBox = new QVBoxLayout(mainWidget());

    // Some explanation.
    QLabel* explanationLabel = new QLabel(i18n("If you have a photo in your set with a clock or "
                                               "another external time source on it, you can load "
                                               "it here and set the indicator to the (date and) "
                                               "time displayed. The difference of your internal "
                                               "camera clock will be determined from this "
                                               "setting."));
    explanationLabel->setWordWrap(true);
    vBox->addWidget(explanationLabel);

    // The image is displayed by loading a KPPreviewManager
    d->imagePreview = new KPPreviewManager(this);
    d->imagePreview->setBackgroundRole(QPalette::Window);
    d->imagePreview->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    vBox->addWidget(d->imagePreview);

    // The date and time entry widget allows the user to enter the date and time
    // displayed in the image. The format is explicitly set, otherwise seconds
    // might not get displayed.
    QLabel* dtLabel    = new QLabel(i18n("The clock date and time:"));
    d->calendar        = new QDateTimeEdit();
    d->calendar->setDisplayFormat("d MMMM yyyy, hh:mm:ss");
    d->calendar->setCalendarPopup(true);
    d->calendar->setEnabled(false);
    QHBoxLayout* hBox2 = new QHBoxLayout(mainWidget());
    hBox2->addStretch();
    hBox2->addWidget(dtLabel);
    hBox2->addWidget(d->calendar);
    vBox->addLayout(hBox2);

    // Setup the signals and slots.
    connect(this, SIGNAL(user1Clicked()),
            this, SLOT(slotLoadPhoto()));

    connect(this, SIGNAL(okClicked()),
            this, SLOT(slotOk()));

    connect(this, SIGNAL(cancelClicked()),
            this, SLOT(slotCancel()));

    // Show the window.
    loadSettings();
    show();

    // Upon initialization, present the user with a photo loading dialog. This
    // is done before the main dialog is drawn.
    slotLoadPhoto();
}