Skip to content

Commit

Permalink
UI|Home: Added a widget for the "no games" column; tab switching with…
Browse files Browse the repository at this point in the history
… keys
  • Loading branch information
skyjake committed Jan 27, 2016
1 parent 94d851b commit 62d923d
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 17 deletions.
4 changes: 4 additions & 0 deletions doomsday/apps/client/include/ui/home/columnwidget.h
Expand Up @@ -32,6 +32,10 @@ class ColumnWidget : public de::GuiWidget
public:
ColumnWidget(de::String const &name = "");

de::Rule const &maximumContentWidth() const;

void setHighlighted(bool highlighted);

private:
DENG2_PRIVATE(d)
};
Expand Down
35 changes: 35 additions & 0 deletions doomsday/apps/client/include/ui/home/nogamescolumnwidget.h
@@ -0,0 +1,35 @@
/** @file nogamescolumnwidget.h
*
* @authors Copyright (c) 2016 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>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. 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 General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_UI_HOME_NOGAMESCOLUMNWIDGET_H
#define DENG_CLIENT_UI_HOME_NOGAMESCOLUMNWIDGET_H

#include "columnwidget.h"

class NoGamesColumnWidget : public ColumnWidget
{
Q_OBJECT

public:
NoGamesColumnWidget();

public slots:
void browseForDataFiles();
};

#endif // DENG_CLIENT_UI_HOME_NOGAMESCOLUMNWIDGET_H
2 changes: 2 additions & 0 deletions doomsday/apps/client/src/ui/clientwindow.cpp
Expand Up @@ -372,6 +372,8 @@ DENG2_PIMPL(ClientWindow)
gameSelMenu->hide();
iwadNotice->hide();
}

gameSelMenu->hide(); // devel
}

void currentGameChanged(Game const &newGame)
Expand Down
42 changes: 37 additions & 5 deletions doomsday/apps/client/src/ui/home/columnwidget.cpp
Expand Up @@ -20,21 +20,53 @@

#include <de/LabelWidget>
#include <de/Range>
#include <de/math.h>

#include <QColor>

using namespace de;

DENG_GUI_PIMPL(ColumnWidget)
{
bool highlighted;
LabelWidget *back;
Vector4f bgColor;
Rule const *maxContentWidth = nullptr;

Instance(Public *i) : Base(i)
{}
{
back = new LabelWidget;

QColor bg;
bg.setHsvF(de::frand(), .9, .5);
bgColor = Vector4f(bg.redF(), bg.greenF(), bg.blueF(), 1);
}

~Instance()
{
releaseRef(maxContentWidth);
}
};

ColumnWidget::ColumnWidget(String const &name)
: GuiWidget(name)
, d(new Instance(this))
{
LabelWidget *back = new LabelWidget;
back->set(Background(Vector4f(0, Rangef(0, .5f).random(), Rangef(0, .5f).random(), 1)));
back->rule().setRect(rule());
add(back);
changeRef(d->maxContentWidth, rule().width() - style().rules().rule("gap") * 2);

d->back->rule().setRect(rule());
add(d->back);
}

Rule const &ColumnWidget::maximumContentWidth() const
{
return *d->maxContentWidth;
}

void ColumnWidget::setHighlighted(bool highlighted)
{
d->highlighted = highlighted;

d->back->set(Background(highlighted? d->bgColor :
(d->bgColor * Vector4f(.5f, .5f, .5f, 1.f))));
}
58 changes: 46 additions & 12 deletions doomsday/apps/client/src/ui/home/homewidget.cpp
Expand Up @@ -18,6 +18,7 @@

#include "ui/home/homewidget.h"
#include "ui/home/columnwidget.h"
#include "ui/home/nogamescolumnwidget.h"

#include <de/LabelWidget>
#include <de/SequentialLayout>
Expand All @@ -29,8 +30,9 @@ static TimeDelta const SCROLL_SPAN = .5;

DENG_GUI_PIMPL(HomeWidget)
{
int visibleColumnCount = 2;
int visibleColumnCount = 3;
int columnCount = 7;
QList<ColumnWidget *> columns; // not owned
IndirectRule *columnWidth;
LabelWidget *tabsBackground;
TabWidget *tabs;
Expand All @@ -44,8 +46,8 @@ DENG_GUI_PIMPL(HomeWidget)
scrollOffset->setStyle(Animation::EaseBoth);

tabs = new TabWidget;
tabsBackground = new LabelWidget;

tabsBackground = new LabelWidget;
tabsBackground->set(Background(Vector4f(1, 1, 1, 1), Background::Blurred));
}

Expand All @@ -55,12 +57,14 @@ DENG_GUI_PIMPL(HomeWidget)
releaseRef(scrollOffset);
}

void addColumn(GuiWidget *col)
void addColumn(ColumnWidget *col)
{
col->rule()
.setInput(Rule::Width, *columnWidth)
.setInput(Rule::Height, self.rule().height());
self.add(col);

columns << col;
}

void updateLayout()
Expand All @@ -70,13 +74,23 @@ DENG_GUI_PIMPL(HomeWidget)
// Lay out the columns from left to right.
SequentialLayout layout(self.rule().left() - *scrollOffset,
self.rule().top(), ui::Right);
for(Widget *w : self.childWidgets())
for(ColumnWidget *column : columns)
{
if(w->isHidden()) continue;
if(ColumnWidget *column = w->maybeAs<ColumnWidget>())
{
layout << *column;
}
if(column->isHidden()) continue;
layout << *column;
}
}

void switchTab(int dir)
{
auto pos = tabs->current();
if(dir < 0 && pos > 0)
{
tabs->setCurrent(pos - 1);
}
else if(dir > 0 && pos < tabs->items().size() - 1)
{
tabs->setCurrent(pos + 1);
}
}

Expand All @@ -100,6 +114,14 @@ DENG_GUI_PIMPL(HomeWidget)
}
scrollOffset->set(*columnWidth * currentOffsetTab, span);
}

void updateHighlightedTab()
{
for(int pos = 0; pos < columns.size(); ++pos)
{
columns[pos]->setHighlighted(tabs->currentItem().data().toInt() == pos);
}
}
};

HomeWidget::HomeWidget()
Expand All @@ -110,7 +132,7 @@ HomeWidget::HomeWidget()

// Create the columns.

column = new ColumnWidget("nogames-column");
column = new NoGamesColumnWidget();
d->addColumn(column);

column = new ColumnWidget("doom-column");
Expand Down Expand Up @@ -140,6 +162,7 @@ HomeWidget::HomeWidget()
<< new TabItem(tr("Multiplayer"), 5)
<< new TabItem(tr("Packages") , 6);
d->tabs->setCurrent(0);
d->updateHighlightedTab();

// Tabs on top.
add(d->tabsBackground);
Expand Down Expand Up @@ -177,12 +200,22 @@ bool HomeWidget::handleEvent(Event const &event)
KeyEvent const &key = event.as<KeyEvent>();
if(key.qtKey() == Qt::Key_Left)
{
//d->scrollToTab(d->currentOffsetTab - 1, SCROLL_SPAN);
d->switchTab(-1);
return true;
}
else if(key.qtKey() == Qt::Key_Right)
{
//d->scrollToTab(d->currentOffsetTab + 1, SCROLL_SPAN);
d->switchTab(+1);
return true;
}
else if(key.qtKey() == Qt::Key_Home)
{
d->tabs->setCurrent(0);
return true;
}
else if(key.qtKey() == Qt::Key_End)
{
d->tabs->setCurrent(d->tabs->items().size() - 1);
return true;
}
}
Expand All @@ -197,4 +230,5 @@ bool HomeWidget::handleEvent(Event const &event)
void HomeWidget::tabChanged()
{
d->scrollToTab(d->tabs->currentItem().data().toInt(), SCROLL_SPAN);
d->updateHighlightedTab();
}
55 changes: 55 additions & 0 deletions doomsday/apps/client/src/ui/home/nogamescolumnwidget.cpp
@@ -0,0 +1,55 @@
/** @file nogamescolumnwidget.cpp
*
* @authors Copyright (c) 2016 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>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. 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 General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#include "ui/home/nogamescolumnwidget.h"
#include "ui/clientwindow.h"
#include "ui/widgets/taskbarwidget.h"

#include <de/ButtonWidget>
#include <de/SignalAction>

using namespace de;

NoGamesColumnWidget::NoGamesColumnWidget()
: ColumnWidget("nogames-column")
{
LabelWidget *notice = LabelWidget::newWithText(
_E(b) + tr("No playable games were found.\n") + _E(.) +
tr("Please select the folder where you have one or more game WAD files."),
this);
notice->setMaximumTextWidth(maximumContentWidth());
notice->setTextColor("text");
notice->setSizePolicy(ui::Expand, ui::Expand);
notice->rule()
.setMidAnchorX(rule().midX())
.setInput(Rule::Bottom, rule().midY());

ButtonWidget *chooseIwad = new ButtonWidget;
chooseIwad->setText(tr("Select IWAD Folder..."));
chooseIwad->setSizePolicy(ui::Expand, ui::Expand);
chooseIwad->rule()
.setMidAnchorX(rule().midX())
.setInput(Rule::Top, notice->rule().bottom());
chooseIwad->setAction(new SignalAction(this, SLOT(browseForDataFiles())));
add(chooseIwad);
}

void NoGamesColumnWidget::browseForDataFiles()
{
ClientWindow::main().taskBar().chooseIWADFolder();
}

0 comments on commit 62d923d

Please sign in to comment.