Skip to content
Snippets Groups Projects
Select Git revision
  • 3b00b4221321db01df63661c1e1903a8d4f15ecd
  • master default protected
  • nightly/20250806.0
  • nightly/20250805.0
  • beta/202508051403
  • beta/202508051107
  • nightly/20250722.0
  • beta/202507211539
  • stable/20250718.0
  • nightly/20250718.0
  • nightly/20250714.0
  • beta/202507141552
  • beta/202506161038
  • stable/20250613.0
  • nightly/20250613.0
  • beta/202506101658
  • stable/20250610.0
  • nightly/20250610.0
  • beta/202506091027
  • beta/202506061543
  • nightly/20250605.0
  • beta/202506051039
22 results

DualPaneView.qml

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    JPushButton.cpp 2.76 KiB
    /*
     * Copyright (C) 2004-2005 Savoir-Faire Linux inc.
     * Author: Jerome Oufella (jerome.oufella@savoirfairelinux.com)
     *
     * Portions (c) Jean-Philippe Barrette-LaPierre
     *                (jean-philippe.barrette-lapierre@savoirfairelinux.com)
     * Portions (c) Valentin Heinitz
     *
     * This is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as
     * published by the Free Software Foundation; either version 2,
     * or (at your option) any later version.
     *
     * This is distributed in the hope that it will be useful, but
     * WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public
     * License along with dpkg; if not, write to the Free Software
     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     */
    
    #include <qbitmap.h>
    #include <qevent.h>
    #include <qimage.h>
    #include <qevent.h>
    
    #include "globals.h"
    
    #include "JPushButton.hpp"
    
    JPushButton::JPushButton(const QString &released,
    			 const QString &pressed,
    			 QWidget* parent)
      : QLabel(parent)
      , mIsPressed(false)
      , mIsToggling(false)
    {
      mImages[0] = transparize(released);
      mImages[1] = transparize(pressed);
      release();
    }
    
    JPushButton::~JPushButton()
    {}
    
    void
    JPushButton::setToggle(bool toggle)
    {
      mIsToggling = toggle;
    }
    
    QPixmap
    JPushButton::transparize(const QString &image)
    {
      /**
      if (!p.mask()) {
        if (p.hasAlphaChannel()) {
          p.setMask(p.alphaChannel());
        } 
        else {
          p.setMask(p.createHeuristicMask());
        }
      }
      */
      return QPixmap::fromMimeSource(image);
    }
    
    void
    JPushButton::release() 
    {
      setPixmap(mImages[0]);
      /*
      if(mImages[0].hasAlpha()) {
        setMask(mImages[0].mask());
      }
      */
      resize(mImages[0].size());
    }
    
    void
    JPushButton::press() 
    {
      setPixmap(mImages[1]);
      /*
      if(mImages[1].hasAlpha()) {
        setMask(mImages[1].mask());
        }*/
      resize(mImages[1].size());
    }
    
    // Mouse button released
    void 
    JPushButton::mousePressEvent(QMouseEvent *e) 
    {
      switch (e->button()) {
      case Qt::LeftButton:
        press();
        break;
        
      default:
        e->ignore();
        break;
      }
    }
    
    // Mouse button released
    void 
    JPushButton::mouseReleaseEvent (QMouseEvent *e) {
      switch (e->button()) {
      case Qt::LeftButton:
        if(mIsToggling) {
          mIsPressed = !mIsPressed;
          if(mIsPressed) {
    	press();
          }
          else {
    	release();
          }
          emit clicked(mIsPressed);
        }
        else {
          release();
          emit clicked();
        }
        // Emulate the left mouse click
        //if (this->rect().contains(e->pos())) {
        //  emit clicked();
        //}
        break;
        
      default:
        e->ignore();
        break;
      }
    }
    
    void 
    JPushButton::mouseMoveEvent(QMouseEvent *e) 
    {
      e->accept();
    }