Exemplo n.º 1
0
QuickButton::QuickButton(const QString &u, KAction *configAction, QWidget *parent, const char *name)
    : SimpleButton(parent, name), m_flashCounter(0), m_sticky(false)
{
    installEventFilter(KickerTip::the());
    setMouseTracking(true);
    _highlight = false;
    _oldCursor = cursor();
    _qurl = new QuickURL(u);

    QToolTip::add(this, _qurl->name());
    resize(int(DEFAULT_ICON_DIM), int(DEFAULT_ICON_DIM));
    QBrush bgbrush(colorGroup().brush(QColorGroup::Background));

    QuickAddAppsMenu *addAppsMenu = new QuickAddAppsMenu(parent, this, _qurl->url());
    _popup = new QPopupMenu(this);
    _popup->insertItem(i18n("Add Application"), addAppsMenu);
    configAction->plug(_popup);
    _popup->insertSeparator();
    _popup->insertItem(SmallIcon("remove"), i18n("Remove"), this, SLOT(removeApp()));

    m_stickyAction = new KToggleAction(i18n("Never Remove Automatically"), KShortcut(), this);
    connect(m_stickyAction, SIGNAL(toggled(bool)), this, SLOT(slotStickyToggled(bool)));
    m_stickyAction->plug(_popup, 2);
    m_stickyId = _popup->idAt(2);

    connect(this, SIGNAL(clicked()), SLOT(launch()));
    connect(this, SIGNAL(removeApp(QuickButton *)), parent, SLOT(removeAppManually(QuickButton *)));
}
Exemplo n.º 2
0
QuickButton::QuickButton(const QString &u, KAction* configAction, 
                         QWidget *parent, const char *name) : 
     QButton(parent, name),
     m_flashCounter(0),
     m_sticky(false)
{
    installEventFilter(KickerTip::the());
    if (parent && ! parent->parent())
    {
        setBackgroundMode(X11ParentRelative);
    }
    setBackgroundOrigin( AncestorOrigin );
    setMouseTracking(true);
    _highlight = false;
    _oldCursor = cursor();
    _qurl=new QuickURL(u);
    
    QToolTip::add(this, _qurl->name());
    resize(int(DEFAULT_ICON_DIM),int(DEFAULT_ICON_DIM));
    QBrush bgbrush(colorGroup().brush(QColorGroup::Background));
    
    QuickAddAppsMenu *addAppsMenu = new QuickAddAppsMenu(
        parent, this, _qurl->url());
    _popup = new QPopupMenu(this);
    _popup->insertItem(i18n("Add Application"), addAppsMenu);
    configAction->plug(_popup);
        _popup->insertSeparator();
    _popup->insertItem(SmallIcon("remove"), i18n("Remove"), 
            this, SLOT(removeApp()));

    m_stickyAction = new KToggleAction(i18n("Never Remove Automatically"),
        KShortcut(), this);
    connect(m_stickyAction, SIGNAL(toggled(bool)), 
        this, SLOT(slotStickyToggled(bool)));
    m_stickyAction->plug(_popup, 2);
    m_stickyId = _popup->idAt(2);

    settingsChanged(KApplication::SETTINGS_MOUSE);
    connect(kapp, SIGNAL(settingsChanged(int)), SLOT(settingsChanged(int)));
    connect(kapp, SIGNAL(iconChanged(int)), SLOT(iconChanged(int)));
    connect(this, SIGNAL(clicked()), SLOT(launch()));
    connect(this, SIGNAL(removeApp(QuickButton *)), parent,
        SLOT(removeAppManually(QuickButton *)));
    kapp->addKipcEventMask(KIPC::SettingsChanged);
    kapp->addKipcEventMask(KIPC::IconChanged);
}
Exemplo n.º 3
0
// ----------------------------------------------------------------------------
// FindObjects - Return a list of all the ids that draw to (x,y)
// ----------------------------------------------------------------------------
PyObject *wxPseudoDC::FindObjects(wxCoord x, wxCoord y, 
                                  wxCoord radius, const wxColor& bg)
{
    //wxPyBlock_t blocked = wxPyBeginBlockThreads();
    pdcObjectList::Node *pt = m_objectlist.GetFirst();
    pdcObject *obj;
    PyObject* pyList = NULL;
    pyList = PyList_New(0);
    wxBrush bgbrush(bg);
    wxPen bgpen(bg);
    // special case radius = 0
    if (radius == 0)
    {
        wxBitmap bmp(4,4,24);
        wxMemoryDC memdc;
        wxColor pix;
        wxRect viewrect(x-2,y-2,4,4);
        // setup the memdc for rendering
        memdc.SelectObject(bmp);
        memdc.SetBackground(bgbrush);
        memdc.Clear();
        memdc.SetDeviceOrigin(2-x,2-y);
        while (pt) 
        {
            obj = pt->GetData();
            if (obj->IsBounded() && obj->GetBounds().Contains(x,y))
            {
                // start clean
                memdc.SetBrush(bgbrush);
                memdc.SetPen(bgpen);
                memdc.DrawRectangle(viewrect);
                // draw the object
                obj->DrawToDC(&memdc);
                memdc.GetPixel(x,y,&pix);
                // clear and update rgn2
                if (pix != bg)
                {
                    PyObject* pyObj = PyInt_FromLong((long)obj->GetId());
                    PyList_Insert(pyList, 0, pyObj);
                    Py_DECREF(pyObj);
                }
            }
            pt = pt->GetNext();
        }
        memdc.SelectObject(wxNullBitmap);
    }
    else
    {
        wxRect viewrect(x-radius,y-radius,2*radius,2*radius);
        wxBitmap maskbmp(2*radius,2*radius,24);
        wxMemoryDC maskdc;
        // create bitmap with circle for masking
        maskdc.SelectObject(maskbmp);
        maskdc.SetBackground(*wxBLACK_BRUSH);
        maskdc.Clear();
        maskdc.SetBrush(*wxWHITE_BRUSH);
        maskdc.SetPen(*wxWHITE_PEN);
        maskdc.DrawCircle(radius,radius,radius);
        // now setup a memdc for rendering our object
        wxBitmap bmp(2*radius,2*radius,24);
        wxMemoryDC memdc;
        memdc.SelectObject(bmp);
        // set the origin so (x,y) is in the bmp center
        memdc.SetDeviceOrigin(radius-x,radius-y);
        // a region will be used to see if the result is empty
        wxRegion rgn2;
        while (pt) 
        {
            obj = pt->GetData();
            if (obj->IsBounded() && viewrect.Intersects(obj->GetBounds()))
            {
                // start clean
                //memdc.Clear();
                memdc.SetBrush(bgbrush);
                memdc.SetPen(bgpen);
                memdc.DrawRectangle(viewrect);
                // draw the object
                obj->DrawToDC(&memdc);
                // remove background color
                memdc.SetLogicalFunction(wxXOR);
                memdc.SetBrush(bgbrush);
                memdc.SetPen(bgpen);
                memdc.DrawRectangle(viewrect);
                memdc.SetLogicalFunction(wxCOPY);
#ifdef __WXMAC__
                // wxAND is not supported on wxMac, but it doesn't seem to
                // hurt anything to use wxCOPY instead...
                memdc.Blit(x-radius,y-radius,2*radius,2*radius,&maskdc,0,0,wxCOPY);
#else
                // AND with circle bitmap
                memdc.Blit(x-radius,y-radius,2*radius,2*radius,&maskdc,0,0,wxAND);
#endif
                // clear and update rgn2
                memdc.SelectObject(wxNullBitmap);
                rgn2.Clear();
                rgn2.Union(bmp, *wxBLACK);
                //rgn2.Intersect(rgn);
                memdc.SelectObject(bmp);
                if (!rgn2.IsEmpty())
                {
                    PyObject* pyObj = PyInt_FromLong((long)obj->GetId());
                    PyList_Insert(pyList, 0, pyObj);
                    Py_DECREF(pyObj);
                }
            }
            pt = pt->GetNext();
        }
        maskdc.SelectObject(wxNullBitmap);
        memdc.SelectObject(wxNullBitmap);
    }
    //wxPyEndBlockThreads(blocked);
    return pyList;
}
Exemplo n.º 4
0
bool CGdiPlusImage::DrawImage(CDC* pDC, CRect& rcDraw, CRect& rcCanvas)
{
    //´´½¨ÆÁÄ»
    ASSERT(pDC!=NULL); 
    if ( !pDC ) return false; 

    Bitmap bmp(rcCanvas.Width(), rcCanvas.Height()); 
    Graphics* pGraphics = Graphics::FromImage(&bmp); 
    if ( !pGraphics ) return false;

    //GraphicsContainer Containter = pGraphics->BeginContainer();
    pGraphics->SetSmoothingMode(SmoothingModeHighQuality); 

    SolidBrush bgbrush(Color(238, 243, 250));
    pGraphics->FillRectangle(&bgbrush, 0, 0, rcCanvas.Width(), rcCanvas.Height());
     
    if ( m_pImage )
    {
        //»ñÈ¡ÊôÐÔ 
        INT nImageWidth  = m_pImage->GetWidth();
        INT nImageHeight = m_pImage->GetHeight(); 


        float fMin = 1.0F;  
        bool bZoomOut = false; 
        int nXSrc = 0;
        int nYSrc = 0;  
         
        //¹¹ÔìλÖÃ
        RectF rcDrawRect;  
        rcDrawRect.X = rcDraw.left;
        rcDrawRect.Y = rcDraw.top;
        rcDrawRect.Width = rcDraw.Width();
        rcDrawRect.Height = rcDraw.Height(); 

        // »­±Ê
        Pen pen(Color(255, 0, 0), 2); 

        Matrix mtr;
        mtr.Translate(rcDrawRect.X + rcDrawRect.Width / 2, rcDrawRect.Y + rcDrawRect.Height / 2);
        mtr.Rotate(m_nRotateAngle);
        mtr.Translate(-(rcDrawRect.X + rcDrawRect.Width / 2), -(rcDrawRect.Y + rcDrawRect.Height / 2));

        pGraphics->SetTransform(&mtr); 

        //»æ»­Í¼Ïñ 
        pGraphics->DrawImage(
            m_pImage, rcDrawRect,
            nXSrc, nYSrc,
            (REAL)nImageWidth - nXSrc * 2, (REAL)nImageHeight - nYSrc * 2, UnitPixel);  
         

        for ( int i = 0; i < m_vvecPoints.size(); ++ i )
        {
            int nCount = m_vvecPoints[i].size(); 
            Point *pts = new Point[nCount];

            for ( int j = 0; j < nCount; ++ j )
            {
                pts[ j ] = m_vvecPoints[ i ][ j ]; 
                pts[ j ].X += rcDraw.left;
                pts[ j ].Y += rcDraw.top; 
            }  

            //for ( int j = 0; j < nCount - 1; ++ j )
            { 
               // pGraphics->DrawLine(&pen, pts[ j ], pts[ j +1 ]); 
            } 

  
                pGraphics->DrawLines(&pen, pts, nCount);
                //pGraphics->DrawPolygon(&pen, pts, nCount); 
        


            delete[] pts;
            pts = NULL; 
        }


        pGraphics->ResetTransform();   
        //pGraphics->EndContainer(Containter);

    } // if ( m_pImage )

    // ´ÓÄڴ濽±´ÖÁÉ豸
    Graphics graphicsreal(pDC->GetSafeHdc()); 
    graphicsreal.DrawImage(&bmp, 0, 0, rcCanvas.Width(), rcCanvas.Height()); 
    delete pGraphics;
    pGraphics = NULL;

    return true;
}
Exemplo n.º 5
0
bool CGdiPlusImage::DrawImage(CDC* pDC)
{
    //´´½¨ÆÁÄ»
    ASSERT(pDC!=NULL); 
    if ( !pDC ) return false; 

    Bitmap bmp(m_rcDest.Width(), m_rcDest.Height()); 
    Graphics* pGraphics = Graphics::FromImage(&bmp); 
    if ( !pGraphics ) return false;

    GraphicsContainer Containter = pGraphics->BeginContainer();
    pGraphics->SetSmoothingMode(SmoothingModeHighQuality); 

    SolidBrush bgbrush(Color(238, 243, 250));
    pGraphics->FillRectangle(&bgbrush, 0, 0, m_rcDest.Width(), m_rcDest.Height());
    
    if ( m_pImage )
    {
        //»ñÈ¡ÊôÐÔ 
        INT nImageWidth  = m_pImage->GetWidth();
        INT nImageHeight = m_pImage->GetHeight(); 


        float fMin = 1.0F; 
        float fZoomRate = 1.0F; 
        bool bZoomOut = false; 
        int nXSrc = 0;
        int nYSrc = 0; 

        if ( nImageWidth >= m_rcDest.Width() || nImageHeight >= m_rcDest.Height() )
        { 
            float fXRate = 1.0F * m_rcDest.Width() / nImageWidth;
            float fYRate = 1.0F * m_rcDest.Height() / nImageHeight;
            fMin = min(fXRate, fYRate);   
            fZoomRate = max(nImageWidth * 1.0F / m_rcDest.Width(), nImageHeight * 1.0F / m_rcDest.Height()); 
            bZoomOut = true;
        } 


        int nDestWidth  = fMin * nImageWidth;
        int nDestHeight = fMin * nImageHeight;


        //¹¹ÔìλÖÃ
        RectF rcDrawRect;  
        rcDrawRect.X = m_rcDest.left + (m_rcDest.Width() - nDestWidth ) / 2;   
        rcDrawRect.Y = m_rcDest.top + (m_rcDest.Height() - nDestHeight ) / 2; 
        rcDrawRect.Width = nDestWidth;
        rcDrawRect.Height = nDestHeight; 

        Matrix matrix;

        CPoint pt(m_rcDest.Width() / 2, m_rcDest.Height() / 2);
        PointF ptBase((float)pt.x, (float)pt.y);  

        //¾ØÕó±ä»»Òª×¢Òâ˳Ðò£¬ÏÈƽÒÆÔÚËõ·ÅºóÐýת
        matrix.Translate((REAL)m_rcDest.left,(REAL)m_rcDest.top,MatrixOrderAppend);

        //Ëõ·Å
        if ( m_szZoom.cx != 1.0f || m_szZoom.cy != 1.0f )
        {
            ptBase.X += m_szZoom.cx;
            ptBase.Y += m_szZoom.cy;

            matrix.Translate(-ptBase.X,-ptBase.Y,MatrixOrderAppend);
            matrix.Scale(m_szZoom.cx,m_szZoom.cy,MatrixOrderAppend);
            matrix.Translate(ptBase.X,ptBase.Y,MatrixOrderAppend);
        }

        //Ðýת
        if (m_nRotateAngle)
        {
            matrix.RotateAt((REAL)m_nRotateAngle,ptBase,MatrixOrderAppend);
        }

        pGraphics->SetTransform(&matrix);

        //͸Ã÷¾ØÕó
        ColorMatrix Matrix=
        {
            1.0f,0.0f,0.0f,0.0f,0.0f, 
            0.0f,1.0f,0.0f,0.0f,0.0f, 
            0.0f,0.0f,1.0f,0.0f,0.0f,
            0.0f,0.0f,0.0f,m_cbAlphaDepth/255.0f,0.0f, 
            0.0f,0.0f,0.0f,0.0f,1.0f
        };

        //ÉèÖÃÊôÐÔ
        ImageAttributes Attributes; 
        Attributes.SetColorMatrix(&Matrix,ColorMatrixFlagsDefault,ColorAdjustTypeBitmap); 

        //»æ»­Í¼Ïñ
        pGraphics->DrawImage(m_pImage, rcDrawRect, nXSrc, nYSrc, (REAL)nImageWidth - nXSrc * 2, (REAL)nImageHeight - nYSrc * 2, UnitPixel,&Attributes);  
        pGraphics->ResetTransform();   
        pGraphics->EndContainer(Containter);

    } // if ( m_pImage )
   
    // ´ÓÄڴ濽±´ÖÁÉ豸
    Graphics graphicsreal(pDC->GetSafeHdc()); 
    graphicsreal.DrawImage(&bmp, 0, 0, m_rcDest.Width(), m_rcDest.Height()); 
    delete pGraphics;
    pGraphics = NULL;

    return true;
}