2011-07-02 23:03:18 +00:00
/*****************************************************************************
* PokerTH - The open source texas holdem engine *
2012-12-25 15:06:23 +01:00
* Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May *
2011-07-02 23:03:18 +00:00
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program 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 Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
2012-12-25 15:06:23 +01:00
* *
* *
* Additional permission under GNU AGPL version 3 section 7 *
* *
* If you modify this program, or any covered work, by linking or *
* combining it with the OpenSSL project's OpenSSL library (or a *
* modified version of that library), containing parts covered by the *
* terms of the OpenSSL or SSLeay licenses, the authors of PokerTH *
* (Felix Hammer, Florian Thauer, Lothar May) grant you additional *
* permission to convey the resulting work. *
* Corresponding Source for a non-source form of such a combination *
* shall include the source code for the parts of OpenSSL used as well *
* as that of the covered work. *
2011-07-03 19:45:08 +00:00
*****************************************************************************/
#include "myavatarlabel.h"
2008-05-05 07:46:19 +00:00
#include "gametableimpl.h"
2011-01-31 23:53:52 +00:00
#include "gametablestylereader.h"
2008-10-17 19:39:27 +00:00
#include "session.h"
#include "playerinterface.h"
#include "game.h"
2010-03-31 20:12:44 +00:00
#include "mymessagedialogimpl.h"
#include "chattools.h"
2012-01-07 22:35:23 +00:00
#include <QSysInfo>
2008-05-05 07:46:19 +00:00
using namespace std ;
MyAvatarLabel :: MyAvatarLabel ( QGroupBox * parent )
2014-01-08 09:44:20 +01:00
: QLabel ( parent ), voteRunning ( false ), transparent ( false ), myUniqueId ( 0 ), myPingState ( 0 ), myAvgPing ( - 1 ), myMinPing ( - 1 ), myMaxPing ( - 1 )
2008-05-05 07:46:19 +00:00
{
2011-02-11 20:02:08 +00:00
myContextMenu = new QMenu ;
2011-12-29 11:30:44 +00:00
action_EditTip = new QAction ( QIcon ( ":/gfx/user_properties.png" ), tr ( "Add/Edit/Remove tooltip" ), myContextMenu );
2011-02-11 20:02:08 +00:00
myContextMenu -> addAction ( action_EditTip );
action_VoteForKick = new QAction ( QIcon ( ":/gfx/list_remove_user.png" ), tr ( "Start vote to kick this player" ), myContextMenu );
myContextMenu -> addAction ( action_VoteForKick );
action_IgnorePlayer = new QAction ( QIcon ( ":/gfx/im-ban-user.png" ), tr ( "Ignore Player" ), myContextMenu );
myContextMenu -> addAction ( action_IgnorePlayer );
2013-12-12 00:31:42 +01:00
action_UnignorePlayer = new QAction ( QIcon ( ":/gfx/dialog_ok_apply.png" ), tr ( "Unignore Player" ), myContextMenu );
myContextMenu -> addAction ( action_UnignorePlayer );
2011-02-11 20:02:08 +00:00
action_ReportBadAvatar = new QAction ( QIcon ( ":/gfx/emblem-important.png" ), tr ( "Report inappropriate avatar" ), myContextMenu );
myContextMenu -> addAction ( action_ReportBadAvatar );
2010-12-11 00:58:40 +00:00
2011-02-11 20:02:08 +00:00
connect ( action_VoteForKick , SIGNAL ( triggered () ), this , SLOT ( sendTriggerVoteOnKickSignal () ) );
connect ( action_IgnorePlayer , SIGNAL ( triggered () ), this , SLOT ( putPlayerOnIgnoreList () ) );
2013-12-12 00:31:42 +01:00
connect ( action_UnignorePlayer , SIGNAL ( triggered () ), this , SLOT ( removePlayerFromIgnoreList () ) );
2011-02-11 20:02:08 +00:00
connect ( action_ReportBadAvatar , SIGNAL ( triggered () ), this , SLOT ( reportBadAvatar () ) );
connect ( action_EditTip , SIGNAL ( triggered () ), this , SLOT ( startEditTip () ) );
2008-05-05 07:46:19 +00:00
}
MyAvatarLabel ::~ MyAvatarLabel ()
{
}
2011-02-11 20:02:08 +00:00
void MyAvatarLabel :: contextMenuEvent ( QContextMenuEvent * event )
{
2015-01-13 22:21:11 +01:00
if ( myW -> getSession () -> getCurrentGame () && myW -> getSession () -> isNetworkClientRunning ()) {
2008-12-07 21:47:53 +00:00
2011-02-11 20:02:08 +00:00
boost :: shared_ptr < PlayerInterface > humanPlayer = myW -> getSession () -> getCurrentGame () -> getSeatsList () -> front ();
//only active players are allowed to start a vote
if ( humanPlayer -> getMyActiveStatus ()) {
2008-10-17 19:39:27 +00:00
2011-01-12 22:37:33 +00:00
boost :: shared_ptr < Game > currentGame = myW -> getSession () -> getCurrentGame ();
2011-02-11 20:02:08 +00:00
PlayerListConstIterator it_c ;
int activePlayerCounter = 0 ;
PlayerList seatList = currentGame -> getSeatsList ();
2011-02-09 14:33:39 +00:00
for ( it_c = seatList -> begin (); it_c != seatList -> end (); ++ it_c ) {
2011-02-11 20:02:08 +00:00
if (( * it_c ) -> getMyActiveStatus ()) activePlayerCounter ++ ;
2011-01-31 23:53:52 +00:00
}
2011-02-11 20:02:08 +00:00
GameInfo info ( myW -> getSession () -> getClientGameInfo ( myW -> getSession () -> getClientCurrentGameId ()));
if ( activePlayerCounter > 2 && ! voteRunning && info . data . gameType != GAME_TYPE_RANKING && ! myW -> getGuestMode ()) {
2013-08-28 10:49:03 +02:00
setVoteOnKickContextMenuEnabled ( true );
2011-02-11 20:02:08 +00:00
} else {
2013-08-28 10:49:03 +02:00
setVoteOnKickContextMenuEnabled ( false );
2011-01-31 23:53:52 +00:00
}
2011-01-03 22:23:58 +00:00
2011-02-11 20:02:08 +00:00
action_IgnorePlayer -> setEnabled ( true );
2013-12-12 00:31:42 +01:00
action_UnignorePlayer -> setDisabled ( true );
2011-02-11 20:02:08 +00:00
action_EditTip -> setEnabled ( true );
int j = 0 ;
2011-02-09 14:33:39 +00:00
for ( it_c = seatList -> begin (); it_c != seatList -> end (); ++ it_c ) {
2011-01-03 21:55:35 +00:00
2011-02-11 20:02:08 +00:00
if ( myId == j ) {
if ( j == 0 ) {
action_EditTip -> setDisabled ( true );
}
if ( myW -> myStartWindow -> getSession () -> getGameType () == Session :: GAME_TYPE_NETWORK ) {
action_EditTip -> setDisabled ( true );
}
2011-01-03 21:55:35 +00:00
2011-02-11 20:02:08 +00:00
if ( myW -> getSession () -> getClientPlayerInfo (( * it_c ) -> getMyUniqueID ()). isGuest ) {
action_IgnorePlayer -> setDisabled ( true );
action_EditTip -> setDisabled ( true );
}
if ( myW -> getSession () -> getGameType () == Session :: GAME_TYPE_INTERNET && ! (( * it_c ) -> getMyAvatar (). empty ()) ) {
2013-08-28 10:49:03 +02:00
action_ReportBadAvatar -> setVisible ( true );
2011-02-11 20:02:08 +00:00
} else {
2013-08-28 10:49:03 +02:00
action_ReportBadAvatar -> setVisible ( false );
2011-02-11 20:02:08 +00:00
}
2013-12-12 00:31:42 +01:00
if ( playerIsOnIgnoreList ( QString :: fromUtf8 (( * it_c ) -> getMyName (). c_str ()))) {
action_UnignorePlayer -> setEnabled ( true );
action_IgnorePlayer -> setDisabled ( true );
}
2011-02-11 20:02:08 +00:00
}
j ++ ;
}
int i = 0 ;
for ( it_c = seatList -> begin (); it_c != seatList -> end (); ++ it_c ) {
//also inactive player which stays on table can be voted to kick
if ( myContextMenuEnabled && myId != 0 && myId == i && ( * it_c ) -> getMyType () != PLAYER_TYPE_COMPUTER && ( ( * it_c ) -> getMyActiveStatus () || ( * it_c ) -> getMyStayOnTableStatus () ) )
showContextMenu ( event -> globalPos ());
i ++ ;
}
}
}
2008-05-05 07:46:19 +00:00
}
2011-02-11 20:02:08 +00:00
void MyAvatarLabel :: showContextMenu ( const QPoint & pos )
{
2008-05-05 07:46:19 +00:00
2011-02-11 20:02:08 +00:00
myContextMenu -> popup ( pos );
2008-09-23 08:15:33 +00:00
}
2011-01-31 23:53:52 +00:00
void MyAvatarLabel :: setPlayerRating ( QString playerInfo )
{
2011-02-11 20:02:08 +00:00
int found = 0 ;
QStringList playerInfoList = playerInfo . split ( " \" " , QString :: KeepEmptyParts , Qt :: CaseSensitive ), tipInfo ;
boost :: shared_ptr < Game > currentGame = myW -> myStartWindow -> getSession () -> getCurrentGame ();
PlayerList seatsList = currentGame -> getSeatsList ();
std :: list < std :: string > tipsList = myW -> getMyConfig () -> readConfigStringList ( "PlayerTooltips" );
std :: list < std :: string > result ;
std :: string separator = "(!#$%)" ;
std :: list < std :: string >:: iterator iterator ;
for ( iterator = tipsList . begin (); iterator != tipsList . end (); ++ iterator ) {
tipInfo = QString :: fromUtf8 ( iterator -> c_str ()). split ( "(!#$%)" , QString :: KeepEmptyParts , Qt :: CaseSensitive );
if ( tipInfo . at ( 0 ) == playerInfoList . at ( 0 )) {
result . push_back ( tipInfo . at ( 0 ). toUtf8 (). constData () + separator + tipInfo . at ( 1 ). toUtf8 (). constData () + separator + playerInfoList . at ( 1 ). toUtf8 (). constData () + separator );
found = 1 ;
} else {
result . push_back ( tipInfo . at ( 0 ). toUtf8 (). constData () + separator + tipInfo . at ( 1 ). toUtf8 (). constData () + separator + tipInfo . at ( 2 ). toUtf8 (). constData () + separator );
}
}
if ( found == 0 ) {
result . push_back ( playerInfoList . at ( 0 ). toUtf8 (). constData () + separator + separator + playerInfoList . at ( 1 ). toUtf8 (). constData () + separator );
}
myW -> getMyConfig () -> writeConfigStringList ( "PlayerTooltips" , result );
myW -> getMyConfig () -> writeBuffer ();
refreshStars ();
2011-01-31 23:53:52 +00:00
}
2011-02-11 20:02:08 +00:00
void MyAvatarLabel :: startChangePlayerTip ( QString playerName )
{
2012-02-03 16:49:27 +00:00
#ifdef GUI_800x480
if ( myW -> tabs . tabWidget_Left -> widget ( 2 ) == myW -> tabs . tab_Kick ) {
myW -> tabs . tabWidget_Left -> insertTab ( 3 , myW -> tabs . tab_editTip , playerName );
myW -> tabs . tabWidget_Left -> setCurrentIndex ( 3 );
} else {
myW -> tabs . tabWidget_Left -> insertTab ( 2 , myW -> tabs . tab_editTip , playerName );
myW -> tabs . tabWidget_Left -> setCurrentIndex ( 2 );
}
myW -> tabs . textEdit_tipInput -> setPlainText ( getPlayerTip ( playerName ));
#else
2011-02-11 20:02:08 +00:00
if ( myW -> tabWidget_Left -> widget ( 2 ) == myW -> tab_Kick ) {
myW -> tabWidget_Left -> insertTab ( 3 , myW -> tab_editTip , playerName );
myW -> tabWidget_Left -> setCurrentIndex ( 3 );
} else {
myW -> tabWidget_Left -> insertTab ( 2 , myW -> tab_editTip , playerName );
myW -> tabWidget_Left -> setCurrentIndex ( 2 );
}
myW -> textEdit_tipInput -> setPlainText ( getPlayerTip ( playerName ));
2012-02-03 16:49:27 +00:00
#endif
2011-02-11 20:02:08 +00:00
}
2011-01-31 23:53:52 +00:00
void MyAvatarLabel :: refreshStars ()
{
2012-01-01 22:24:59 +00:00
QString fontSize ( "12" );
2012-01-07 19:52:47 +00:00
QString fontFamily ( myW -> getMyGameTableStyle () -> getFont1String ());
2012-01-01 22:24:59 +00:00
#ifdef _WIN32
2012-01-07 21:40:17 +00:00
fontSize = "10" ;
2012-01-07 22:43:00 +00:00
if ( QSysInfo :: windowsVersion () == QSysInfo :: WV_XP ) {
2012-01-07 22:35:23 +00:00
fontFamily = "font-family: \" DejaVu Sans \" ;" ;
2012-01-07 23:14:21 +00:00
fontSize = "12" ;
2012-01-07 22:35:23 +00:00
}
2012-01-01 22:24:59 +00:00
#else
2012-01-05 20:54:27 +00:00
#ifdef __APPLE__
fontSize = "7" ;
#else
2012-01-07 18:42:24 +00:00
fontSize = "12" ;
2012-01-05 20:54:27 +00:00
#endif
2012-01-01 22:24:59 +00:00
#endif
2011-02-11 20:02:08 +00:00
boost :: shared_ptr < Game > curGame = myW -> myStartWindow -> getSession () -> getCurrentGame ();
PlayerListConstIterator it_c ;
int seatPlace ;
PlayerList seatsList = curGame -> getSeatsList ();
for ( seatPlace = 0 , it_c = seatsList -> begin (); it_c != seatsList -> end (); ++ it_c , seatPlace ++ ) {
for ( int i = 1 ; i <= 5 ; i ++ ) myW -> playerStarsArray [ i ][ seatPlace ] -> setText ( "" );
2012-01-07 08:17:13 +00:00
if ( myW -> myStartWindow -> getSession () -> getGameType () == Session :: GAME_TYPE_INTERNET && ! myW -> getSession () -> getClientPlayerInfo (( * it_c ) -> getMyUniqueID ()). isGuest && ( * it_c ) -> getMyType () != PLAYER_TYPE_COMPUTER ) {
2013-08-28 10:49:03 +02:00
if (( * it_c ) -> getMyStayOnTableStatus () == true && ( * it_c ) -> getMyName () != "" && seatPlace != 0 ) {
2011-02-11 20:02:08 +00:00
int playerStars = getPlayerRating ( QString :: fromUtf8 (( * it_c ) -> getMyName (). c_str ()));
for ( int i = 1 ; i <= 5 ; i ++ ) {
2012-01-07 08:17:13 +00:00
myW -> playerStarsArray [ i ][ seatPlace ] -> setText ( "<a style='color: #" + myW -> getMyGameTableStyle () -> getRatingStarsColor () + "; " + fontFamily + " font-size: " + fontSize + "px; text-decoration: none;' href='" + QString :: fromUtf8 (( * it_c ) -> getMyName (). c_str ()) + " \" " + QString :: number ( i ) + "'>☆</a>" );
2011-02-11 20:02:08 +00:00
}
for ( int i = 1 ; i <= playerStars ; i ++ ) {
2012-01-07 08:17:13 +00:00
myW -> playerStarsArray [ i ][ seatPlace ] -> setText ( "<a style='color: #" + myW -> getMyGameTableStyle () -> getRatingStarsColor () + "; " + fontFamily + " font-size: " + fontSize + "px; text-decoration: none;' href='" + QString :: fromUtf8 (( * it_c ) -> getMyName (). c_str ()) + " \" " + QString :: number ( i ) + "'>★</a>" );
2011-02-11 20:02:08 +00:00
}
}
2012-01-07 08:17:13 +00:00
}
2011-01-31 23:53:52 +00:00
}
}
2011-02-11 20:02:08 +00:00
void MyAvatarLabel :: refreshTooltips ()
{
2011-01-31 23:53:52 +00:00
boost :: shared_ptr < Game > currentGame = myW -> myStartWindow -> getSession () -> getCurrentGame ();
2011-02-11 20:02:08 +00:00
PlayerListConstIterator it_c ;
2011-01-31 23:53:52 +00:00
int seatPlace ;
2011-02-11 20:02:08 +00:00
PlayerList seatsList = currentGame -> getSeatsList ();
for ( seatPlace = 0 , it_c = seatsList -> begin (); it_c != seatsList -> end (); ++ it_c , seatPlace ++ ) {
2013-08-28 10:49:03 +02:00
if (( * it_c ) -> getMyStayOnTableStatus () == true || ( * it_c ) -> getMyActiveStatus ()) {
2011-02-11 20:02:08 +00:00
bool computerPlayer = false ;
if (( * it_c ) -> getMyType () == PLAYER_TYPE_COMPUTER ) {
computerPlayer = true ;
}
2011-12-31 13:33:34 +00:00
if ( ! computerPlayer && getPlayerTip ( QString :: fromUtf8 (( * it_c ) -> getMyName (). c_str ())) != "" && seatPlace != 0 ) {
2011-02-11 20:02:08 +00:00
myW -> playerTipLabelArray [( * it_c ) -> getMyID ()] -> setText ( QString ( "<a style='text-decoration: none; color: #" + myW -> getMyGameTableStyle () -> getPlayerInfoHintTextColor () + "; font-size: 14px; font-weight: bold; font-family:serif;' href= \' " ) + QString :: fromUtf8 (( * it_c ) -> getMyName (). c_str ()) + " \' >i</a>" );
myW -> playerTipLabelArray [( * it_c ) -> getMyID ()] -> setToolTip ( getPlayerTip ( QString :: fromUtf8 (( * it_c ) -> getMyName (). c_str ())) );
myW -> playerAvatarLabelArray [( * it_c ) -> getMyID ()] -> setToolTip ( getPlayerTip ( QString :: fromUtf8 (( * it_c ) -> getMyName (). c_str ())) );
} else {
myW -> playerTipLabelArray [( * it_c ) -> getMyID ()] -> setText ( "" );
myW -> playerTipLabelArray [( * it_c ) -> getMyID ()] -> setToolTip ( "" );
myW -> playerAvatarLabelArray [( * it_c ) -> getMyID ()] -> setToolTip ( "" );
}
} else {
myW -> playerTipLabelArray [( * it_c ) -> getMyID ()] -> setText ( "" );
myW -> playerTipLabelArray [( * it_c ) -> getMyID ()] -> setToolTip ( "" );
myW -> playerAvatarLabelArray [( * it_c ) -> getMyID ()] -> setToolTip ( "" );
2011-01-31 23:53:52 +00:00
2011-02-11 20:02:08 +00:00
}
2011-01-31 23:53:52 +00:00
2011-02-11 20:02:08 +00:00
}
refreshStars ();
2011-01-31 23:53:52 +00:00
}
int MyAvatarLabel :: getPlayerRating ( QString playerName )
{
2011-02-11 20:02:08 +00:00
std :: list < std :: string > tipsList = myW -> getMyConfig () -> readConfigStringList ( "PlayerTooltips" );
std :: list < std :: string >:: iterator iterator ;
QStringList playerInfo ;
QString result = "0" ;
for ( iterator = tipsList . begin (); iterator != tipsList . end (); ++ iterator ) {
playerInfo = QString :: fromUtf8 ( iterator -> c_str ()). split ( "(!#$%)" , QString :: KeepEmptyParts , Qt :: CaseSensitive );
if ( playerInfo . at ( 0 ) == playerName ) {
result = playerInfo . at ( 2 );
break ;
2011-01-31 23:53:52 +00:00
}
2011-02-11 20:02:08 +00:00
}
return result . toInt ();
2011-01-31 23:53:52 +00:00
}
QString MyAvatarLabel :: getPlayerTip ( QString playerName )
{
2011-02-11 20:02:08 +00:00
std :: list < std :: string > tipsList = myW -> getMyConfig () -> readConfigStringList ( "PlayerTooltips" );
std :: list < std :: string >:: iterator iterator ;
QStringList playerInfo ;
for ( iterator = tipsList . begin (); iterator != tipsList . end (); ++ iterator ) {
playerInfo = QString :: fromUtf8 ( iterator -> c_str ()). split ( "(!#$%)" , QString :: KeepEmptyParts , Qt :: CaseSensitive );
if ( playerInfo . at ( 0 ) == playerName ) return playerInfo . at ( 1 );
}
return QString ( "" );
2011-01-31 23:53:52 +00:00
}
void MyAvatarLabel :: setPlayerTip ()
{
2011-02-11 20:02:08 +00:00
int found = 0 ;
2011-09-29 20:54:24 +00:00
//std::string rating="1";
std :: string separator = "(!#$%)" ;
2011-02-11 20:02:08 +00:00
std :: string playerName ;
2012-02-03 16:49:27 +00:00
#ifdef GUI_800x480
std :: string tip = std :: string (( const char * ) myW -> tabs . textEdit_tipInput -> toPlainText (). toUtf8 ());
if ( myW -> tabs . tabWidget_Left -> widget ( 2 ) == myW -> tabs . tab_editTip ) playerName = myW -> tabs . tabWidget_Left -> tabText ( 2 ). toUtf8 (). constData ();
if ( myW -> tabs . tabWidget_Left -> widget ( 3 ) == myW -> tabs . tab_editTip ) playerName = myW -> tabs . tabWidget_Left -> tabText ( 3 ). toUtf8 (). constData ();
#else
std :: string tip = std :: string (( const char * ) myW -> textEdit_tipInput -> toPlainText (). toUtf8 ());
2011-02-11 20:02:08 +00:00
if ( myW -> tabWidget_Left -> widget ( 2 ) == myW -> tab_editTip ) playerName = myW -> tabWidget_Left -> tabText ( 2 ). toUtf8 (). constData ();
if ( myW -> tabWidget_Left -> widget ( 3 ) == myW -> tab_editTip ) playerName = myW -> tabWidget_Left -> tabText ( 3 ). toUtf8 (). constData ();
2012-02-03 16:49:27 +00:00
#endif
2011-02-11 20:02:08 +00:00
QStringList playerInfo ;
std :: list < std :: string > tipsList = myW -> getMyConfig () -> readConfigStringList ( "PlayerTooltips" );
std :: list < std :: string > result ;
std :: list < std :: string >:: iterator iterator ;
for ( iterator = tipsList . begin (); iterator != tipsList . end (); ++ iterator ) {
playerInfo = QString :: fromUtf8 ( iterator -> c_str ()). split ( "(!#$%)" , QString :: KeepEmptyParts , Qt :: CaseSensitive );
if ( QString :: fromUtf8 ( playerName . c_str ()) == playerInfo . at ( 0 )) {
result . push_back ( playerName + separator + QString :: fromUtf8 ( tip . c_str ()). toUtf8 (). constData () + separator + playerInfo . at ( 2 ). toStdString () + separator );
found = 1 ;
} else {
result . push_back ( playerInfo . at ( 0 ). toUtf8 (). constData () + separator + playerInfo . at ( 1 ). toUtf8 (). constData () + separator + playerInfo . at ( 2 ). toStdString () + separator );
}
}
if ( found == 0 ) {
result . push_back ( playerName . c_str () + separator + QString :: fromUtf8 ( tip . c_str ()). toUtf8 (). constData () + separator + QString ( "0" ). toStdString () + separator );
}
myW -> getMyConfig () -> writeConfigStringList ( "PlayerTooltips" , result );
myW -> getMyConfig () -> writeBuffer ();
2011-01-31 23:53:52 +00:00
2012-02-03 16:49:27 +00:00
#ifdef GUI_800x480
if ( myW -> tabs . tabWidget_Left -> widget ( 3 ) == myW -> tabs . tab_editTip ) {
myW -> tabs . tabWidget_Left -> removeTab ( 3 );
} else if ( myW -> tabs . tabWidget_Left -> widget ( 2 ) == myW -> tabs . tab_editTip ) {
myW -> tabs . tabWidget_Left -> removeTab ( 2 );
}
#else
2011-02-11 20:02:08 +00:00
if ( myW -> tabWidget_Left -> widget ( 3 ) == myW -> tab_editTip ) {
myW -> tabWidget_Left -> removeTab ( 3 );
} else if ( myW -> tabWidget_Left -> widget ( 2 ) == myW -> tab_editTip ) {
myW -> tabWidget_Left -> removeTab ( 2 );
}
2012-02-03 16:49:27 +00:00
#endif
2011-02-11 20:02:08 +00:00
refreshTooltips ();
2011-01-31 23:53:52 +00:00
}
2008-10-12 19:36:46 +00:00
void MyAvatarLabel :: sendTriggerVoteOnKickSignal ()
2008-09-23 08:15:33 +00:00
{
2011-02-11 20:02:08 +00:00
myW -> triggerVoteOnKick ( myId );
2008-10-12 19:36:46 +00:00
}
void MyAvatarLabel :: setEnabledContextMenu ( bool b )
{
2011-02-11 20:02:08 +00:00
myContextMenuEnabled = b ;
2008-05-05 07:46:19 +00:00
}
2008-11-17 16:02:11 +00:00
void MyAvatarLabel :: setVoteOnKickContextMenuEnabled ( bool b )
{
2011-02-11 20:02:08 +00:00
action_VoteForKick -> setEnabled ( b );
2009-04-22 22:32:45 +00:00
}
2011-02-11 20:02:08 +00:00
void MyAvatarLabel :: setPixmap ( const QPixmap & pix , const bool trans )
{
2009-04-22 22:32:45 +00:00
2011-02-11 20:02:08 +00:00
myPixmap = pix . scaled ( 50 , 50 , Qt :: IgnoreAspectRatio , Qt :: SmoothTransformation );
transparent = trans ;
update ();
2009-04-22 22:32:45 +00:00
}
2011-02-11 20:02:08 +00:00
void MyAvatarLabel :: setPixmapAndCountry ( const QPixmap & pix , QString countryString , int seatPlace , const bool trans )
{
QPixmap resultAvatar ( pix . scaled ( 50 , 50 , Qt :: IgnoreAspectRatio , Qt :: SmoothTransformation ));
QPainter painter ( & resultAvatar );
int showCountryFlags = myW -> getMyConfig () -> readConfigInt ( "ShowCountryFlagInAvatar" );
if ( showCountryFlags && ! countryString . isEmpty ()) {
if ( seatPlace <= 2 || seatPlace >= 8 ) {
painter . drawPixmap ( resultAvatar . width () - ( QPixmap ( countryString )). width (), resultAvatar . height () - ( QPixmap ( countryString )). height (), QPixmap ( countryString ));
} else {
painter . drawPixmap ( resultAvatar . width () - ( QPixmap ( countryString )). width (), 0 , QPixmap ( countryString ));
}
2010-10-26 17:31:41 +00:00
}
2011-02-11 20:02:08 +00:00
painter . end ();
myPixmap = resultAvatar ;
transparent = trans ;
update ();
2010-10-26 17:31:41 +00:00
}
2011-02-11 20:02:08 +00:00
void MyAvatarLabel :: paintEvent ( QPaintEvent * )
{
2009-04-22 22:32:45 +00:00
2011-02-11 20:02:08 +00:00
QPainter painter ( this );
if ( transparent )
painter . setOpacity ( 0.4 );
else
painter . setOpacity ( 1.0 );
2009-04-22 22:32:45 +00:00
2013-07-01 10:05:37 +02:00
//hide avatar if player is on ignore list
2013-08-31 14:03:44 +02:00
boost :: shared_ptr < Session > mySession = myW -> myStartWindow -> getSession ();
if ( ! playerIsOnIgnoreList ( QString :: fromUtf8 ( mySession -> getClientPlayerInfo ( myUniqueId ). playerName . c_str ()))) {
2013-10-06 16:30:09 +02:00
painter . drawPixmap ( 0 , 0 , myPixmap );
} else if ( myW -> getMyConfig () -> readConfigInt ( "DontHideAvatarsOfIgnored" )) {
2013-08-31 14:03:44 +02:00
painter . drawPixmap ( 0 , 0 , myPixmap );
2013-12-11 15:54:29 +01:00
}
if ( myW -> getMyConfig () -> readConfigInt ( "ShowPingStateInAvatar" )) {
//paint ping state color for network clients
if ( mySession -> isNetworkClientRunning () && myId == 0 ) {
QColor pingColor ;
2014-01-08 09:44:20 +01:00
if ( myAvgPing >= 0 && myAvgPing <= 1000 ) {
2013-12-11 15:54:29 +01:00
pingColor . setNamedColor ( "green" );
2013-12-19 14:27:24 +01:00
} else if ( myAvgPing > 1000 && myAvgPing <= 2000 ) {
2013-12-11 15:54:29 +01:00
pingColor . setNamedColor ( "yellow" );
2013-12-19 14:27:24 +01:00
} else if ( myAvgPing > 2000 ) {
2013-12-11 15:54:29 +01:00
pingColor . setNamedColor ( "red" );
2013-12-19 14:27:24 +01:00
} else {
2013-12-11 15:54:29 +01:00
pingColor . setNamedColor ( "white" );
}
QColor pen = pingColor . darker ( 200 );
2013-12-19 14:27:24 +01:00
// pen.setAlpha(130);
2013-12-11 15:54:29 +01:00
painter . setPen ( pen );
QColor brush = pingColor ;
2013-12-19 14:27:24 +01:00
// brush.setAlpha(130);
2013-12-11 15:54:29 +01:00
painter . setBrush ( brush );
painter . setRenderHint ( QPainter :: Antialiasing );
2013-12-18 23:21:35 +01:00
painter . drawEllipse ( 1 , 39 , 10 , 10 );
2013-12-11 15:54:29 +01:00
}
}
}
void MyAvatarLabel :: refreshPing ( unsigned minPing , unsigned avgPing , unsigned maxPing )
{
myMinPing = minPing ;
myAvgPing = avgPing ;
myMaxPing = maxPing ;
this -> update ();
if ( myW -> getMyConfig () -> readConfigInt ( "ShowPingStateInAvatar" )) {
QString toolTip = "<b>" + tr ( "Server response times" ) + "</b>" ;
toolTip . append ( "<br>" + tr ( "Average: " ) + QString ( "%1" ). arg ( myAvgPing ) + tr ( "ms" ));
toolTip . append ( "<br>" + tr ( "Minimum: " ) + QString ( "%1" ). arg ( myMinPing ) + tr ( "ms" ));
toolTip . append ( "<br>" + tr ( "Maximum: " ) + QString ( "%1" ). arg ( myMaxPing ) + tr ( "ms" ));
this -> setToolTip ( toolTip );
2013-12-19 14:27:24 +01:00
} else {
2013-12-11 15:54:29 +01:00
this -> setToolTip ( "" );
2013-07-01 10:05:37 +02:00
}
2009-04-22 22:32:45 +00:00
}
2011-02-11 20:02:08 +00:00
bool MyAvatarLabel :: playerIsOnIgnoreList ( QString playerName )
{
2010-03-31 20:12:44 +00:00
2011-02-11 20:02:08 +00:00
list < std :: string > playerIgnoreList = myW -> getMyConfig () -> readConfigStringList ( "PlayerIgnoreList" );
list < std :: string >:: iterator it1 ;
2011-02-09 16:25:05 +00:00
for ( it1 = playerIgnoreList . begin (); it1 != playerIgnoreList . end (); ++ it1 ) {
2010-03-31 20:12:44 +00:00
2011-02-11 20:02:08 +00:00
if ( playerName == QString :: fromUtf8 ( it1 -> c_str ())) {
return true ;
}
}
return false ;
2010-03-31 20:12:44 +00:00
}
2011-02-11 20:02:08 +00:00
void MyAvatarLabel :: putPlayerOnIgnoreList ()
{
QStringList list ;
PlayerListConstIterator it_c ;
PlayerList seatList = myW -> getSession () -> getCurrentGame () -> getSeatsList ();
2011-02-09 14:33:39 +00:00
for ( it_c = seatList -> begin (); it_c != seatList -> end (); ++ it_c ) {
2011-02-11 20:02:08 +00:00
list << QString :: fromUtf8 (( * it_c ) -> getMyName (). c_str ());
}
2010-03-31 20:12:44 +00:00
2011-02-11 20:02:08 +00:00
if ( ! playerIsOnIgnoreList ( list . at ( myId ))) {
myMessageDialogImpl dialog ( myW -> getMyConfig (), this );
2013-12-12 00:31:42 +01:00
if ( dialog . exec ( IGNORE_PLAYER_QUESTION , tr ( "You will no longer receive chat messages or game invitations from this user.<br>Do you really want to put player <b>%1</b> on ignore list?" ). arg ( list . at ( myId )), tr ( "PokerTH - Question" ), QPixmap ( ":/gfx/im-ban-user_64.png" ), QDialogButtonBox :: Yes | QDialogButtonBox :: No , false ) == QDialog :: Accepted ) {
2011-02-11 20:02:08 +00:00
std :: list < std :: string > playerIgnoreList = myW -> getMyConfig () -> readConfigStringList ( "PlayerIgnoreList" );
playerIgnoreList . push_back ( list . at ( myId ). toUtf8 (). constData ());
myW -> getMyConfig () -> writeConfigStringList ( "PlayerIgnoreList" , playerIgnoreList );
myW -> getMyConfig () -> writeBuffer ();
2013-12-12 00:31:42 +01:00
myW -> getMyChat () -> refreshIgnoreList ();
}
}
}
2010-03-31 20:12:44 +00:00
2013-12-12 00:31:42 +01:00
void MyAvatarLabel :: removePlayerFromIgnoreList ()
{
QStringList list ;
PlayerListConstIterator it_c ;
PlayerList seatList = myW -> getSession () -> getCurrentGame () -> getSeatsList ();
for ( it_c = seatList -> begin (); it_c != seatList -> end (); ++ it_c ) {
list << QString :: fromUtf8 (( * it_c ) -> getMyName (). c_str ());
}
if ( playerIsOnIgnoreList ( list . at ( myId ))) {
myMessageDialogImpl dialog ( myW -> getMyConfig (), this );
if ( dialog . exec ( UNIGNORE_PLAYER_QUESTION , tr ( "You will receive chat messages and game invitations from this user again!<br>Do you really want to remove player <b>%1</b> from your ignore list?" ). arg ( list . at ( myId )), tr ( "PokerTH - Question" ), QPixmap ( ":/gfx/dialog_ok_apply.png" ), QDialogButtonBox :: Yes | QDialogButtonBox :: No , false ) == QDialog :: Accepted ) {
std :: list < std :: string > playerIgnoreList = myW -> getMyConfig () -> readConfigStringList ( "PlayerIgnoreList" );
playerIgnoreList . remove ( list . at ( myId ). toUtf8 (). constData ());
myW -> getMyConfig () -> writeConfigStringList ( "PlayerIgnoreList" , playerIgnoreList );
myW -> getMyConfig () -> writeBuffer ();
2011-02-11 20:02:08 +00:00
myW -> getMyChat () -> refreshIgnoreList ();
2011-01-31 23:53:52 +00:00
}
2011-02-11 20:02:08 +00:00
}
}
void MyAvatarLabel :: reportBadAvatar ()
{
boost :: shared_ptr < Game > currentGame = myW -> getSession () -> getCurrentGame ();
int j = 0 ;
PlayerListConstIterator it_c ;
PlayerList seatList = currentGame -> getSeatsList ();
for ( it_c = seatList -> begin (); it_c != seatList -> end (); ++ it_c ) {
if ( myId == j ) {
QString avatar = QString :: fromUtf8 (( * it_c ) -> getMyAvatar (). c_str ());
if ( ! avatar . isEmpty ()) {
QString nick = QString :: fromUtf8 (( * it_c ) -> getMyName (). c_str ());
2012-05-17 01:35:59 +02:00
int ret = MyMessageBox :: question ( this , tr ( "PokerTH - Question" ),
2012-12-21 01:01:01 +01:00
tr ( "Are you sure you want to report the avatar of \" %1 \" as inappropriate?" ). arg ( nick ), QMessageBox :: Yes | QMessageBox :: No );
2011-02-11 20:02:08 +00:00
if ( ret == QMessageBox :: Yes ) {
QFileInfo fi ( avatar );
myW -> getSession () -> reportBadAvatar (( * it_c ) -> getMyUniqueID (), fi . baseName (). toStdString ());
}
}
break ;
}
j ++ ;
}
}
void MyAvatarLabel :: startEditTip ()
{
boost :: shared_ptr < Game > currentGame = myW -> getSession () -> getCurrentGame ();
int j = 0 ;
PlayerListConstIterator it_c ;
PlayerList seatList = currentGame -> getSeatsList ();
for ( it_c = seatList -> begin (); it_c != seatList -> end (); ++ it_c ) {
if ( myId == j ) {
QString nick = QString :: fromUtf8 (( * it_c ) -> getMyName (). c_str ());
startChangePlayerTip ( nick );
break ;
}
j ++ ;
2011-01-31 23:53:52 +00:00
}
}