Esempio n. 1
0
void kpTool::endInternal ()
{
    if (m_began)
    {
        // before we can stop using the tool, we must stop the current drawing operation (if any)
        if (hasBegunShape ())
            endShapeInternal (m_currentPoint, QRect (m_startPoint, m_currentPoint).normalize ());

        // call user virtual func
        end ();

        // clear leftover statusbar messages
        setUserMessage ();
        setUserShapePoints (currentPoint ());

        // we've stopped using the tool...
        m_began = false;

        // and so we can't be drawing with it
        m_beganDraw = false;

        if (m_mainWindow)
        {
            kpToolToolBar *tb = m_mainWindow->toolToolBar ();
            if (tb)
            {
                tb->hideAllToolWidgets ();
            }
        }

    }
}
// protected
void kpAbstractImageSelectionTool::changeImageSelectionTransparency (
        const QString &name,
        const kpImageSelectionTransparency &newTrans,
        const kpImageSelectionTransparency &oldTrans)
{
#if DEBUG_KP_TOOL_SELECTION
    qCDebug(kpLogTools) << "CALL(" << name << ")";
#endif

    kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor);

    if (hasBegunShape ())
        endShapeInternal ();

    kpAbstractImageSelection *imageSel = document ()->imageSelection ();

    if (imageSel->hasContent () && newTrans.isTransparent ())
        environ ()->flashColorSimilarityToolBarItem ();

    imageSel->setTransparency (newTrans);

    // We _must_ add the command even if kpAbstractImageSelection::setTransparency()
    // above did not change the selection transparency mask at all.
    // Consider the following case:
    //
    //   0. Ensure that selection transparency is opaque and any
    //      color other than red is the background color.  Ensure that
    //      the color similarity setting is 0.
    //
    //   1. Select a solid red rectangle and pull it off.
    //
    //   2. Switch to transparent and set red as the background color.
    //      [the selection is now invisible as red is the background
    //       color, which is the same as the contents of the selection]
    //
    //   3. Invert Colors.
    //      [the selection is now cyan, red is still the background color]
    //
    //   4. Change the background color to green.
    //      [the selection transparency mask does not change so the
    //       selection is still cyan; green is the background color]
    //
    //   5. Undo
    //
    // If no transparency command were added for Step 4., the Undo
    // in Step 5. would take us straight to the state after Step 2.,
    // where we would expect the red selection to be invisible.  However,
    // as the background color was changed to green in Step 4. and was not
    // undone, the red selection is not invisible when it should be -- Undo
    // has moved us to an incorrect state.
    //
    // KDE3: Copy this comment into the KDE 3 branch.
    commandHistory ()->addCommand (new kpToolImageSelectionTransparencyCommand (
        name,
        newTrans, oldTrans,
        environ ()->commandEnvironment ()),
        false/*no exec*/);
}
Esempio n. 3
0
void kpTool::mousePressEvent (QMouseEvent *e)
{
#if DEBUG_KP_TOOL && 1
    kdDebug () << "kpTool::mousePressEvent pos=" << e->pos ()
               << " btnStateBefore=" << (int) e->state ()
               << " btnStateAfter=" << (int) e->stateAfter ()
               << " button=" << (int) e->button ()
               << " beganDraw=" << m_beganDraw << endl;
#endif

    // state of all the buttons - not just the one that triggered the event (button())
    Qt::ButtonState buttonState = e->stateAfter ();

    if (m_mainWindow && e->button () == Qt::MidButton)
    {
        const QString text = QApplication::clipboard ()->text (QClipboard::Selection);
    #if DEBUG_KP_TOOL && 1
        kdDebug () << "\tMMB pasteText='" << text << "'" << endl;
    #endif
        if (!text.isEmpty ())
        {
            if (hasBegunShape ())
            {
            #if DEBUG_KP_TOOL && 1
                kdDebug () << "\t\thasBegunShape - end" << endl;
            #endif
                endShapeInternal (m_currentPoint,
                                  QRect (m_startPoint, m_currentPoint).normalize ());
            }

            if (viewUnderCursor ())
            {
                m_mainWindow->pasteTextAt (text,
                    viewUnderCursor ()->transformViewToDoc (e->pos ()),
                    true/*adjust topLeft so that cursor isn't
                          on top of resize handle*/);
            }

            return;
        }
    }

    int mb = mouseButton (buttonState);
#if DEBUG_KP_TOOL && 1
    kdDebug () << "\tmb=" << mb << " m_beganDraw=" << m_beganDraw << endl;
#endif

    if (mb == -1 && !m_beganDraw) return; // ignore

    if (m_beganDraw)
    {
        if (mb == -1 || mb != m_mouseButton)
        {
        #if DEBUG_KP_TOOL && 1
            kdDebug () << "\tCancelling operation as " << mb << " == -1 or != " << m_mouseButton << endl;
        #endif

            kpView *view = viewUnderStartPoint ();
            if (!view)
            {
                kdError () << "kpTool::mousePressEvent() cancel without a view under the start point!" << endl;
            }

            // if we get a mousePressEvent when we're drawing, then the other
            // mouse button must have been pressed
            m_currentPoint = view ? view->transformViewToDoc (e->pos ()) : QPoint (-1, -1);
            m_currentViewPoint = view ? e->pos () : QPoint (-1, -1);
            cancelShapeInternal ();
        }

        return;
    }

    kpView *view = viewUnderCursor ();
    if (!view)
    {
        kdError () << "kpTool::mousePressEvent() without a view under the cursor!" << endl;
    }

#if DEBUG_KP_TOOL && 1
    if (view)
        kdDebug () << "\tview=" << view->name () << endl;
#endif


    // let user know what mouse button is being used for entire draw
    m_mouseButton = mouseButton (buttonState);
    m_shiftPressed = (buttonState & Qt::ShiftButton);
    m_controlPressed = (buttonState & Qt::ControlButton);
    m_altPressed = (buttonState & Qt::AltButton);
    m_startPoint = m_currentPoint = view ? view->transformViewToDoc (e->pos ()) : QPoint (-1, -1);
    m_currentViewPoint = view ? e->pos () : QPoint (-1, -1);
    m_viewUnderStartPoint = view;
    m_lastPoint = QPoint (-1, -1);

#if DEBUG_KP_TOOL && 1
    kdDebug () << "\tBeginning draw @ " << m_currentPoint << endl;
#endif

    beginDrawInternal ();

    draw (m_currentPoint, m_lastPoint, QRect (m_currentPoint, m_currentPoint));
    m_lastPoint = m_currentPoint;
}