2017-11-12 17:21:50 +01:00
# include "widgets/window.hpp"
2018-04-27 22:11:19 +02:00
# include "application.hpp"
2018-05-26 20:25:00 +02:00
# include "controllers/accounts/accountcontroller.hpp"
2018-01-12 19:15:21 +01:00
# include "singletons/ircmanager.hpp"
2017-12-31 00:50:07 +01:00
# include "singletons/settingsmanager.hpp"
# include "singletons/thememanager.hpp"
2018-01-24 15:08:22 +01:00
# include "singletons/windowmanager.hpp"
# include "widgets/accountswitchpopupwidget.hpp"
2018-01-06 20:27:26 +01:00
# include "widgets/helper/shortcut.hpp"
2017-06-11 09:31:45 +02:00
# include "widgets/notebook.hpp"
# include "widgets/settingsdialog.hpp"
2017-12-17 02:18:13 +01:00
# include "widgets/split.hpp"
2016-12-29 17:31:07 +01:00
2018-04-10 02:02:49 +02:00
# include <QApplication>
2018-04-25 14:49:30 +02:00
# include <QHeaderView>
2017-01-18 04:52:47 +01:00
# include <QPalette>
2017-05-27 15:40:42 +02:00
# include <QShortcut>
2017-04-12 17:46:44 +02:00
# include <QVBoxLayout>
2017-01-18 04:52:47 +01:00
2018-04-26 18:10:26 +02:00
# include <QStandardItemModel>
2018-04-25 14:49:30 +02:00
2017-04-14 17:52:22 +02:00
namespace chatterino {
namespace widgets {
2017-01-18 21:30:23 +01:00
2018-04-27 22:11:19 +02:00
Window : : Window ( WindowType _type )
2018-05-23 22:27:29 +02:00
: BaseWindow ( nullptr , BaseWindow : : EnableCustomFrame )
2018-04-06 23:31:34 +02:00
, type ( _type )
2018-01-25 20:49:49 +01:00
, dpi ( this - > getScale ( ) )
2018-05-23 04:22:17 +02:00
, notebook ( this )
2016-12-29 17:31:07 +01:00
{
2018-04-27 22:11:19 +02:00
auto app = getApp ( ) ;
2018-05-26 20:26:25 +02:00
app - > accounts - > twitch . currentUserChanged . connect ( [ this ] {
2018-05-26 13:38:25 +02:00
if ( this - > userLabel = = nullptr ) {
return ;
}
2018-05-26 20:26:25 +02:00
auto user = getApp ( ) - > accounts - > twitch . getCurrent ( ) ;
2018-05-25 18:23:13 +02:00
if ( user - > isAnon ( ) ) {
2018-04-27 22:11:19 +02:00
this - > refreshWindowTitle ( " Not logged in " ) ;
2018-05-25 18:23:13 +02:00
this - > userLabel - > getLabel ( ) . setText ( " anonymous " ) ;
2018-04-27 22:11:19 +02:00
} else {
2018-05-25 18:23:13 +02:00
this - > refreshWindowTitle ( user - > getUserName ( ) ) ;
this - > userLabel - > getLabel ( ) . setText ( user - > getUserName ( ) ) ;
2018-04-27 22:11:19 +02:00
}
} ) ;
2017-12-18 21:02:17 +01:00
2018-04-06 23:31:34 +02:00
if ( this - > hasCustomWindowFrame ( ) & & _type = = Window : : Main ) {
2018-04-27 22:11:19 +02:00
this - > addTitleBarButton ( TitleBarButton : : Settings , [ app ] {
app - > windows - > showSettingsDialog ( ) ; //
2018-01-24 20:27:56 +01:00
} ) ;
2018-05-25 13:53:55 +02:00
this - > userLabel = this - > addTitleBarLabel ( [ this , app ] {
app - > windows - > showAccountSelectPopup (
this - > userLabel - > mapToGlobal ( this - > userLabel - > rect ( ) . bottomLeft ( ) ) ) ; //
2018-01-24 15:08:22 +01:00
} ) ;
2018-01-15 01:35:35 +01:00
}
2018-04-06 23:31:34 +02:00
if ( _type = = Window : : Main ) {
2018-05-25 13:53:55 +02:00
this - > resize ( int ( 600 * this - > getScale ( ) ) , int ( 500 * this - > getScale ( ) ) ) ;
2018-04-06 23:31:34 +02:00
} else {
2018-05-25 13:53:55 +02:00
this - > resize ( int ( 300 * this - > getScale ( ) ) , int ( 500 * this - > getScale ( ) ) ) ;
2018-04-06 23:31:34 +02:00
}
2017-04-12 17:46:44 +02:00
QVBoxLayout * layout = new QVBoxLayout ( this ) ;
2017-06-13 21:13:58 +02:00
layout - > addWidget ( & this - > notebook ) ;
2018-01-15 01:35:35 +01:00
this - > getLayoutContainer ( ) - > setLayout ( layout ) ;
2017-04-12 17:46:44 +02:00
// set margin
layout - > setMargin ( 0 ) ;
2016-12-30 12:20:26 +01:00
2018-01-06 20:27:26 +01:00
/// Initialize program-wide hotkeys
2018-05-23 19:46:08 +02:00
// CTRL+P: Open settings dialog
2018-01-29 13:22:22 +01:00
CreateWindowShortcut ( this , " CTRL+P " , [ ] { SettingsDialog : : showDialog ( ) ; } ) ;
2018-05-23 19:46:08 +02:00
// CTRL+T: Create new split
CreateWindowShortcut ( this , " CTRL+T " ,
[ this ] { this - > notebook . getOrAddSelectedPage ( ) - > appendNewSplit ( true ) ; } ) ;
2018-01-06 20:27:26 +01:00
// CTRL+Number: Switch to n'th tab
2018-01-06 20:58:56 +01:00
CreateWindowShortcut ( this , " CTRL+1 " , [ this ] { this - > notebook . selectIndex ( 0 ) ; } ) ;
CreateWindowShortcut ( this , " CTRL+2 " , [ this ] { this - > notebook . selectIndex ( 1 ) ; } ) ;
CreateWindowShortcut ( this , " CTRL+3 " , [ this ] { this - > notebook . selectIndex ( 2 ) ; } ) ;
CreateWindowShortcut ( this , " CTRL+4 " , [ this ] { this - > notebook . selectIndex ( 3 ) ; } ) ;
CreateWindowShortcut ( this , " CTRL+5 " , [ this ] { this - > notebook . selectIndex ( 4 ) ; } ) ;
CreateWindowShortcut ( this , " CTRL+6 " , [ this ] { this - > notebook . selectIndex ( 5 ) ; } ) ;
CreateWindowShortcut ( this , " CTRL+7 " , [ this ] { this - > notebook . selectIndex ( 6 ) ; } ) ;
CreateWindowShortcut ( this , " CTRL+8 " , [ this ] { this - > notebook . selectIndex ( 7 ) ; } ) ;
CreateWindowShortcut ( this , " CTRL+9 " , [ this ] { this - > notebook . selectIndex ( 8 ) ; } ) ;
// CTRL+SHIFT+T: New tab
2018-05-23 04:22:17 +02:00
CreateWindowShortcut ( this , " CTRL+SHIFT+T " , [ this ] { this - > notebook . addPage ( true ) ; } ) ;
2018-01-06 20:58:56 +01:00
// CTRL+SHIFT+W: Close current tab
CreateWindowShortcut ( this , " CTRL+SHIFT+W " , [ this ] { this - > notebook . removeCurrentPage ( ) ; } ) ;
2018-01-12 19:15:21 +01:00
std : : vector < QString > cheerMessages ;
// clang-format off
cheerMessages . emplace_back ( R " (@badges=subscriber/12,premium/1;bits=2000;color=#B22222;display-name=arzenhuz;emotes=185989:33-37;id=1ae336ac-8e1a-4d6b-8b00-9fcee26e8337;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1515783470139;turbo=0;user-id=111553331;user-type= :arzenhuz!arzenhuz@arzenhuz.tmi.twitch.tv PRIVMSG #pajlada :pajacheer2000 Buy pizza for both pajaH) " ) ;
cheerMessages . emplace_back ( R " (@badges=subscriber/12,premium/1;bits=37;color=#3FBF72;display-name=VADIKUS007;emotes=;id=eedd95fd-2a17-4da1-879c-a1e76ffce582;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1515783184352;turbo=0;user-id=72256775;user-type= :vadikus007!vadikus007@vadikus007.tmi.twitch.tv PRIVMSG #pajlada :cheer37) " ) ;
cheerMessages . emplace_back ( R " (@badges=moderator/1,subscriber/24,bits/100;bits=1;color=#DCD3E6;display-name=swiftapples;emotes=80803:7-13;id=1c4647f6-f1a8-4acc-a9b2-b5d23d91258d;mod=1;room-id=11148817;subscriber=1;tmi-sent-ts=1515538318854;turbo=0;user-id=80526177;user-type=mod :swiftapples!swiftapples@swiftapples.tmi.twitch.tv PRIVMSG #pajlada :cheer1 pajaHey) " ) ;
cheerMessages . emplace_back ( R " (@badges=subscriber/12,turbo/1;bits=1;color=#0A2927;display-name=Binkelderk;emotes=;id=a1d9bdc6-6f6a-4c03-8554-d5b34721a878;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1515538899479;turbo=1;user-id=89081828;user-type= :binkelderk!binkelderk@binkelderk.tmi.twitch.tv PRIVMSG #pajlada :pajacheer1) " ) ;
cheerMessages . emplace_back ( R " (@badges=moderator/1,subscriber/24,bits/100;bits=1;color=#DCD3E6;display-name=swiftapples;emotes=80803:6-12;id=e9e21793-0b58-4ac6-8a1e-c19e165dbc9f;mod=1;room-id=11148817;subscriber=1;tmi-sent-ts=1515539073209;turbo=0;user-id=80526177;user-type=mod :swiftapples!swiftapples@swiftapples.tmi.twitch.tv PRIVMSG #pajlada :bday1 pajaHey) " ) ;
cheerMessages . emplace_back ( R " (@badges=partner/1;bits=1;color=#CC44FF;display-name=pajlada;emotes=;id=ca89214e-4fb5-48ec-853e-d2e6b41355ea;mod=0;room-id=39705480;subscriber=0;tmi-sent-ts=1515546977622;turbo=0;user-id=11148817;user-type= :pajlada!pajlada@pajlada.tmi.twitch.tv PRIVMSG #leesherwhy :test123 owocheer1 456test) " ) ;
cheerMessages . emplace_back ( R " (@badges=subscriber/12,premium/1;bits=1;color=#3FBF72;display-name=VADIKUS007;emotes=;id=c4c5061b-f5c6-464b-8bff-7f1ac816caa7;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1515782817171;turbo=0;user-id=72256775;user-type= :vadikus007!vadikus007@vadikus007.tmi.twitch.tv PRIVMSG #pajlada :trihard1) " ) ;
cheerMessages . emplace_back ( R " (@badges=;bits=1;color=#FF0000;display-name=?????;emotes=;id=979b6b4f-be9a-42fb-a54c-88fcb0aca18d;mod=0;room-id=11148817;subscriber=0;tmi-sent-ts=1515782819084;turbo=0;user-id=70656218;user-type= :stels_tv!stels_tv@stels_tv.tmi.twitch.tv PRIVMSG #pajlada :trihard1) " ) ;
cheerMessages . emplace_back ( R " (@badges=subscriber/3,premium/1;bits=1;color=#FF0000;display-name=kalvarenga;emotes=;id=4744d6f0-de1d-475d-a3ff-38647113265a;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1515782860740;turbo=0;user-id=108393131;user-type= :kalvarenga!kalvarenga@kalvarenga.tmi.twitch.tv PRIVMSG #pajlada :trihard1) " ) ;
// clang-format on
2018-02-05 15:11:50 +01:00
// CreateWindowShortcut(this, "F5", [cheerMessages] {
// auto &ircManager = singletons::IrcManager::getInstance();
// static int index = 0;
// ircManager.addFakeMessage(cheerMessages[index++ % cheerMessages.size()]);
// });
2018-04-18 18:55:49 +02:00
this - > setWindowTitle ( " Chatterino 2 Development Build " ) ;
2018-05-23 04:22:17 +02:00
this - > notebook . setAllowUserTabManagement ( true ) ;
this - > notebook . setShowAddButton ( true ) ;
2016-12-29 17:31:07 +01:00
}
2018-04-06 23:31:34 +02:00
Window : : WindowType Window : : getType ( )
{
return this - > type ;
}
2017-11-12 17:21:50 +01:00
void Window : : repaintVisibleChatWidgets ( Channel * channel )
2017-01-16 03:15:07 +01:00
{
2018-04-06 23:31:34 +02:00
auto * page = this - > notebook . getOrAddSelectedPage ( ) ;
2017-01-16 03:15:07 +01:00
2017-06-11 09:37:30 +02:00
if ( page = = nullptr ) {
2017-01-16 03:15:07 +01:00
return ;
}
2018-04-03 02:55:32 +02:00
for ( const auto & split : page - > getSplits ( ) ) {
if ( channel = = nullptr | | channel = = split - > getChannel ( ) . get ( ) ) {
split - > layoutMessages ( ) ;
2017-01-16 15:06:12 +01:00
}
2017-01-16 03:15:07 +01:00
}
}
2017-01-28 22:35:23 +01:00
2018-05-23 04:22:17 +02:00
SplitNotebook & Window : : getNotebook ( )
2017-04-12 17:46:44 +02:00
{
2017-06-13 21:13:58 +02:00
return this - > notebook ;
2017-04-12 17:46:44 +02:00
}
2017-06-07 10:09:24 +02:00
2017-12-18 21:02:17 +01:00
void Window : : refreshWindowTitle ( const QString & username )
{
this - > setWindowTitle ( username + " - Chatterino for Twitch " ) ;
}
2018-05-08 15:12:04 +02:00
bool Window : : event ( QEvent * event )
2018-01-23 22:48:33 +01:00
{
2018-05-08 15:12:04 +02:00
switch ( event - > type ( ) ) {
2018-01-23 22:48:33 +01:00
case QEvent : : WindowActivate :
break ;
case QEvent : : WindowDeactivate : {
2018-04-06 23:31:34 +02:00
auto page = this - > notebook . getOrAddSelectedPage ( ) ;
2018-01-23 22:48:33 +01:00
if ( page ! = nullptr ) {
std : : vector < Split * > splits = page - > getSplits ( ) ;
for ( Split * split : splits ) {
split - > updateLastReadMessage ( ) ;
}
}
2018-05-25 16:11:03 +02:00
if ( SplitContainer * container = dynamic_cast < SplitContainer * > ( page ) ) {
container - > hideResizeHandles ( ) ;
}
2018-01-23 22:48:33 +01:00
} break ;
2018-05-25 13:53:55 +02:00
default : ;
2018-01-23 22:48:33 +01:00
} ;
2018-05-08 15:12:04 +02:00
return BaseWindow : : event ( event ) ;
2018-01-23 22:48:33 +01:00
}
2018-05-25 13:53:55 +02:00
void Window : : closeEvent ( QCloseEvent * )
2017-12-17 17:09:50 +01:00
{
2018-04-06 23:31:34 +02:00
if ( this - > type = = Window : : Main ) {
2018-04-27 22:11:19 +02:00
auto app = getApp ( ) ;
app - > windows - > save ( ) ;
app - > windows - > closeAll ( ) ;
2018-01-05 03:09:44 +01:00
}
2018-04-06 23:31:34 +02:00
this - > closed . invoke ( ) ;
2018-04-10 02:02:49 +02:00
2018-04-20 22:54:09 +02:00
if ( this - > type = = Window : : Main ) {
QApplication : : exit ( ) ;
}
2017-12-22 14:44:31 +01:00
}
2017-04-14 17:52:22 +02:00
} // namespace widgets
} // namespace chatterino