From atlantik-devel Fri Nov 29 04:27:33 2002 From: kde () office ! kde ! org Date: Fri, 29 Nov 2002 04:27:33 +0000 To: atlantik-devel Subject: [atlantik-cvs] CVS: kdegames/atlantik/libatlantikui board.cpp,1.99,1.100 portfolioview.cpp,1.47,1.48 X-MARC-Message: https://marc.info/?l=atlantik-devel&m=103854408900426 Update of /home/kde/kdegames/atlantik/libatlantikui In directory office:/tmp/cvs-serv1832/libatlantikui Modified Files: board.cpp portfolioview.cpp portfolioview.h token.cpp token.h Log Message: framework support for custom tokens Index: board.cpp =================================================================== RCS file: /home/kde/kdegames/atlantik/libatlantikui/board.cpp,v retrieving revision 1.99 retrieving revision 1.100 diff -u -d -r1.99 -r1.100 --- board.cpp 2002/11/28 21:38:24 1.99 +++ board.cpp 2002/11/29 04:27:31 1.100 @@ -43,6 +43,8 @@ m_animateTokens = false; m_lastServerDisplay = 0; + setMinimumSize(QSize(500, 500)); + int sideLen = maxEstates/4; // Animated token movement Index: portfolioview.cpp =================================================================== RCS file: /home/kde/kdegames/atlantik/libatlantikui/portfolioview.cpp,v retrieving revision 1.47 retrieving revision 1.48 diff -u -d -r1.47 -r1.48 --- portfolioview.cpp 2002/11/27 21:08:56 1.47 +++ portfolioview.cpp 2002/11/29 04:27:31 1.48 @@ -17,8 +17,13 @@ #include #include +#include +#include +#include +#include #include #include +#include #include #include @@ -33,6 +38,7 @@ #define PE_SPACE 2 #define PE_MARGINW 5 #define PE_MARGINH 2 +#define ICONSIZE 48 PortfolioView::PortfolioView(AtlanticCore *core, Player *player, QColor activeColor, QColor inactiveColor, QWidget *parent, const char *name) : QWidget(parent, name) { @@ -42,32 +48,15 @@ m_inactiveColor = inactiveColor; m_lastPE = 0; - b_recreate = true; - qpixmap = 0; - - setFixedSize(QSize(225, 100)); setBackgroundColor(Qt::white); - - m_nameLabel = new QLabel(this); - m_nameLabel->setAlignment(Qt::AlignLeft); - m_nameLabel->setGeometry(5, 0, width()/2, height()); - m_nameLabel->setBackgroundColor(m_player->hasTurn() ? m_activeColor : m_inactiveColor); - m_nameLabel->setMinimumSize(m_nameLabel->sizeHint()); - m_nameLabel->setMaximumWidth(width()-10); - m_nameLabel->setMaximumHeight(15); - m_nameLabel->show(); - m_moneyLabel = new QLabel(this); - m_moneyLabel->setAlignment(Qt::AlignRight); - m_moneyLabel->setGeometry(width()/2, 0, width()-5, height()); - m_moneyLabel->setBackgroundColor(m_player->hasTurn() ? m_activeColor : m_inactiveColor); - m_moneyLabel->setMinimumSize(m_moneyLabel->sizeHint()); - m_moneyLabel->setMaximumWidth(width()/2); - m_moneyLabel->setMaximumHeight(15); - m_moneyLabel->show(); + qpixmap = 0; + b_recreate = true; - // TODO: call buildPortfolio? Although, we should be able to assume no - // new estates or players are introduced after the game has been started + // Init icon + m_image = 0; + m_imageName = "hamburger"; + loadIcon(); } Player *PortfolioView::player() @@ -82,6 +71,9 @@ QPtrList estateGroups = m_atlanticCore->estateGroups(); PortfolioEstate *lastPE = 0, *firstPEprevGroup = 0; + int x = 100, y = 25, marginHint = 5, bottom; + bottom = ICONSIZE - PE_HEIGHT - marginHint; + EstateGroup *estateGroup; for (QPtrListIterator it(estateGroups); *it; ++it) { @@ -102,22 +94,25 @@ portfolioEstateMap[estate->id()] = portfolioEstate; connect(portfolioEstate, SIGNAL(estateClicked(Estate *)), this, SIGNAL(estateClicked(Estate *))); - int x, y; if (lastPE) { x = lastPE->x() + 2; y = lastPE->y() + 4; + if (y > bottom) + bottom = y; } else if (firstPEprevGroup) { x = firstPEprevGroup->x() + PE_WIDTH + 8; - y = 18; + y = 20 + marginHint; firstPEprevGroup = portfolioEstate; } else { - x = 5; - y = 18; + x = ICONSIZE + marginHint; + y = 20 + marginHint; + if (y > bottom) + bottom = y; firstPEprevGroup = portfolioEstate; } @@ -131,9 +126,43 @@ } } } + setMinimumWidth(x + PE_WIDTH + marginHint); + setMinimumHeight(bottom + PE_HEIGHT + marginHint); } -/* +void PortfolioView::loadIcon() +{ + if (m_imageName == m_player->image()) + return; + m_imageName = m_player->image(); + + delete m_image; + m_image = 0; + + m_image = new QPixmap(locate("data", "atlantik/themes/default/tokens/hamburger.png")); + + QString filename = locate("data", "atlantik/themes/default/tokens/" + m_imageName + ".png"); + if (KStandardDirs::exists(filename)) + m_image = new QPixmap(filename); + + if (!m_image) + { + m_imageName = "hamburger"; + + filename = locate("data", "atlantik/themes/default/tokens/" + m_imageName + ".png"); + if (KStandardDirs::exists(filename)) + m_image = new QPixmap(filename); + } + + QWMatrix m; + m.scale(double(ICONSIZE) / m_image->width(), double(ICONSIZE) / m_image->height()); + QPixmap *scaledPixmap = new QPixmap(ICONSIZE, ICONSIZE); + *scaledPixmap = m_image->xForm(m); + + delete m_image; + m_image = scaledPixmap; +} + void PortfolioView::paintEvent(QPaintEvent *) { if (b_recreate) @@ -144,21 +173,40 @@ QPainter painter; painter.begin(qpixmap, this); + painter.setPen(Qt::white); + painter.setBrush(Qt::white); + painter.drawRect(rect()); + + painter.setPen(m_player->hasTurn() ? m_activeColor : Qt::black); + painter.setBrush(m_player->hasTurn() ? m_activeColor : Qt::black); + painter.drawRect(0, 0, width(), 20); + + if (m_image) + { + painter.setPen(Qt::black); + painter.setBrush(Qt::white); + painter.drawRect(0, 0, ICONSIZE, ICONSIZE); + + painter.drawPixmap(0, 0, *m_image); + } + + painter.setPen(Qt::white); + painter.setFont(QFont(KGlobalSettings::generalFont().family(), KGlobalSettings::generalFont().pointSize(), QFont::Bold)); + painter.drawText(ICONSIZE + KDialog::marginHint(), 15, m_player->name()); + b_recreate = false; } bitBlt(this, 0, 0, qpixmap); } -*/ -void PortfolioView::playerChanged() +void PortfolioView::resizeEvent(QResizeEvent *) { - m_nameLabel->setText(m_player->name()); - m_nameLabel->setBackgroundColor(m_player->hasTurn() ? m_activeColor : m_inactiveColor); - m_nameLabel->update(); + b_recreate = true; +} - m_moneyLabel->setText(QString::number(m_player->money())); - m_moneyLabel->setBackgroundColor(m_player->hasTurn() ? m_activeColor : m_inactiveColor); - m_moneyLabel->update(); +void PortfolioView::playerChanged() +{ + loadIcon(); b_recreate = true; update(); Index: portfolioview.h =================================================================== RCS file: /home/kde/kdegames/atlantik/libatlantikui/portfolioview.h,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- portfolioview.h 2002/11/27 21:08:56 1.24 +++ portfolioview.h 2002/11/29 04:27:31 1.25 @@ -19,7 +19,6 @@ #include #include -#include #include #include "portfolioestate.h" @@ -42,7 +41,8 @@ Player *player(); protected: -// void paintEvent(QPaintEvent *); + void paintEvent(QPaintEvent *); + void resizeEvent(QResizeEvent *); void mousePressEvent(QMouseEvent *); signals: @@ -54,13 +54,15 @@ void slotMenuAction(int item); private: + void loadIcon(); + AtlanticCore *m_atlanticCore; Player *m_player; PortfolioEstate *m_lastPE; QColor m_activeColor, m_inactiveColor; - QPixmap *qpixmap; + QPixmap *qpixmap, *m_image; + QString m_imageName; bool b_recreate; - QLabel *m_nameLabel, *m_moneyLabel; QMap portfolioEstateMap; }; Index: token.cpp =================================================================== RCS file: /home/kde/kdegames/atlantik/libatlantikui/token.cpp,v retrieving revision 1.32 retrieving revision 1.33 diff -u -d -r1.32 -r1.33 --- token.cpp 2002/11/28 21:38:24 1.32 +++ token.cpp 2002/11/29 04:27:31 1.33 @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -30,6 +31,8 @@ #include "token.moc" +#define ICONSIZE 32 + Token::Token(Player *player, AtlantikBoard *parent, const char *name) : QWidget(parent, name) { setBackgroundMode(NoBackground); // avoid flickering @@ -46,7 +49,12 @@ qpixmap = 0; b_recreate = true; - setFixedSize(QSize(26, 26)); + // Init icon + m_image = 0; + m_imageName = "hamburger"; + loadIcon(); + + setFixedSize(QSize(ICONSIZE, ICONSIZE + KGlobalSettings::generalFont().pointSize())); } Player *Token::player() @@ -68,25 +76,72 @@ void Token::playerChanged() { + loadIcon(); + b_recreate = true; update(); } +void Token::loadIcon() +{ + kdDebug() << "loadicon [" << m_imageName << "][" << m_player->image() << "]" << endl; + + if (m_imageName != m_player->image()) + m_imageName = m_player->image(); + else + return; + + delete m_image; + m_image = 0; + + QString filename = locate("data", "atlantik/themes/default/tokens/" + m_imageName + ".png"); + if (KStandardDirs::exists(filename)) + m_image = new QPixmap(filename); + + if (!m_image) + { + m_imageName = "hamburger"; + + filename = locate("data", "atlantik/themes/default/tokens/" + m_imageName + ".png"); + if (KStandardDirs::exists(filename)) + m_image = new QPixmap(filename); + } + + QWMatrix m; + m.scale(double(ICONSIZE) / m_image->width(), double(ICONSIZE) / m_image->height()); + QPixmap *scaledPixmap = new QPixmap(ICONSIZE, ICONSIZE); + *scaledPixmap = m_image->xForm(m); + + delete m_image; + m_image = scaledPixmap; +} + void Token::paintEvent(QPaintEvent *) { if (b_recreate) { delete qpixmap; - qpixmap = new QPixmap(locate("data", "atlantik/pics/token.png")); + qpixmap = new QPixmap(width(), height()); QPainter painter; painter.begin(qpixmap, this); - painter.drawPixmap(0, 0, *qpixmap); + if (m_image) + { + painter.setPen(Qt::black); + painter.setBrush(Qt::white); + painter.drawRect(0, 0, ICONSIZE, ICONSIZE); + + painter.drawPixmap(0, 0, *m_image); + } painter.setPen(Qt::black); - painter.setFont(QFont(KGlobalSettings::generalFont().family(), KGlobalSettings::generalFont().pointSize(), QFont::Bold)); - painter.drawText(2, height()-2, m_player->name()); + painter.setBrush(Qt::black); + painter.drawRect(0, ICONSIZE, width(), KGlobalSettings::generalFont().pointSize()); + + painter.setPen(Qt::white); + painter.setFont(QFont(KGlobalSettings::generalFont().family(), KGlobalSettings::generalFont().pointSize(), QFont::DemiBold)); + painter.drawText(1, height()-1, m_player->name()); b_recreate = false; } Index: token.h =================================================================== RCS file: /home/kde/kdegames/atlantik/libatlantikui/token.h,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- token.h 2002/11/28 21:38:24 1.18 +++ token.h 2002/11/29 04:27:31 1.19 @@ -18,7 +18,8 @@ #define ATLANTIK_TOKEN_H #include -#include + +class QPixmap; class Player; class Estate; @@ -46,12 +47,15 @@ void resizeEvent(QResizeEvent *); private: + void loadIcon(); + Player *m_player; Estate *m_location, *m_destination; bool m_inJail; AtlantikBoard *m_parentBoard; bool b_recreate; - QPixmap *qpixmap; + QPixmap *qpixmap, *m_image; + QString m_imageName; }; #endif _______________________________________________ atlantik-cvs mailing list atlantik-cvs@mail.kde.org http://mail.kde.org/mailman/listinfo/atlantik-cvs