dbrowser.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #include "dbrowser.h"
  2. #include <QDesktopWidget>
  3. #include <QTextEdit>
  4. DBrowser::DBrowser(QString homedir, QWidget *parent) :
  5. QWidget(parent)
  6. {
  7. //Depending on the screen size we use full screen or not. Assuming a small screen is a cellular device
  8. QDesktopWidget *desk=QApplication::desktop();
  9. bool mobile_device=false;
  10. if (desk->screenGeometry().height()<900 && desk->screenGeometry().width()<900){ //Probably a mobile device
  11. setWindowState(Qt::WindowFullScreen);
  12. mobile_device=true;
  13. }
  14. else if (DDeviceInformation::isTouchable()){
  15. setWindowState(Qt::WindowMaximized);
  16. }
  17. QFile qss(DDeviceInformation::getStyleName());
  18. //qDebug()<< DDeviceInformation::getStyleName();
  19. if( ! qss.open( QIODevice::ReadOnly ) )
  20. qDebug("Unable to open qss file");
  21. else if( qss.isOpen() )
  22. {
  23. QString styleSheet = QLatin1String(qss.readAll());
  24. setStyleSheet( styleSheet );
  25. this->setStyleSheet(styleSheet);
  26. }
  27. layout= new QVBoxLayout();
  28. layout->setMargin(3);
  29. layout->setSpacing(2);
  30. lblLocation=new QLabel;
  31. lblLocation->setObjectName("lblLocation");
  32. bButtons=new BrowserButtons();
  33. fBrowser = new FileBrowser(homedir,this);
  34. contextMenu = new ContextMenu();
  35. fBrowser->setContextMenu(contextMenu);
  36. lblLocation->setText(fBrowser->getCurrentPath());
  37. lblLocation->setWordWrap(true);
  38. //lblLocation->setStyleSheet("QLabel {color: #282828; background-color: #E3E4E5; border: 1px solid grey;}");
  39. connect(bButtons->tbView,SIGNAL(clicked()),this,SLOT(changeView()));
  40. if (mobile_device){
  41. layout->addWidget(lblLocation);
  42. layout->addWidget(fBrowser);
  43. layout->addWidget(bButtons);
  44. bButtons->setMobileGUI();
  45. connect(fBrowser->listViewWidget(),SIGNAL(clicked(QModelIndex)),fBrowser,SLOT(openResource()));
  46. }
  47. else {
  48. layout->addWidget(bButtons);
  49. layout->addWidget(lblLocation);
  50. layout->addWidget(fBrowser);
  51. lblLocation->setMinimumHeight(20);
  52. bButtons->setDesktopGUI();
  53. connect(fBrowser->listViewWidget(),SIGNAL(doubleClicked(QModelIndex)),fBrowser,SLOT(openResource()));
  54. connect(fBrowser->tableViewWidget(),SIGNAL(doubleClicked(QModelIndex)),fBrowser,SLOT(openResource()));
  55. connect(bButtons->tbExit,SIGNAL(clicked()),this,SLOT(exitRequested()));
  56. iconViewMode=new QAction(QIcon(":/icons32/icon-view"),tr("Icons"),this);
  57. listViewMode=new QAction(QIcon(":/icons32/list-view"),tr("List"),this);
  58. detailViewMode=new QAction(QIcon(":/icons32/list-view"),tr("Detail"),this);
  59. bButtons->tbView->addAction(iconViewMode);
  60. bButtons->tbView->addAction(listViewMode);
  61. bButtons->tbView->addAction(detailViewMode);
  62. connect(bButtons->tbView,SIGNAL(triggered(QAction*)),this,SLOT(changeViewRequested(QAction*)));
  63. }
  64. setLayout(layout);
  65. connect(fBrowser,SIGNAL(changeDirectory(QString)),lblLocation,SLOT(setText(QString)));
  66. connect(bButtons->tbPrev,SIGNAL(clicked()),fBrowser,SLOT(goBack()));
  67. connect(bButtons->tbUp,SIGNAL(clicked()),fBrowser,SLOT(goUp()));
  68. connect(bButtons->tbNext,SIGNAL(clicked()),fBrowser,SLOT(goForward()));
  69. connect(bButtons->tbHome,SIGNAL(clicked()),fBrowser,SLOT(goHome()));
  70. connect(fBrowser, SIGNAL(setBackButtonEnabled(bool)),bButtons->tbPrev,SLOT(setEnabled(bool)));
  71. connect(fBrowser, SIGNAL(setNextButtonEnabled(bool)),bButtons->tbNext,SLOT(setEnabled(bool)));
  72. connect(fBrowser, SIGNAL(setUpButtonEnabled(bool)),bButtons->tbUp,SLOT(setEnabled(bool)));
  73. connect(bButtons->tbFull,SIGNAL(clicked()),this,SLOT(maximizeRequested()));
  74. connect(this,SIGNAL(mapReady(QMap<qint64,int>*)),fBrowser,SLOT(setMap(QMap<qint64,int>*)));
  75. //Shortcut definitions
  76. QShortcut *scOpen = new QShortcut(QKeySequence(tr("Ctrl+o","Open")),this);
  77. connect(scOpen,SIGNAL(activated()),fBrowser,SLOT(openResource()));
  78. QShortcut *scCopy = new QShortcut(QKeySequence(tr("Ctrl+c","Copy")),this);
  79. connect(scCopy,SIGNAL(activated()),fBrowser,SLOT(copyResourceToBuffer()));
  80. QShortcut *scCut = new QShortcut(QKeySequence(tr("Ctrl+x","Cut")),this);
  81. connect(scCut,SIGNAL(activated()),fBrowser,SLOT(cutResourceToBuffer()));
  82. QShortcut *scPaste = new QShortcut(QKeySequence(tr("Ctrl+v","Paste")),this);
  83. connect(scPaste,SIGNAL(activated()),fBrowser,SLOT(pasteResource()));
  84. QShortcut *scBack = new QShortcut(QKeySequence(tr("Alt+Left","Back")),this);
  85. connect(scBack,SIGNAL(activated()),fBrowser,SLOT(goBack()));
  86. QShortcut *scForward = new QShortcut(QKeySequence(tr("Alt+Right","Forward")),this);
  87. connect(scForward,SIGNAL(activated()),fBrowser,SLOT(goForward()));
  88. QShortcut *scUp = new QShortcut(QKeySequence(tr("Alt+Up","Up")),this);
  89. connect(scUp,SIGNAL(activated()),fBrowser,SLOT(goUp()));
  90. QShortcut *scHome = new QShortcut(QKeySequence(tr("Home","Home")),this);
  91. connect(scHome,SIGNAL(activated()),fBrowser,SLOT(goHome()));
  92. QShortcut *scDelete = new QShortcut(QKeySequence(tr("Del","Delete")),this);
  93. connect(scDelete,SIGNAL(activated()),fBrowser,SLOT(deleteResourceRequest()));
  94. QShortcut *scEnter = new QShortcut(QKeySequence(tr("Enter","Enter")),this);
  95. connect(scEnter,SIGNAL(activated()),fBrowser,SLOT(openResource()));
  96. QShortcut *scIntro = new QShortcut(QKeySequence(tr("Return","Enter")),this);
  97. connect(scIntro,SIGNAL(activated()),fBrowser,SLOT(openResource()));
  98. QShortcut *scViewIcons = new QShortcut(QKeySequence(tr("Ctrl+1","View icons")),this);
  99. connect(scViewIcons,SIGNAL(activated()),fBrowser,SLOT(setIconViewConfiguration()));
  100. QShortcut *scViewList = new QShortcut(QKeySequence(tr("Ctrl+2","View list")),this);
  101. connect(scViewList,SIGNAL(activated()),fBrowser,SLOT(setListViewConfiguration()));
  102. QShortcut *scViewDetail = new QShortcut(QKeySequence(tr("Ctrl+3","View detail")),this);
  103. connect(scViewDetail,SIGNAL(activated()),fBrowser,SLOT(setDetailViewConfiguration()));
  104. }
  105. void DBrowser::exitRequested(){
  106. emit exit();
  107. }
  108. void DBrowser::maximizeRequested(){
  109. bButtons->tbFull->toggle();
  110. if(bButtons->tbFull->isChecked())
  111. bButtons->tbFull->setChecked(false);
  112. else
  113. bButtons->tbFull->setChecked(true);
  114. emit maximize();
  115. }
  116. void DBrowser::changeViewRequested(QAction * view){
  117. if ((view)==iconViewMode && fBrowser->viewMode()!=FileBrowser::icon){
  118. fBrowser->changeView(FileBrowser::icon);
  119. bButtons->tbView->setIcon(QIcon(":/icons32/icon-view"));
  120. }
  121. else if(view==listViewMode && fBrowser->viewMode()!=FileBrowser::list){
  122. fBrowser->changeView(FileBrowser::list);
  123. bButtons->tbView->setIcon(QIcon(":/icons32/list-view"));
  124. }
  125. else if(view==detailViewMode && fBrowser->viewMode()!=FileBrowser::detail){
  126. fBrowser->changeView(FileBrowser::detail);
  127. bButtons->tbView->setIcon(QIcon(":/icons32/list-view"));
  128. }
  129. }
  130. void DBrowser::changeView(){
  131. if (fBrowser->viewMode()==FileBrowser::icon){
  132. fBrowser->changeView(FileBrowser::list);
  133. bButtons->tbView->setIcon(QIcon(":/icons32/list-view"));
  134. }
  135. else if (fBrowser->viewMode()==FileBrowser::list){
  136. fBrowser->changeView(FileBrowser::detail);
  137. bButtons->tbView->setIcon(QIcon(":/icons32/list-view"));
  138. }
  139. else{
  140. fBrowser->changeView(FileBrowser::icon);
  141. bButtons->tbView->setIcon(QIcon(":/icons32/icon-view"));
  142. }
  143. bButtons->tbView->setIconSize(QSize(32,32));
  144. }
  145. void DBrowser::setItemWidget(QString path, QWidget * w){
  146. fBrowser->setItemWidget(path, w);
  147. }
  148. void DBrowser::setOverlayStatus(QString path, int status){
  149. fBrowser->setOverlayStatus(path,status);
  150. }
  151. void DBrowser::removeOverlayStatus(QString path){
  152. fBrowser->setOverlayStatus(path);
  153. }
  154. QFileSystemModel *DBrowser::getDirModel(){
  155. return fBrowser->getDirModel();
  156. }
  157. void DBrowser::addToolButtonButton(QToolButton *btn){
  158. bButtons->addWidget(btn);
  159. }
  160. /*void DBrowser::removeFromToolButton(QToolButton *btn){
  161. QToolButton *b=bButtons->findChild(btn->objectName());
  162. }
  163. */
  164. void DBrowser::addContextMenuAction(QAction *action){
  165. contextMenu->addContextMenuAction(action);
  166. }
  167. void DBrowser::addContextMenuMenu(QMenu *menu){
  168. contextMenu->addContextMenuMenu(menu);
  169. }
  170. void DBrowser::addContextMenuSeparator(){
  171. contextMenu->addContextMenuSeparator();
  172. }
  173. void DBrowser::removeFromContextMenu(int index){
  174. contextMenu->removeFromContextMenu(contextMenu->contextMenuActions().at(index));
  175. }
  176. /*
  177. void DBrowser::setContextMenuActionEnabled(QAction *action, bool enable){
  178. contextMenu->contextMenuActions().at(contextMenu->contextMenuActions().indexOf(action))->setEnabled(enable);
  179. }
  180. void DBrowser::setContextMenuActionVisible(QAction *action, bool enable){
  181. contextMenu->contextMenuActions().at(contextMenu->contextMenuActions().indexOf(action))->setVisible(enable);
  182. }
  183. */