comparison demos/browser/tabwidget.d @ 94:87bb4e622f9e

more porting
author mandel
date Thu, 28 May 2009 22:11:52 +0000
parents 85c59c4e5f19
children
comparison
equal deleted inserted replaced
93:55fd7080c4b9 94:87bb4e622f9e
50 import qt.gui.QMessageBox; 50 import qt.gui.QMessageBox;
51 import qt.gui.QMouseEvent; 51 import qt.gui.QMouseEvent;
52 import qt.gui.QStackedWidget; 52 import qt.gui.QStackedWidget;
53 import qt.gui.QStyle; 53 import qt.gui.QStyle;
54 import qt.gui.QToolButton; 54 import qt.gui.QToolButton;
55 55 import qt.gui.QLineEdit;
56 import qt.core.QDebug; 56
57 //import qt.core.QDebug;
57 58
58 import browserapplication; 59 import browserapplication;
59 import browsermainwindow; 60 import browsermainwindow;
60 import history; 61 import history;
61 import urllineedit; 62 import urllineedit;
207 208
208 QPoint m_dragStartPos; 209 QPoint m_dragStartPos;
209 int m_dragCurrentIndex; 210 int m_dragCurrentIndex;
210 } 211 }
211 212
212 import QtWebKit.QWebPage; 213 import qt.webkit.QWebPage;
213 214
214 /*! 215 /*!
215 A proxy object that connects a single browser action 216 A proxy object that connects a single browser action
216 to one child webpage action at a time. 217 to one child webpage action at a time.
217 218
315 to proxy the actions. 316 to proxy the actions.
316 */ 317 */
317 class TabWidget : public QTabWidget 318 class TabWidget : public QTabWidget
318 { 319 {
319 // tab widget signals 320 // tab widget signals
320 mixin Singal!("loadPage", string /*url*/); 321 mixin Signal!("loadPage", string /*url*/);
321 mixin Singal!("tabsChanged"); 322 mixin Signal!("tabsChanged");
322 mixin Singal!("lastTabClosed"); 323 mixin Signal!("lastTabClosed");
323 324
324 // current tab signals 325 // current tab signals
325 mixin Singal!("setCurrentTitle", string /*url*/); 326 mixin Signal!("setCurrentTitle", string /*url*/);
326 mixin Singal!("showStatusBarMessage", string /*message*/); 327 mixin Signal!("showStatusBarMessage", string /*message*/);
327 mixin Singal!("linkHovered", string /*link*/); 328 mixin Signal!("linkHovered", string /*link*/);
328 mixin Singal!("loadProgress", int /*progress*/); 329 mixin Signal!("loadProgress", int /*progress*/);
329 mixin Singal!("geometryChangeRequested", QRect /*geometry*/); 330 mixin Signal!("geometryChangeRequested", QRect /*geometry*/);
330 mixin Singal!("menuBarVisibilityChangeRequested", bool /*visible*/); 331 mixin Signal!("menuBarVisibilityChangeRequested", bool /*visible*/);
331 mixin Singal!("statusBarVisibilityChangeRequested", bool /*visible*/); 332 mixin Signal!("statusBarVisibilityChangeRequested", bool /*visible*/);
332 mixin Singal!("toolBarVisibilityChangeRequested", bool /*visible*/); 333 mixin Signal!("toolBarVisibilityChangeRequested", bool /*visible*/);
333 mixin Singal!("printRequested", QWebFrame /*frame*/); 334 mixin Signal!("printRequested", QWebFrame /*frame*/);
334 335
335 public: 336 public:
336 337
337 this(QWidget parent = null) 338 this(QWidget parent = null)
338 { 339 {
379 m_nextTabAction.setShortcuts(shortcuts); 380 m_nextTabAction.setShortcuts(shortcuts);
380 m_nextTabAction.triggered.connect(&this.nextTab); 381 m_nextTabAction.triggered.connect(&this.nextTab);
381 382
382 m_previousTabAction = new QAction(tr("Show Previous Tab"), this); 383 m_previousTabAction = new QAction(tr("Show Previous Tab"), this);
383 shortcuts.clear(); 384 shortcuts.clear();
384 shortcuts ~= QKeySequence(Qt.CTRL | Qt.Key_BraceLeft); 385 shortcuts ~= QKeySequence(Qt_Modifier.CTRL | Qt_Key.Key_BraceLeft);
385 shortcuts ~= QKeySequence(Qt.CTRL | Qt.Key_PageUp); 386 shortcuts ~= QKeySequence(Qt_Modifier.CTRL | Qt_Key.Key_PageUp);
386 shortcuts ~= QKeySequence(Qt.CTRL | Qt.Key_BracketLeft); 387 shortcuts ~= QKeySequence(Qt_Modifier.CTRL | Qt_Key.Key_BracketLeft);
387 shortcuts ~= QKeySequence(Qt.CTRL | Qt.Key_Greater); 388 shortcuts ~= QKeySequence(Qt_Modifier.CTRL | Qt_Key.Key_Greater);
388 m_previousTabAction.setShortcuts(shortcuts); 389 m_previousTabAction.setShortcuts(shortcuts);
389 m_previousTabAction.triggered.connect(&this.previousTab); 390 m_previousTabAction.triggered.connect(&this.previousTab);
390 391
391 m_recentlyClosedTabsMenu = new QMenu(this); 392 m_recentlyClosedTabsMenu = new QMenu(this);
392 m_recentlyClosedTabsMenu.aboutToShow.connect(&this.aboutToShowRecentTabsMenu); 393 m_recentlyClosedTabsMenu.aboutToShow.connect(&this.aboutToShowRecentTabsMenu);
398 this.currentChanged.connect(&this.currentChanged); 399 this.currentChanged.connect(&this.currentChanged);
399 400
400 m_lineEdits = new QStackedWidget(this); 401 m_lineEdits = new QStackedWidget(this);
401 } 402 }
402 403
403 void clear() 404 void clearTabs()
404 { 405 {
405 // clear the recently closed tabs 406 // clear the recently closed tabs
406 m_recentlyClosedTabs.length = 0; 407 m_recentlyClosedTabs.length = 0;
407 // clear the line edit history 408 // clear the line edit history
408 for (int i = 0; i < m_lineEdits.count(); ++i) { 409 for (int i = 0; i < m_lineEdits.count(); ++i) {
495 static const int TabWidgetMagic = 0xaa; 496 static const int TabWidgetMagic = 0xaa;
496 497
497 QByteArray saveState() 498 QByteArray saveState()
498 { 499 {
499 int version_ = 1; 500 int version_ = 1;
500 QByteArray data; 501 auto data = new QByteArray;
501 QDataStream stream(data, QIODevice.WriteOnly); 502 auto stream = new QDataStream(data, QIODevice.WriteOnly);
502 503
503 stream << cast(int) TabWidgetMagic; 504 stream << cast(int) TabWidgetMagic;
504 stream << cast(int) version_; 505 stream << cast(int) version_;
505 506
506 string[] tabs; 507 string[] tabs;
507 for (int i = 0; i < count(); ++i) { 508 for (int i = 0; i < count(); ++i) {
508 if (WebView tab = cast(WebView) widget(i)) { 509 if (WebView tab = cast(WebView) widget(i)) {
509 tabs.append(tab.url().toString()); 510 tabs ~= tab.getUrl().toString();
510 } else { 511 } else {
511 tabs.append(null); //QString.null); 512 tabs ~= null; //QString.null);
512 } 513 }
513 } 514 }
514 stream << tabs; 515 stream << tabs;
515 stream << currentIndex(); 516 stream << currentIndex();
516 return data; 517 return data;
518 519
519 bool restoreState(QByteArray state) 520 bool restoreState(QByteArray state)
520 { 521 {
521 int version_ = 1; 522 int version_ = 1;
522 QByteArray sd = state; 523 QByteArray sd = state;
523 QDataStream stream(sd, QIODevice.ReadOnly); 524 auto stream = new QDataStream(sd, QIODevice.ReadOnly);
524 if (stream.atEnd()) 525 if (stream.atEnd())
525 return false; 526 return false;
526 527
527 int marker; 528 int marker;
528 int v; 529 int v;
663 if (index < 0) 664 if (index < 0)
664 index = currentIndex(); 665 index = currentIndex();
665 if (index < 0 || index >= count()) 666 if (index < 0 || index >= count())
666 return; 667 return;
667 WebView tab = newTab(false); 668 WebView tab = newTab(false);
668 tab.setUrl(webView(index).url()); 669 tab.setUrl(webView(index).getUrl());
669 } 670 }
670 671
671 // When index is -1 index chooses the current tab 672 // When index is -1 index chooses the current tab
672 void closeTab(int index = -1) 673 void closeTab(int index = -1)
673 { 674 {
692 return; 693 return;
693 } 694 }
694 hasFocus = tab.hasFocus(); 695 hasFocus = tab.hasFocus();
695 696
696 m_recentlyClosedTabsAction.setEnabled(true); 697 m_recentlyClosedTabsAction.setEnabled(true);
697 m_recentlyClosedTabs = [tab.url()] ~ m_recentlyClosedTabs; 698 m_recentlyClosedTabs = [tab.getUrl()] ~ m_recentlyClosedTabs;
698 if (m_recentlyClosedTabs.length >= TabWidget.m_recentlyClosedTabsSize) 699 if (m_recentlyClosedTabs.length >= TabWidget.m_recentlyClosedTabsSize)
699 m_recentlyClosedTabs.removeLast(); 700 m_recentlyClosedTabs = m_recentlyClosedTabs[0..$-1];
700 } 701 }
701 QWidget lineEdit = m_lineEdits.widget(index); 702 QWidget lineEdit = m_lineEdits.widget(index);
702 m_lineEdits.removeWidget(lineEdit); 703 m_lineEdits.removeWidget(lineEdit);
703 lineEdit.deleteLater(); 704 lineEdit.deleteLater();
704 QWidget webView = widget(index); 705 QWidget webView = widget(index);
787 } 788 }
788 setCurrentTitle.emit(webView.title()); 789 setCurrentTitle.emit(webView.title());
789 m_lineEdits.setCurrentIndex(index); 790 m_lineEdits.setCurrentIndex(index);
790 loadProgress.emit(webView.progress()); 791 loadProgress.emit(webView.progress());
791 showStatusBarMessage.emit(webView.lastStatusBarText()); 792 showStatusBarMessage.emit(webView.lastStatusBarText());
792 if (webView.url().isEmpty()) 793 if (webView.getUrl().isEmpty())
793 m_lineEdits.currentWidget().setFocus(); 794 m_lineEdits.currentWidget().setFocus();
794 else 795 else
795 webView.setFocus(); 796 webView.setFocus();
796 } 797 }
797 798
827 void webViewIconChanged() 828 void webViewIconChanged()
828 { 829 {
829 WebView webView = cast(WebView) signalSender(); 830 WebView webView = cast(WebView) signalSender();
830 int index = webViewIndex(webView); 831 int index = webViewIndex(webView);
831 if (-1 != index) { 832 if (-1 != index) {
832 QIcon icon = BrowserApplication.instance().icon(webView.url()); 833 QIcon icon = BrowserApplication.instance().icon(webView.getUrl());
833 setTabIcon(index, icon); 834 setTabIcon(index, icon);
834 } 835 }
835 } 836 }
836 837
837 void webViewTitleChanged(string title) 838 void webViewTitleChanged(string title)
841 if (-1 != index) { 842 if (-1 != index) {
842 setTabText(index, title); 843 setTabText(index, title);
843 } 844 }
844 if (currentIndex() == index) 845 if (currentIndex() == index)
845 setCurrentTitle.emit(title); 846 setCurrentTitle.emit(title);
846 BrowserApplication.historyManager().updateHistoryItem(webView.url(), title); 847 BrowserApplication.historyManager().updateHistoryItem(webView.getUrl(), title);
847 } 848 }
848 849
849 void webViewUrlChanged(QUrl url) 850 void webViewUrlChanged(QUrl url)
850 { 851 {
851 WebView webView = cast(WebView) signalSender(); 852 WebView webView = cast(WebView) signalSender();