Skip to content

Commit

Permalink
Client|ConsoleWidget: Improved integration with LogWidget
Browse files Browse the repository at this point in the history
When in non-expanded mode, the console will expand the console when
pressing PageUp/Dn, instead of scrolling the log.
  • Loading branch information
skyjake committed May 30, 2013
1 parent c3020ca commit 51c74f5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
7 changes: 7 additions & 0 deletions doomsday/client/include/ui/widgets/logwidget.h
Expand Up @@ -72,6 +72,13 @@ class LogWidget : public QObject, public GuiWidget

void setContentYOffset(de::Animation const &anim);

/**
* Enables or disables scrolling with Page Up/Down keys.
*
* @param enabled @c true to enable Page Up/Down.
*/
void enablePageKeys(bool enabled);

// Events.
void viewResized();
void update();
Expand Down
25 changes: 22 additions & 3 deletions doomsday/client/src/ui/widgets/consolewidget.cpp
Expand Up @@ -53,6 +53,17 @@ DENG2_PIMPL(ConsoleWidget)
void glDeinit()
{
}

void expandLog(int delta, bool useOffsetAnimation)
{
height->set(height->scalar().target() + delta, .25f);

if(useOffsetAnimation)
{
// Sync the log content with the height animation.
log->setContentYOffset(Animation::range(Animation::EaseIn, delta, 0, .25f));
}
}
};

ConsoleWidget::ConsoleWidget() : GuiWidget("Console"), d(new Instance(this))
Expand Down Expand Up @@ -121,10 +132,20 @@ bool ConsoleWidget::handleEvent(Event const &event)
if(event.type() == Event::KeyPress)
{
KeyEvent const &key = static_cast<KeyEvent const &>(event);

if(key.qtKey() == Qt::Key_PageUp ||
key.qtKey() == Qt::Key_PageDown)
{
d->log->enablePageKeys(true);
d->expandLog(rule().top().valuei(), false);
return true;
}

if(key.qtKey() == Qt::Key_F5)
{
d->height->set(0);
d->log->scrollToBottom();
d->log->enablePageKeys(false);
return true;
}
}
Expand All @@ -133,7 +154,5 @@ bool ConsoleWidget::handleEvent(Event const &event)

void ConsoleWidget::logContentHeightIncreased(int delta)
{
d->height->set(d->height->scalar().target() + delta, .25f);
// Sync the log content with the height animation.
d->log->setContentYOffset(Animation::range(Animation::EaseIn, delta, 0, .25f));
d->expandLog(delta, true);
}
11 changes: 10 additions & 1 deletion doomsday/client/src/ui/widgets/logwidget.cpp
Expand Up @@ -301,6 +301,7 @@ DENG2_PIMPL(LogWidget), public Font::RichFormat::IStyle
enum { CancelAllRewraps = 0xffffffff };

// State.
bool pageKeysEnabled;
Animation visibleOffset;
int totalHeight;
int maxScroll;
Expand Down Expand Up @@ -339,6 +340,7 @@ DENG2_PIMPL(LogWidget), public Font::RichFormat::IStyle
sink(this),
cacheWidth(0),
cancelRewrap(0),
pageKeysEnabled(true),
visibleOffset(0),
totalHeight(0),
maxScroll(0),
Expand Down Expand Up @@ -840,6 +842,11 @@ void LogWidget::setContentYOffset(Animation const &anim)
}
}

void LogWidget::enablePageKeys(bool enabled)
{
d->pageKeysEnabled = enabled;
}

void LogWidget::viewResized()
{
d->updateProjection();
Expand All @@ -866,7 +873,8 @@ bool LogWidget::handleEvent(Event const &event)

switch(ev.ddKey())
{
case DDKEY_PGUP:
case DDKEY_PGUP:
if(!d->pageKeysEnabled) return false;
if(ev.modifiers().testFlag(KeyEvent::Shift))
{
d->setVisibleOffset(d->maxScroll, .3f);
Expand All @@ -879,6 +887,7 @@ bool LogWidget::handleEvent(Event const &event)
return true;

case DDKEY_PGDN:
if(!d->pageKeysEnabled) return false;
if(ev.modifiers().testFlag(KeyEvent::Shift))
{
scrollToBottom();
Expand Down

0 comments on commit 51c74f5

Please sign in to comment.