24 #include <QHBoxLayout>
25 #include <QGridLayout>
27 #include <kmessagebox.h>
28 #include <kcomponentdata.h>
30 #include <kstandarddirs.h>
32 #include <kactioncollection.h>
33 #include <ktoggleaction.h>
34 #include <kstandardaction.h>
48 setMainWidget(mainWidget);
58 drawFrame->setFocusPolicy(Qt::NoFocus);
59 drawFrame->setMouseTracking(
true);
62 gridLayout->
addLayout(layout, 0, 0, 1, 1);
65 setMinimumHeight(120);
68 setCaption(i18n(
"Edit Board Layout"));
70 connect(drawFrame, SIGNAL(mousePressed(
QMouseEvent*)),
this, SLOT(
72 connect(drawFrame, SIGNAL(mouseMoved(
QMouseEvent*)),
this, SLOT(
77 setButtons(KDialog::None);
89 if (tileset == mTileset) {
94 if (!tiles.loadTileset(tileset)) {
96 if (!tiles.loadTileset(mTileset)) {
105 tiles.loadGraphics();
118 tiles.reloadTileset(tileSize);
120 borderLeft = (drawFrame->size().width() - (theBoard.
m_width * tiles.qWidth())) / 2;
121 borderTop = (drawFrame->size().height() - (theBoard.
m_height * tiles.qHeight())) / 2;
131 topToolbar =
new KToolBar(
this,
"editToolBar");
132 topToolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
134 actionCollection =
new KActionCollection(
this);
139 newBoard->
setText(i18n(
"New board"));
140 connect(newBoard, SIGNAL(triggered(
bool)), SLOT(
newBoard()));
141 topToolbar->addAction(newBoard);
146 openBoard->
setText(i18n(
"Open board"));
147 connect(openBoard, SIGNAL(triggered(
bool)), SLOT(
loadBoard()));
148 topToolbar->addAction(openBoard);
153 saveBoard->
setText(i18n(
"Save board"));
154 connect(saveBoard, SIGNAL(triggered(
bool)), SLOT(
saveBoard()));
155 topToolbar->addAction(saveBoard);
159 topToolbar->addSeparator();
162 #ifdef FUTURE_OPTIONS
168 select->
setText(i18n(
"Select"));
169 topToolbar->addAction(select);
175 topToolbar->addAction(cut);
180 topToolbar->addAction(copy);
185 topToolbar->addAction(paste);
187 topToolbar->addSeparator();
191 moveTiles->
setText(i18n(
"Move tiles"));
192 topToolbar->addAction(moveTiles);
198 KToggleAction *addTiles =
new KToggleAction(KIcon(
QLatin1String(
"draw-freehand")), i18n(
"Add ti"
200 actionCollection->addAction(
QLatin1String(
"add_tiles"), addTiles);
201 topToolbar->addAction(addTiles);
202 KToggleAction *delTiles =
new KToggleAction(KIcon(
QLatin1String(
"edit-delete")), i18n(
"Remove t"
204 actionCollection->addAction(
QLatin1String(
"del_tiles"), delTiles);
205 topToolbar->addAction(delTiles);
213 #ifdef FUTURE_OPTIONS
227 topToolbar->addSeparator();
233 shiftLeft->
setText(i18n(
"Shift left"));
234 connect(shiftLeft, SIGNAL(triggered(
bool)), SLOT(
slotShiftLeft()));
235 topToolbar->addAction(shiftLeft);
239 shiftUp->
setText(i18n(
"Shift up"));
240 connect(shiftUp, SIGNAL(triggered(
bool)), SLOT(
slotShiftUp()));
241 topToolbar->addAction(shiftUp);
245 shiftDown->
setText(i18n(
"Shift down"));
246 connect(shiftDown, SIGNAL(triggered(
bool)), SLOT(
slotShiftDown()));
247 topToolbar->addAction(shiftDown);
251 shiftRight->
setText(i18n(
"Shift right"));
252 connect(shiftRight, SIGNAL(triggered(
bool)), SLOT(
slotShiftRight()));
253 topToolbar->addAction(shiftRight);
255 topToolbar->addSeparator();
258 topToolbar->addAction(quit);
270 topToolbar->addWidget(hbox);
272 topToolbar->adjustSize();
273 setMinimumWidth(topToolbar->width());
278 bool canSave = ((numTiles != 0) && ((numTiles & 1) == 0));
280 actionCollection->action(
"save_board")->setEnabled(canSave);
309 if (act == actionCollection->action(
"move_tiles")) {
311 }
else if (act == actionCollection->action(
"del_tiles")) {
313 }
else if (act == actionCollection->action(
"add_tiles")) {
332 if (x >= theBoard.
m_width || x < 0 || y >= theBoard.
m_height || y < 0) {
336 buf = i18n(
"Tiles: %1 Pos: %2,%3,%4", numTiles, x, y, z);
348 KUrl url = KFileDialog::getOpenUrl(KUrl(), i18n(
"*.layout|Board Layout (*.layout)\n*|All File"
349 "s"),
this, i18n(
"Open Board Layout"));
379 if (!((numTiles != 0) && ((numTiles & 1) == 0))) {
380 KMessageBox::sorry(
this, i18n(
"You can only save with a even number of tiles."));
386 KUrl url = KFileDialog::getSaveUrl(KUrl(), i18n(
"*.layout|Board Layout (*.layout)\n*|All File"
387 "s"),
this, i18n(
"Save Board Layout"));
393 if (!url.isLocalFile()) {
394 KMessageBox::sorry(
this, i18n(
"Only saving to local files currently supported."));
402 int res = KMessageBox::warningContinueCancel(
this, i18n(
"A file with that name already exis"
403 "ts. Do you wish to overwrite it?"), i18n(
"Save Board Layout" ),
404 KStandardGuiItem::save());
406 if (res != KMessageBox::Continue) {
413 if (result ==
true) {
432 res = KMessageBox::warningYesNoCancel(
this, i18n(
"The board has been modified. Would you like t"
433 "o save the changes?"),
QString(), KStandardGuiItem::save(),KStandardGuiItem::dontSave());
435 if (res == KMessageBox::Yes) {
440 KMessageBox::sorry(
this, i18n(
"Save failed. Aborting operation."));
445 return (res != KMessageBox::Cancel);
477 int sy = tiles.qHeight();
478 int sx = tiles.qWidth();
480 for (
int y = 0; y <= theBoard.
m_height; y++) {
481 int nextY = borderTop + (y * tiles.qHeight());
482 p.
drawLine(borderLeft, nextY, borderLeft + (theBoard.
m_width * tiles.qWidth()), nextY);
485 for (
int x = 0; x <= theBoard.
m_width; x++) {
486 int nextX = borderLeft + (x * tiles.qWidth());
487 p.
drawLine(nextX, borderTop, nextX, borderTop + (theBoard.
m_height * tiles.qHeight()));
495 int shadowX = tiles.width() - tiles.qWidth() * 2 - tiles.levelOffsetX();
496 int shadowY = tiles.height() - tiles.qHeight() * 2 - tiles.levelOffsetY();
499 int xOffset = -shadowX;
500 int yOffset = -tiles.levelOffsetY();
505 for (
int z = 0; z < theBoard.
m_depth; z++) {
507 for (
int y = 0; y < theBoard.
m_height; y++) {
509 for (
int x = theBoard.
m_width - 1; x >= 0; x--) {
510 int sx = x * tiles.qWidth() + xOffset + borderLeft;
511 int sy = y * tiles.qHeight() + yOffset + borderTop;
522 t = tiles.unselectedTile(0);
531 if ((x > 1) && (y > 0) && theBoard.
getBoardData(z, y - 1, x - 2) ==
'1') {
540 p.
drawPixmap(sx - tiles.qWidth() + shadowX + tiles.levelOffsetX(), sy, t, t.
width() - tiles.qWidth(), t.height() - tiles.qHeight() - tiles.levelOffsetX() - shadowY,
541 tiles.qWidth(), tiles.qHeight() + tiles.levelOffsetX());
552 xOffset += tiles.levelOffsetX();
553 yOffset -= tiles.levelOffsetY();
566 MouseClickPos.
e = 100;
569 for (z = theBoard.
m_depth - 1; z >= 0; --z) {
573 x = ((point.
x() - borderLeft) - (z + 1) * tiles.levelOffsetX()) / tiles.qWidth();
574 y = ((point.
y() - borderTop) + z * tiles.levelOffsetX()) / tiles.qHeight();
577 if (x < 0 || x >= theBoard.
m_width || y < 0 || y >= theBoard.
m_height) {
625 if (MouseClickPos.
e == 100) {
676 int x = borderLeft + (p.
e * tiles.levelOffsetX()) + (p.
x * tiles.qWidth());
677 int y = borderTop - ((p.
e + 1) * tiles.levelOffsetY()) + (p.
y * tiles.qHeight());
678 int w = (tiles.qWidth() * 2) + tiles.levelOffsetX();
679 int h = (tiles.qHeight() * 2) + tiles.levelOffsetY();
681 if (p.
e == 100 || !visible) {
685 drawFrame->
setRect(x, y, w, h, tiles.levelOffsetX(), mode-
remove);
696 if ((mPos.
x==currPos.
x) && (mPos.
y==currPos.
y) && (mPos.
e==currPos.
e)) {
785 #include "Editor.moc"
void setText(const QString &text)
void slotShiftLeft()
Slot Description.
void newBoard()
Slot Description.
void insertTile(POSITION &p)
Description.
void slotShiftRight()
Slot Description.
void fillRect(const QRectF &rectangle, const QBrush &brush)
void clearBoardLayout()
Method description.
int m_height
Member Description.
bool canInsert(POSITION &p)
Method Description.
void shiftUp()
Method description.
void setIcon(const QIcon &icon)
USHORT e
Member Description.
void drawCursor(POSITION &p, bool visible)
Method Description.
void slotModeChanged(QAction *)
Slot Description.
QAction * addAction(QAction *action)
void deleteTile(POSITION &p)
Description.
void drawLine(const QLineF &line)
UCHAR getBoardData(short z, short y, short x)
Method description.
const QString getTileset() const
Return the tileset that is actually set.
void updateTileSize(const QSize size)
Update the tile size.
void drawBackground(QPixmap *to)
Method Description.
USHORT x
Member Description.
bool saveBoard()
Slot Description.
QPixmap * getPreviewPixmap()
Method Description.
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
int m_width
Member Description.
bool testSave()
Method Description.
Editor(QWidget *parent=0)
Constructor Description.
bool saveBoardLayout(const QString &where)
Method description.
void setText(const QString &)
void shiftDown()
Method description.
void setMargin(int margin)
USHORT y
Member Description.
const QSize & size() const
void paintEvent(QPaintEvent *pa)
Method Description.
static void setEditorGeometry(const QRect &v)
Set EditorGeometry.
static QString tileSet()
Get The tile-set to use.
QString statusText()
Method Description.
void setTilesetFromSettings()
Load the settings from prefs.
virtual ~Editor()
Default Destructor.
void resizeEvent(QResizeEvent *event)
Slot Description.
void addLayout(QLayout *layout, int row, int column, QFlags< Qt::AlignmentFlag > alignment)
void statusChanged()
Method Description.
void closeEvent(QCloseEvent *e)
Override the closeEvent(...) method of kdialog..qdialog.
void transformPointToPosition(const QPoint &, POSITION &, bool align)
Method Description.
void addStretch(int stretch)
int m_depth
Member Description.
bool isTileAt(POSITION &p)
Description.
void slotShiftDown()
Slot Description.
void slotShiftUp()
Slot Description.
void setupToolbar()
Method Description.
void drawTiles(QPixmap *to)
Method Description.
void shiftLeft()
Method description.
const QPoint & pos() const
void drawFrameMouseMovedEvent(QMouseEvent *)
Slot Description.
bool tileAbove(short z, short y, short x)
is there a tile anywhere above here (top left to bot right quarter)
void setTileset(const QString tileset)
Set a new tileset.
void drawFrameMousePressEvent(QMouseEvent *)
Slot Description.
void shiftRight()
Method description.
void loadBoard()
Slot Description.
bool anyFilled(POSITION &p)
Description.
bool allFilled(POSITION &p)
Description.
USHORT f
Member Description.
void setSpacing(int spacing)
void setRect(int x, int y, int w, int h, int ss, int type)
Method Description.
bool loadBoardLayout(const QString &from)
Method description.