Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ruby-warrior
- Loading branch information
Showing
4 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module InvertsTheme | ||
def self.included(kls) | ||
kls.extend(Config) | ||
end | ||
module Config | ||
def default_theme(theme=nil) | ||
theme ? @default_theme = theme : @default_theme | ||
end | ||
def alternate_theme(theme=nil) | ||
theme ? @alternate_theme = theme : @alternate_theme | ||
end | ||
end | ||
|
||
attr_accessor :current_theme | ||
def current_theme | ||
@current_theme ||= self.class.default_theme | ||
end | ||
|
||
def keyPressEvent(event) | ||
invert_key = (event.key == Qt::Key_I && event.modifiers == Qt::CTRL) | ||
invert_key ? invert_theme : super | ||
end | ||
|
||
protected | ||
|
||
def invert_theme | ||
self.current_theme = using_default_theme? ? alternate_theme : default_theme | ||
set_theme(self.current_theme) | ||
rescue NoMethodError | ||
fail 'implement "set_theme(theme)" method.' | ||
end | ||
|
||
private | ||
|
||
def using_default_theme? | ||
current_theme == default_theme | ||
end | ||
|
||
def alternate_theme | ||
self.class.alternate_theme | ||
end | ||
|
||
def default_theme | ||
self.class.default_theme | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require_relative "../spec_helper" | ||
require_relative "../../app/models/inverts_theme" | ||
|
||
class DummyWidget | ||
include InvertsTheme | ||
|
||
default_theme "foo/bar" | ||
alternate_theme "foo/baz" | ||
|
||
def set_theme(theme) | ||
# This method must be implemented in any class that. | ||
# includes the InvertsTheme module. | ||
end | ||
end | ||
|
||
describe 'dummy widget includes theme inversion' do | ||
include KeyPressEventsTestHelper | ||
|
||
describe 'inverting the theme' do | ||
it 'delegates to the javascript function' do | ||
widget = DummyWidget.new | ||
widget.current_theme.must_equal "foo/bar" | ||
widget.keyPressEvent(ctrl_i_key_press) | ||
widget.current_theme.must_equal "foo/baz" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters