Skip to content

Commit

Permalink
Client|ConsoleWidget: Opening and closing
Browse files Browse the repository at this point in the history
The new console widget is starting to be functional enough to allow
dropping the old one.
  • Loading branch information
skyjake committed Jun 1, 2013
1 parent 430d076 commit 1381b34
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 6 deletions.
6 changes: 6 additions & 0 deletions doomsday/client/include/ui/widgets/consolewidget.h
Expand Up @@ -40,10 +40,16 @@ class ConsoleWidget : public QObject, public GuiWidget

ConsoleCommandWidget &commandLine();
LogWidget &log();
de::Rule const &shift();

// Events.
void viewResized();
bool handleEvent(de::Event const &event);

public slots:
void open();
void close();

protected slots:
void logContentHeightIncreased(int delta);

Expand Down
4 changes: 1 addition & 3 deletions doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -111,11 +111,9 @@ DENG2_OBSERVES(Canvas, FocusChange)
ConsoleWidget *console = new ConsoleWidget;
console->rule()
.setInput(Rule::Bottom, taskBar->rule().top() - unit)
.setInput(Rule::Left, root.viewLeft());
.setInput(Rule::Left, root.viewLeft() + console->shift());
root.add(console);

root.setFocus(&console->commandLine());

// Initially the widget is disabled. It will be enabled when the window
// is visible and ready to be drawn.
legacy->disable();
Expand Down
78 changes: 75 additions & 3 deletions doomsday/client/src/ui/widgets/consolewidget.cpp
Expand Up @@ -34,9 +34,11 @@ DENG2_PIMPL(ConsoleWidget)
{
ConsoleCommandWidget *cmdLine;
LogWidget *log;
ScalarRule *horizShift;
ScalarRule *height;
ScalarRule *width;

bool opened;
bool grabHover;
int grabWidth;
bool grabbed;
Expand All @@ -45,18 +47,21 @@ DENG2_PIMPL(ConsoleWidget)
: Base(i),
cmdLine(0),
log(0),
opened(true),
grabHover(false),
grabWidth(0),
grabbed(false)
{
width = new ScalarRule(self.style().rules().rule("console.width").valuei());
height = new ScalarRule(0);
horizShift = new ScalarRule(0);
width = new ScalarRule(self.style().rules().rule("console.width").valuei());
height = new ScalarRule(0);

grabWidth = self.style().rules().rule("unit").valuei();
grabWidth = self.style().rules().rule("unit").valuei();
}

~Instance()
{
releaseRef(horizShift);
releaseRef(width);
releaseRef(height);
}
Expand Down Expand Up @@ -132,6 +137,8 @@ ConsoleWidget::ConsoleWidget() : GuiWidget("Console"), d(new Instance(this))
.setInput(Rule::Width, OperatorRule::minimum(ClientWindow::main().root().viewWidth(),
OperatorRule::maximum(*d->width, Const(320))))
.setInput(Rule::Height, d->cmdLine->rule().height() + *d->height);

close();
}

ConsoleCommandWidget &ConsoleWidget::commandLine()
Expand All @@ -144,6 +151,20 @@ LogWidget &ConsoleWidget::log()
return *d->log;
}

Rule const &ConsoleWidget::shift()
{
return *d->horizShift;
}

void ConsoleWidget::viewResized()
{
if(!d->opened)
{
// Make sure it stays shifted out of the view.
d->horizShift->set(-rule().width().valuei() - 1);
}
}

void ConsoleWidget::glInit()
{
LOG_AS("ConsoleWidget");
Expand All @@ -157,6 +178,23 @@ void ConsoleWidget::glDeinit()

bool ConsoleWidget::handleEvent(Event const &event)
{
if(!d->opened)
{
// Just check for the opening event.
if(event.isKeyDown())
{
KeyEvent const &key = event.as<KeyEvent>();
if(key.qtKey() == Qt::Key_Escape &&
key.modifiers().testFlag(KeyEvent::Shift))
{
open();
return true;
}
}
return false;
}

// Hovering over the right edge shows the <-> cursor.
if(event.type() == Event::MousePosition)
{
MouseEvent const &mouse = event.as<MouseEvent>();
Expand Down Expand Up @@ -184,6 +222,7 @@ bool ConsoleWidget::handleEvent(Event const &event)
}
}

// Dragging the right edge resizes the widget.
if(d->grabHover && event.type() == Event::MouseButton)
{
switch(handleMouseClick(event))
Expand All @@ -206,6 +245,13 @@ bool ConsoleWidget::handleEvent(Event const &event)
{
KeyEvent const &key = event.as<KeyEvent>();

if(!d->grabbed && key.qtKey() == Qt::Key_Escape &&
key.modifiers().testFlag(KeyEvent::Shift))
{
close();
return true;
}

if(key.qtKey() == Qt::Key_PageUp ||
key.qtKey() == Qt::Key_PageDown)
{
Expand All @@ -225,6 +271,32 @@ bool ConsoleWidget::handleEvent(Event const &event)
return false;
}

void ConsoleWidget::open()
{
if(d->opened) return;

d->opened = true;
d->horizShift->set(0, .3f);

if(hasRoot())
{
root().setFocus(d->cmdLine);
}
}

void ConsoleWidget::close()
{
if(!d->opened) return;

d->opened = false;
d->horizShift->set(-rule().width().valuei() - 1, .3f);

if(hasRoot())
{
root().setFocus(0);
}
}

void ConsoleWidget::logContentHeightIncreased(int delta)
{
d->expandLog(delta, true);
Expand Down

0 comments on commit 1381b34

Please sign in to comment.