Logo Search packages:      
Sourcecode: kmess version File versions

likebackbar.cpp

/***************************************************************************
                          (filename).cpp -  description
                             -------------------
    begin                : (Weekday) (Month) (day) 2008
    copyright            : (C) 2008 by (yourname)
    email                : (e-mail address)
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program 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 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <KApplication>

#include "likebackbar.h"
#include "../../kmessdebug.h"



// Constructor
LikeBackBar::LikeBackBar( LikeBack *likeBack )
: QWidget( 0, Qt::Tool | Qt::X11BypassWindowManagerHint )
, Ui::LikeBackBar()
, m_likeBack( likeBack )
{
  // Set up the user interface
  setupUi( this );
  resize( sizeHint() );

  // Set the button icons
  m_likeButton   ->setIcon( KIcon( "likeback_like"    ) );
  m_dislikeButton->setIcon( KIcon( "likeback_dislike" ) );
  m_bugButton    ->setIcon( KIcon( "likeback_bug"     ) );
  m_featureButton->setIcon( KIcon( "likeback_feature" ) );

  // Show buttons for the enabled types of feedback only
  LikeBack::Button buttons = likeBack->buttons();
  m_likeButton   ->setShown( buttons & LikeBack::Like    );
  m_dislikeButton->setShown( buttons & LikeBack::Dislike );
  m_bugButton    ->setShown( buttons & LikeBack::Bug     );
  m_featureButton->setShown( buttons & LikeBack::Feature );

  // Connect the slot which moves the bar always over the active window
  connect( &m_timer, SIGNAL(  timeout() ),
           this,     SLOT  ( autoMove() ) );
}



// Destructor
LikeBackBar::~LikeBackBar()
{
}



// Begin moving the bar
void LikeBackBar::startTimer()
  {
    m_timer.start( 500 );
}



// End moving the bar
void LikeBackBar::stopTimer()
{
  m_timer.stop();
}



// Move the bar where the parent window is
void LikeBackBar::autoMove()
{
  static QWidget *lastWindow = 0;

  QWidget *window = kapp->activeWindow();

  // When a Kicker applet has the focus, like the Commandline QLineEdit,
  // the systemtray icon indicates to be the current window and the LikeBack is shown next to the system tray icon.
  // It's obviously bad ;-) :
  bool shouldShow = ( m_likeBack->userWantsToShowBar() && m_likeBack->enabledBar() && window && ! window->inherits("KSystemTray") );
  if( shouldShow )
  {
    QPoint point( window->mapToGlobal(QPoint( 0, 0 ) ) );
    move( point.x() + window->width() - width(), point.y() + 1 );

#ifdef KMESSDEBUG_LIKEBACK
    if( window != lastWindow && m_likeBack->windowNamesListing() != LikeBack::NoListing )
    {
      if( window->objectName() == "unnamed" || window->objectName() == "unnamed" )
      {
        kDebug() << "Unnamed active window of type" << window->metaObject()->className() << ", active window:" << LikeBack::activeWindowPath();
      }
      else if( m_likeBack->windowNamesListing() == LikeBack::AllWindows )
      {
        kDebug() << "Active window:" << LikeBack::activeWindowPath();
      }
    }
#endif

    lastWindow = window;
  }

  // Show or hide the bar accordingly:
  if( shouldShow && ! isVisible() )
  {
    show();
  }
  else if( ! shouldShow && isVisible() )
  {
    hide();
  }
}



// The Like button has been clicked
void LikeBackBar::likeClicked()
{
  m_likeBack->execCommentDialog( LikeBack::Like );
}



// The Dislike button has been clicked
void LikeBackBar::dislikeClicked()
{
  m_likeBack->execCommentDialog( LikeBack::Dislike );
}



// The Bug button has been clicked
void LikeBackBar::bugClicked()
{
  m_likeBack->execCommentDialog( LikeBack::Bug );
}



// The Feature button has been clicked
void LikeBackBar::featureClicked()
{
  m_likeBack->execCommentDialog( LikeBack::Feature );
}


#include "likebackbar.moc"

Generated by  Doxygen 1.6.0   Back to index