~smartboyhw/ubuntu/raring/rekonq/new-version-2.1-0ubuntu1

« back to all changes in this revision

Viewing changes to src/tabwindow/tabwindow.cpp

  • Committer: Howard Chan
  • Date: 2013-01-30 13:47:26 UTC
  • mfrom: (1.2.12)
  • Revision ID: smartboyhw@gmail.com-20130130134726-mzqeywo489dj4q64
* New upstream release.
* Fixed patch kubuntu_no_default_bookmarks.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
#include <QMovie>
65
65
#include <QTabBar>
66
66
#include <QToolButton>
67
 
 
 
67
#include <QSignalMapper>
68
68
#include <QWebHistory>
69
69
#include <QWebSettings>
70
70
 
171
171
    _addTabButton->setToolButtonStyle(Qt::ToolButtonIconOnly);
172
172
 
173
173
    connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
 
174
 
 
175
    // ----------------------------------------------------------------------------------------------
 
176
    // shortcuts for quickly switching to a tab
 
177
    QSignalMapper *tabSignalMapper = new QSignalMapper(this);
 
178
    for (int i = 0; i < 9; i++)
 
179
    {
 
180
        a = new KAction(i18n("Switch to Tab %1", i+1), this);
 
181
        a->setShortcut(KShortcut(QString("Alt+%1").arg(i+1)));
 
182
        actionCollection()->addAction(QL1S(QString("switch_tab_" + QString::number(i+1)).toAscii()), a);
 
183
        connect(a, SIGNAL(triggered(bool)), tabSignalMapper, SLOT(map()));
 
184
        tabSignalMapper->setMapping(a, i);
 
185
    }
 
186
    connect(tabSignalMapper, SIGNAL(mapped(int)), this, SLOT(setCurrentIndex(int)));
 
187
 
 
188
    // shortcuts for loading favorite pages
 
189
    QSignalMapper *favoritesSignalMapper = new QSignalMapper(this);
 
190
    for (int i = 1; i <= 9; ++i)
 
191
    {
 
192
        a = new KAction(i18n("Switch to Favorite Page %1", i), this);
 
193
        a->setShortcut(KShortcut(QString("Ctrl+%1").arg(i)));
 
194
        actionCollection()->addAction(QL1S(QString("switch_favorite_" + QString::number(i)).toAscii()), a);
 
195
        connect(a, SIGNAL(triggered(bool)), favoritesSignalMapper, SLOT(map()));
 
196
        favoritesSignalMapper->setMapping(a, i);
 
197
    }
 
198
    connect(favoritesSignalMapper, SIGNAL(mapped(int)), this, SLOT(loadFavorite(int)));
 
199
 
 
200
    _ac->readSettings();
174
201
}
175
202
 
176
203
 
220
247
    WebWindow *tab = new WebWindow(this, _isPrivateBrowsing, page);
221
248
 
222
249
    connect(tab, SIGNAL(titleChanged(QString)), this, SLOT(tabTitleChanged(QString)));
 
250
    connect(tab, SIGNAL(iconChanged()), this, SLOT(tabIconChanged()));
223
251
 
224
252
    connect(tab, SIGNAL(loadStarted()), this, SLOT(tabLoadStarted()));
225
253
    connect(tab, SIGNAL(loadFinished(bool)), this, SLOT(tabLoadFinished(bool)));
366
394
    tabTitle.replace('&', "&&");
367
395
 
368
396
    int index = indexOf(tab);
 
397
 
369
398
    if (-1 != index && !tabBar()->tabData(index).toBool())
370
399
    {
371
400
        setTabText(index, tabTitle);
382
411
}
383
412
 
384
413
 
 
414
void TabWindow::tabIconChanged()
 
415
{
 
416
    WebWindow *tab = qobject_cast<WebWindow *>(sender());
 
417
    if (!tab)
 
418
        return;
 
419
 
 
420
    if (tab->isLoading())
 
421
        return;
 
422
 
 
423
    int index = indexOf(tab);
 
424
 
 
425
    if (-1 == index)
 
426
        return;
 
427
 
 
428
    QLabel *label = qobject_cast<QLabel* >(tabBar()->tabButton(index, QTabBar::LeftSide));
 
429
    if (!label)
 
430
    {
 
431
        label = new QLabel(this);
 
432
        tabBar()->setTabButton(index, QTabBar::LeftSide, 0);
 
433
        tabBar()->setTabButton(index, QTabBar::LeftSide, label);
 
434
    }
 
435
 
 
436
    KIcon ic = IconManager::self()->iconForUrl(tab->url());
 
437
    label->setPixmap(ic.pixmap(16, 16));
 
438
}
 
439
 
 
440
 
385
441
void TabWindow::tabLoadStarted()
386
442
{
387
443
    WebWindow *tab = qobject_cast<WebWindow *>(sender());
577
633
    // WARNING: Code copied from prepareNewTab method.
578
634
    // Any new changes there should be applied here...
579
635
    disconnect(tab, SIGNAL(titleChanged(QString)), this, SLOT(tabTitleChanged(QString)));
 
636
    disconnect(tab, SIGNAL(iconChanged()), this, SLOT(tabIconChanged()));
580
637
    disconnect(tab, SIGNAL(loadStarted()), this, SLOT(tabLoadStarted()));
581
638
    disconnect(tab, SIGNAL(loadFinished(bool)), this, SLOT(tabLoadFinished(bool)));
582
639
    disconnect(tab, SIGNAL(pageCreated(WebPage*)), this, SLOT(pageCreated(WebPage*)));
585
642
    // WARNING: Code copied from prepareNewTab method.
586
643
    // Any new changes there should be applied here...
587
644
    connect(tab, SIGNAL(titleChanged(QString)), w, SLOT(tabTitleChanged(QString)));
 
645
    connect(tab, SIGNAL(iconChanged()), w, SLOT(tabIconChanged()));
588
646
    connect(tab, SIGNAL(loadStarted()), w, SLOT(tabLoadStarted()));
589
647
    connect(tab, SIGNAL(loadFinished(bool)), w, SLOT(tabLoadFinished(bool)));
590
648
    connect(tab, SIGNAL(pageCreated(WebPage*)), w, SLOT(pageCreated(WebPage*)));
672
730
{
673
731
    return _isPrivateBrowsing;
674
732
}
 
733
 
 
734
 
 
735
void TabWindow::loadFavorite(const int index)
 
736
{
 
737
    QStringList urls = ReKonfig::previewUrls();
 
738
    if (index < 0 || index > urls.length())
 
739
        return;
 
740
 
 
741
    KUrl url = KUrl(urls.at(index - 1));
 
742
    loadUrl(url);
 
743
    currentWebWindow()->setFocus();
 
744
}