Example #1
0
/*
*       Convert the screen to graphics-mode in preparation for the 
*       running of a GEM-based graphic application.
*/
void sh_tographic()
{
                                                /* retake ints that may */
                                                /*   have been stepped  */
                                                /*   on by char. appl.  */
                                                /*   including err.     */
                                                /*   handler and gem.int*/
        cli();
        retake();
        sti();
                                                /* convert to graphic   */
        gsx_graphic(TRUE);
                                                /* set initial clip rect*/
        gsx_sclip(&gl_rscreen);
                                                /* allocate screen space*/
        gsx_malloc();
                                                /* start up the mouse   */
        ratinit();
                                                /* put mouse to hourglass*/
        gsx_mfset(ad_hgmice);
}
// Constructor
EditWindow::EditWindow(Screenshot* screenshot, QListWidget* listWidgetImage) : QMainWindow()
{
    this->screenshot = screenshot;
    this->listWidgetImage = listWidgetImage;
    this->newDrawingsList = screenshot->getDrawings();
    this->screenshotToShow = new QPixmap(screenshot->withDrawings());
    this->painterScreenshot = new QPainter(screenshotToShow);
    painterScreenshot->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);

    // Settings
    settings = new QSettings(this);

    // Pen
    QColor drawColor;
    drawColor.setRed(settings->value("EditWindow/drawColorR", QColor(Qt::red).red()).toInt());
    drawColor.setGreen(settings->value("EditWindow/drawColorG", QColor(Qt::red).green()).toInt());
    drawColor.setBlue(settings->value("EditWindow/drawColorB", QColor(Qt::red).blue()).toInt());
    drawPen.setColor(drawColor);
    drawPen.setWidth(settings->value("EditWindow/width", 2).toInt());
    painterScreenshot->setPen(drawPen);

    // Creation of the toolbar
    toolBar = new QToolBar(this);
    toolBar->setMovable(false);
    toolBar->setContextMenuPolicy(Qt::PreventContextMenu);

        actionValidate = toolBar->addAction(QIcon("://images/editwindow/validate.ico"), tr("Validate (Enter)"));
        actionValidate->setShortcut(QKeySequence(Qt::Key_Return));
        QObject::connect(actionValidate, SIGNAL(triggered()), this, SLOT(validate()));

        actionCancel = toolBar->addAction(QIcon("://images/editwindow/cancel.ico"), tr("Cancel (Escape)"));
        actionCancel->setShortcut(QKeySequence(Qt::Key_Escape));
        QObject::connect(actionCancel, SIGNAL(triggered()), this, SLOT(cancel()));

        // If we edit a fresh new screenshot...
        if(this->listWidgetImage != 0)
        {
            // ... we add the possibility to retake it
            actionRetake = toolBar->addAction(QIcon("://images/editwindow/retakescreenshot.ico"), tr("Retake the screenshot (Ctrl+N)"));
            actionRetake->setShortcut(QKeySequence::New);
            QObject::connect(actionRetake, SIGNAL(triggered()), this, SLOT(retake()));
        }

    toolBar->addSeparator();

        actionSave = toolBar->addAction(QIcon("://images/toolbar/save.ico"), tr("Save it (Ctrl+S)"));
        actionSave->setShortcut(QKeySequence::Save);
        QObject::connect(actionSave, SIGNAL(triggered()), this, SLOT(save()));

        actionCopyIntoClipboard = toolBar->addAction(QIcon("://images/editwindow/copytoclipboard.ico"), tr("Copy to clipboard (Ctrl+C)"));
        actionCopyIntoClipboard->setShortcut(QKeySequence::Copy);
        QObject::connect(actionCopyIntoClipboard, SIGNAL(triggered()), this, SLOT(copyIntoClipboard()));

        actionUpload = toolBar->addAction(QIcon("://images/toolbar/noelshack.ico"), tr("Upload to NoelShack (Ctrl+U)"));
        actionUpload->setShortcut(QKeySequence("Ctrl+U"));
        QObject::connect(actionUpload, SIGNAL(triggered()), this, SLOT(upload()));

    toolBar->addSeparator();

        sliderPenWidth = new QSlider(Qt::Horizontal, toolBar);
            sliderPenWidth->setToolTip(tr("Size of the drawing tools"));
            sliderPenWidth->setValue(drawPen.width());
            sliderPenWidth->setRange(1,10);
            sliderPenWidth->setFixedWidth(50);

    toolBar->addWidget(sliderPenWidth);

        spinBoxPenWidth = new QSpinBox(toolBar);
            spinBoxPenWidth->setToolTip(tr("Size of the drawing tools"));
            spinBoxPenWidth->setValue(sliderPenWidth->value());
            spinBoxPenWidth->setRange(1,10);
            spinBoxPenWidth->setFixedWidth(35);
            QObject::connect(sliderPenWidth, SIGNAL(valueChanged(int)), spinBoxPenWidth, SLOT(setValue(int)));
            QObject::connect(spinBoxPenWidth, SIGNAL(valueChanged(int)), sliderPenWidth, SLOT(setValue(int)));
            QObject::connect(spinBoxPenWidth, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int)));

    toolBar->addWidget(spinBoxPenWidth);

    actionColor = toolBar->addAction(QIcon("://images/editwindow/color.ico"), tr("Color of the drawing tools"));
    QObject::connect(actionColor, SIGNAL(triggered()), this, SLOT(changePenColor()));

    toolBar->addSeparator();

        actionGroupDrawTool = new QActionGroup(toolBar);
        QObject::connect(actionGroupDrawTool, SIGNAL(triggered(QAction*)), this, SLOT(changeDrawingTool()));

            actionFreeLine = actionGroupDrawTool->addAction(QIcon("://images/editwindow/freeline.ico"), tr("Free line"));
            actionFreeLine->setCheckable(true);

            actionStraightLine = actionGroupDrawTool->addAction(QIcon("://images/editwindow/straightline.ico"), tr("Straight line"));
            actionStraightLine->setCheckable(true);

            actionFrame = actionGroupDrawTool->addAction(QIcon("://images/editwindow/frame.ico"), tr("Frame"));
            actionFrame->setCheckable(true);

            actionEraser = actionGroupDrawTool->addAction(QIcon("://images/editwindow/eraser.ico"), tr("Eraser"));
            actionEraser->setCheckable(true);

            // Activate the last drawing tool used by the user
            switch(settings->value("EditWindow/drawingTool", typeDrawTool(FREELINE)).toInt())
            {
                case FREELINE :
                actionFreeLine->setChecked(true);
                break;

                case STRAIGHTLINE :
                actionStraightLine->setChecked(true);
                break;

                case FRAME :
                actionFrame->setChecked(true);
                break;

                case ERASER :
                actionEraser->setChecked(true);
                break;
            }

    toolBar->addActions(actionGroupDrawTool->actions());

    this->addToolBar(toolBar);


    // Creation of the main widget
    widgetMain = new QWidget(this);
    this->setCentralWidget(widgetMain);

        // Creation of the layout of the window
        layout = new QHBoxLayout(widgetMain);
        layout->setContentsMargins(10,10,10,10);

            // If the screenshot is to big
            scrollArea = new QScrollArea(widgetMain);

                // Creation of the label which contain the image to display
                labelImage = new QLabel(scrollArea);
                labelImage->setPixmap(*this->screenshotToShow);
                labelImage->setFixedSize(this->screenshot->getImage().size());

            scrollArea->setWidget(labelImage);
            scrollArea->setAlignment(Qt::AlignCenter);
            scrollArea->setMaximumSize(QApplication::desktop()->screenGeometry().size() - QSize(175,175));
            QSize minimumSize(labelImage->size() + QSize(2,2));
            if(minimumSize.width() > scrollArea->maximumSize().width())
            {
                minimumSize.setWidth(scrollArea->maximumSize().width());
                minimumSize.setHeight(minimumSize.height() + scrollArea->horizontalScrollBar()->sizeHint().height());
            }
            if(minimumSize.height() > scrollArea->maximumSize().height())
            {
                minimumSize.setHeight(scrollArea->maximumSize().height());
                minimumSize.setWidth(minimumSize.width() + scrollArea->verticalScrollBar()->sizeHint().width());
            }
            scrollArea->setMinimumSize(minimumSize);

        // Add the scroll area to the layout
        layout->addWidget(scrollArea, Qt::AlignCenter);

    // Configuration of the window
    this->setWindowTitle(tr("Edit your screenshot"));
    this->setFixedSize(this->sizeHint());
    this->setWindowModality(Qt::ApplicationModal);
    this->setAttribute(Qt::WA_DeleteOnClose);
    this->setWindowFlags(Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
    this->show();
}