-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathweb_browser.rb
120 lines (105 loc) · 3.21 KB
/
web_browser.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
require 'Qt'
require 'QtWebKitWidgets'
class MyWebBrowser < Qt::Widget
def initialize
super
@window = Qt::Widget.new
@window.window_title = 'Sk. Salahuddin - Morning 01 Batch'
@layout = Qt::VBoxLayout.new(@window)
@horizontal = Qt::HBoxLayout.new
@search_bar = Qt::LineEdit.new
@search_bar.placeholder_text = 'Search Google'
@search_bar.minimum_height = 50
@search_bar.style_sheet = <<-CSS
QLineEdit {
border: 2px solid #4a4a4a;
border-radius: 25px;
padding-left: 15px;
padding-right: 50px;
font-size: 18px;
font-family: Arial;
}
QLineEdit:focus {
border: 2px solid #0080ff;
}
CSS
@go_btn = Qt::PushButton.new('GO')
@go_btn.icon = Qt::Icon.new('go.png')
@go_btn.icon_size = Qt::Size.new(32, 32)
@go_btn.minimum_height = 50
@go_btn.set_fixed_size(50, 50)
@go_btn.style_sheet = <<-CSS
QPushButton {
border: none;
background-color: #0080ff;
border-radius: 25px;
}
QPushButton:hover {
background-color: #005ce6;
}
QPushButton:pressed {
background-color: #0047b3;
}
CSS
@back_btn = Qt::PushButton.new('<')
@back_btn.icon = Qt::Icon.new('back.png')
@back_btn.icon_size = Qt::Size.new(32, 32)
@back_btn.minimum_height = 50
@back_btn.set_fixed_size(50, 50)
@back_btn.style_sheet = <<-CSS
QPushButton {
border: none;
background-color: #4a4a4a;
border-radius: 25px;
}
QPushButton:hover {
background-color: #333333;
}
QPushButton:pressed {
background-color: #1a1a1a;
}
CSS
@forward_btn = Qt::PushButton.new('>')
@forward_btn.icon = Qt::Icon.new('forward.png')
@forward_btn.icon_size = Qt::Size.new(32, 32)
@forward_btn.minimum_height = 50
@forward_btn.set_fixed_size(50, 50)
@forward_btn.style_sheet = <<-CSS
QPushButton {
border: none;
background-color: #4a4a4a;
border-radius: 25px;
}
QPushButton:hover {
background-color: #333333;
}
QPushButton:pressed {
background-color: #1a1a1a;
}
CSS
@horizontal.add_widget(@search_bar)
@horizontal.add_widget(@go_btn)
@horizontal.add_widget(@back_btn)
@horizontal.add_widget(@forward_btn)
@browser = QtWebKitWidgets::QWebEngineView.new
@go_btn.connect(SIGNAL :clicked) { navigate(@search_bar.text) }
@back_btn.connect(SIGNAL :clicked) { @browser.back }
@forward_btn.connect(SIGNAL :clicked) { @browser.forward }
@search_bar.return_pressed { navigate(@search_bar.text) }
@layout.add_layout(@horizontal)
@layout.add_widget(@browser)
@browser.load(Qt::Url.new('https://www.google.com/'))
@window.set_layout(@layout)
@window.show
end
def navigate(url)
if !url.start_with?('http')
url = "https://www.google.com/search?q=#{url}"
@search_bar.text = url
end
@browser.load(Qt::Url.new(url))
end
end
app = Qt::Application.new(ARGV)
window = MyWebBrowser.new
app.exec