author | zecke <zecke> | 2004-10-08 21:34:32 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-10-08 21:34:32 (UTC) |
commit | 16afa90172c9b1facaa8888780ed8bb8bd93598c (patch) (unidiff) | |
tree | 3642810e51ceaacff2f6fba499e78d0cff0121b9 | |
parent | 0c3966672847b3b81c96c942727178368ac70e65 (diff) | |
download | opie-16afa90172c9b1facaa8888780ed8bb8bd93598c.zip opie-16afa90172c9b1facaa8888780ed8bb8bd93598c.tar.gz opie-16afa90172c9b1facaa8888780ed8bb8bd93598c.tar.bz2 |
Use KeyPressed instead of KeyReleased for the Accelerator
Key in the Image Display component. This fixes the
double 'next' problem when going from the browser to the viewer/display
-rw-r--r-- | noncore/graphics/opie-eye/gui/imageview.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/noncore/graphics/opie-eye/gui/imageview.cpp b/noncore/graphics/opie-eye/gui/imageview.cpp index b4f3110..5522131 100644 --- a/noncore/graphics/opie-eye/gui/imageview.cpp +++ b/noncore/graphics/opie-eye/gui/imageview.cpp | |||
@@ -1,174 +1,180 @@ | |||
1 | #include "imageview.h" | 1 | #include "imageview.h" |
2 | 2 | ||
3 | #include <opie2/odebug.h> | 3 | #include <opie2/odebug.h> |
4 | #include <opie2/oconfig.h> | 4 | #include <opie2/oconfig.h> |
5 | #include <opie2/okeyconfigwidget.h> | 5 | #include <opie2/okeyconfigwidget.h> |
6 | 6 | ||
7 | #include <qpe/resource.h> | 7 | #include <qpe/resource.h> |
8 | #include <qpe/qpeapplication.h> | 8 | #include <qpe/qpeapplication.h> |
9 | #include <qpopupmenu.h> | 9 | #include <qpopupmenu.h> |
10 | 10 | ||
11 | using namespace Opie::Core; | 11 | using namespace Opie::Core; |
12 | 12 | ||
13 | ImageView::ImageView(Opie::Core::OConfig *cfg, QWidget* parent, const char* name, WFlags fl ) | 13 | ImageView::ImageView(Opie::Core::OConfig *cfg, QWidget* parent, const char* name, WFlags fl ) |
14 | : Opie::MM::OImageScrollView(parent,name,fl) | 14 | : Opie::MM::OImageScrollView(parent,name,fl) |
15 | { | 15 | { |
16 | m_viewManager = 0; | 16 | m_viewManager = 0; |
17 | focus_in_count = 0; | 17 | focus_in_count = 0; |
18 | m_cfg = cfg; | 18 | m_cfg = cfg; |
19 | m_isFullScreen = false; | 19 | m_isFullScreen = false; |
20 | m_ignore_next_in = false; | 20 | m_ignore_next_in = false; |
21 | QPEApplication::setStylusOperation(viewport(),QPEApplication::RightOnHold); | 21 | QPEApplication::setStylusOperation(viewport(),QPEApplication::RightOnHold); |
22 | initKeys(); | 22 | initKeys(); |
23 | } | 23 | } |
24 | 24 | ||
25 | ImageView::~ImageView() | 25 | ImageView::~ImageView() |
26 | { | 26 | { |
27 | odebug << "Delete Imageview" << oendl; | 27 | odebug << "Delete Imageview" << oendl; |
28 | if (m_viewManager) { | 28 | delete m_viewManager; |
29 | delete m_viewManager; | ||
30 | } | ||
31 | } | 29 | } |
32 | 30 | ||
33 | Opie::Core::OKeyConfigManager* ImageView::manager() | 31 | Opie::Core::OKeyConfigManager* ImageView::manager() |
34 | { | 32 | { |
35 | if (!m_viewManager) { | 33 | if (!m_viewManager) { |
36 | initKeys(); | 34 | initKeys(); |
37 | } | 35 | } |
38 | return m_viewManager; | 36 | return m_viewManager; |
39 | } | 37 | } |
40 | 38 | ||
41 | void ImageView::initKeys() | 39 | void ImageView::initKeys() |
42 | { | 40 | { |
43 | odebug << "init imageview keys" << oendl; | 41 | odebug << "init imageview keys" << oendl; |
44 | if (!m_cfg) { | 42 | if (!m_cfg) { |
45 | m_cfg = new Opie::Core::OConfig("phunkview"); | 43 | m_cfg = new Opie::Core::OConfig("phunkview"); |
46 | m_cfg->setGroup("image_view_keys" ); | 44 | m_cfg->setGroup("image_view_keys" ); |
47 | } | 45 | } |
48 | Opie::Core::OKeyPair::List lst; | 46 | Opie::Core::OKeyPair::List lst; |
49 | lst.append( Opie::Core::OKeyPair::upArrowKey() ); | 47 | lst.append( Opie::Core::OKeyPair::upArrowKey() ); |
50 | lst.append( Opie::Core::OKeyPair::downArrowKey() ); | 48 | lst.append( Opie::Core::OKeyPair::downArrowKey() ); |
51 | lst.append( Opie::Core::OKeyPair::leftArrowKey() ); | 49 | lst.append( Opie::Core::OKeyPair::leftArrowKey() ); |
52 | lst.append( Opie::Core::OKeyPair::rightArrowKey() ); | 50 | lst.append( Opie::Core::OKeyPair::rightArrowKey() ); |
53 | lst.append( Opie::Core::OKeyPair(Qt::Key_Escape,0)); | 51 | lst.append( Opie::Core::OKeyPair(Qt::Key_Escape,0)); |
54 | 52 | ||
55 | m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "image_view_keys", | 53 | m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "image_view_keys", |
56 | lst, false,this, "image_view_keys" ); | 54 | lst, false,this, "image_view_keys" ); |
57 | 55 | ||
56 | /** | ||
57 | * Handle KeyEvents when they're pressed. This avoids problems | ||
58 | * with 'double next' on Return. | ||
59 | * The Return press would switch to this view and the return | ||
60 | * release would emit the dispNext Signal. | ||
61 | */ | ||
62 | m_viewManager->setEventMask( Opie::Core::OKeyConfigManager::MaskPressed ); | ||
63 | |||
58 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("View Image Info"), "imageviewinfo", | 64 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("View Image Info"), "imageviewinfo", |
59 | Resource::loadPixmap("1to1"), ViewInfo, | 65 | Resource::loadPixmap("1to1"), ViewInfo, |
60 | Opie::Core::OKeyPair(Qt::Key_I,0), | 66 | Opie::Core::OKeyPair(Qt::Key_I,0), |
61 | this, SLOT(slotShowImageInfo()))); | 67 | this, SLOT(slotShowImageInfo()))); |
62 | 68 | ||
63 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Toggle autorotate"), "imageautorotate", | 69 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Toggle autorotate"), "imageautorotate", |
64 | Resource::loadPixmap("rotate"), Autorotate, | 70 | Resource::loadPixmap("rotate"), Autorotate, |
65 | Opie::Core::OKeyPair(Qt::Key_R,0), | 71 | Opie::Core::OKeyPair(Qt::Key_R,0), |
66 | this, SIGNAL(toggleAutorotate()))); | 72 | this, SIGNAL(toggleAutorotate()))); |
67 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Toggle autoscale"), "imageautoscale", | 73 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Toggle autoscale"), "imageautoscale", |
68 | Resource::loadPixmap("1to1"), Autoscale, | 74 | Resource::loadPixmap("1to1"), Autoscale, |
69 | Opie::Core::OKeyPair(Qt::Key_S,0), | 75 | Opie::Core::OKeyPair(Qt::Key_S,0), |
70 | this, SIGNAL(toggleAutoscale()))); | 76 | this, SIGNAL(toggleAutoscale()))); |
71 | 77 | ||
72 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Switch to next image"), "imageshownext", | 78 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Switch to next image"), "imageshownext", |
73 | Resource::loadPixmap("forward"), ShowNext, | 79 | Resource::loadPixmap("forward"), ShowNext, |
74 | Opie::Core::OKeyPair(Qt::Key_Return,0), | 80 | Opie::Core::OKeyPair(Qt::Key_Return,0), |
75 | this, SIGNAL(dispNext()))); | 81 | this, SIGNAL(dispNext()))); |
76 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Switch to previous image"), "imageshowprev", | 82 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Switch to previous image"), "imageshowprev", |
77 | Resource::loadPixmap("back"), ShowPrevious, | 83 | Resource::loadPixmap("back"), ShowPrevious, |
78 | Opie::Core::OKeyPair(Qt::Key_P,0), | 84 | Opie::Core::OKeyPair(Qt::Key_P,0), |
79 | this, SIGNAL(dispPrev()))); | 85 | this, SIGNAL(dispPrev()))); |
80 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Toggle fullscreen"), "imagefullscreen", | 86 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Toggle fullscreen"), "imagefullscreen", |
81 | Resource::loadPixmap("fullscreen"), FullScreen, | 87 | Resource::loadPixmap("fullscreen"), FullScreen, |
82 | Opie::Core::OKeyPair(Qt::Key_F,0), | 88 | Opie::Core::OKeyPair(Qt::Key_F,0), |
83 | this, SIGNAL(toggleFullScreen()))); | 89 | this, SIGNAL(toggleFullScreen()))); |
84 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Toggle thumbnail"), "imagezoomer", | 90 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Toggle thumbnail"), "imagezoomer", |
85 | Resource::loadPixmap("mag"), Zoomer, | 91 | Resource::loadPixmap("mag"), Zoomer, |
86 | Opie::Core::OKeyPair(Qt::Key_T,0), | 92 | Opie::Core::OKeyPair(Qt::Key_T,0), |
87 | this, SIGNAL(toggleZoomer()))); | 93 | this, SIGNAL(toggleZoomer()))); |
88 | m_viewManager->handleWidget( this ); | 94 | m_viewManager->handleWidget( this ); |
89 | m_viewManager->load(); | 95 | m_viewManager->load(); |
90 | } | 96 | } |
91 | 97 | ||
92 | void ImageView::keyReleaseEvent(QKeyEvent * e) | 98 | void ImageView::keyReleaseEvent(QKeyEvent * e) |
93 | { | 99 | { |
94 | if (!e || e->state()!=0) { | 100 | if (!e || e->state()!=0) { |
95 | return; | 101 | return; |
96 | } | 102 | } |
97 | if (e->key()==Qt::Key_Escape && fullScreen()) emit hideMe(); | 103 | if (e->key()==Qt::Key_Escape && fullScreen()) emit hideMe(); |
98 | } | 104 | } |
99 | 105 | ||
100 | void ImageView::slotShowImageInfo() | 106 | void ImageView::slotShowImageInfo() |
101 | { | 107 | { |
102 | emit dispImageInfo(m_lastName); | 108 | emit dispImageInfo(m_lastName); |
103 | } | 109 | } |
104 | 110 | ||
105 | void ImageView::contentsMousePressEvent ( QMouseEvent * e) | 111 | void ImageView::contentsMousePressEvent ( QMouseEvent * e) |
106 | { | 112 | { |
107 | if (e->button()==1) { | 113 | if (e->button()==1) { |
108 | return OImageScrollView::contentsMousePressEvent(e); | 114 | return OImageScrollView::contentsMousePressEvent(e); |
109 | } | 115 | } |
110 | odebug << "Popup " << oendl; | 116 | odebug << "Popup " << oendl; |
111 | QPopupMenu *m = new QPopupMenu(0); | 117 | QPopupMenu *m = new QPopupMenu(0); |
112 | if (!m) return; | 118 | if (!m) return; |
113 | m->insertItem(tr("Toggle fullscreen"),this, SIGNAL(toggleFullScreen())); | 119 | m->insertItem(tr("Toggle fullscreen"),this, SIGNAL(toggleFullScreen())); |
114 | if (fullScreen()) { | 120 | if (fullScreen()) { |
115 | m->insertSeparator(); | 121 | m->insertSeparator(); |
116 | m->insertItem(tr("Previous image"),this,SIGNAL(dispPrev())); | 122 | m->insertItem(tr("Previous image"),this,SIGNAL(dispPrev())); |
117 | m->insertItem(tr("Next image"),this,SIGNAL(dispNext())); | 123 | m->insertItem(tr("Next image"),this,SIGNAL(dispNext())); |
118 | m->insertSeparator(); | 124 | m->insertSeparator(); |
119 | m->insertItem(tr("Toggle autoscale"),this, SIGNAL(toggleAutoscale())); | 125 | m->insertItem(tr("Toggle autoscale"),this, SIGNAL(toggleAutoscale())); |
120 | m->insertItem(tr("Toggle autorotate"),this, SIGNAL(toggleAutorotate())); | 126 | m->insertItem(tr("Toggle autorotate"),this, SIGNAL(toggleAutorotate())); |
121 | m->insertItem(tr("Toggle thumbnail"),this, SIGNAL(toggleZoomer())); | 127 | m->insertItem(tr("Toggle thumbnail"),this, SIGNAL(toggleZoomer())); |
122 | } | 128 | } |
123 | m->setFocus(); | 129 | m->setFocus(); |
124 | m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); | 130 | m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); |
125 | delete m; | 131 | delete m; |
126 | } | 132 | } |
127 | 133 | ||
128 | void ImageView::setFullScreen(bool how) | 134 | void ImageView::setFullScreen(bool how) |
129 | { | 135 | { |
130 | m_isFullScreen = how; | 136 | m_isFullScreen = how; |
131 | if (how) { | 137 | if (how) { |
132 | m_ignore_next_in = true; | 138 | m_ignore_next_in = true; |
133 | setFixedSize(qApp->desktop()->size()); | 139 | setFixedSize(qApp->desktop()->size()); |
134 | showFullScreen(); | 140 | showFullScreen(); |
135 | } else { | 141 | } else { |
136 | setMinimumSize(10,10); | 142 | setMinimumSize(10,10); |
137 | } | 143 | } |
138 | } | 144 | } |
139 | 145 | ||
140 | void ImageView::focusInEvent(QFocusEvent *) | 146 | void ImageView::focusInEvent(QFocusEvent *) |
141 | { | 147 | { |
142 | // Always do it here, no matter the size. | 148 | // Always do it here, no matter the size. |
143 | odebug << "Focus in (view)" << oendl; | 149 | odebug << "Focus in (view)" << oendl; |
144 | //if (fullScreen()) parentWidget()->showNormal(); | 150 | //if (fullScreen()) parentWidget()->showNormal(); |
145 | if (m_ignore_next_in){m_ignore_next_in=false;return;} | 151 | if (m_ignore_next_in){m_ignore_next_in=false;return;} |
146 | if (fullScreen()) enableFullscreen(); | 152 | if (fullScreen()) enableFullscreen(); |
147 | } | 153 | } |
148 | 154 | ||
149 | void ImageView::hide() | 155 | void ImageView::hide() |
150 | { | 156 | { |
151 | if (fullScreen()) { | 157 | if (fullScreen()) { |
152 | m_ignore_next_in = true; | 158 | m_ignore_next_in = true; |
153 | showNormal(); | 159 | showNormal(); |
154 | } | 160 | } |
155 | QWidget::hide(); | 161 | QWidget::hide(); |
156 | } | 162 | } |
157 | void ImageView::enableFullscreen() | 163 | void ImageView::enableFullscreen() |
158 | { | 164 | { |
159 | if (!fullScreen()) return; | 165 | if (!fullScreen()) return; |
160 | if (m_ignore_next_in) {m_ignore_next_in = false;return;} | 166 | if (m_ignore_next_in) {m_ignore_next_in = false;return;} |
161 | 167 | ||
162 | setUpdatesEnabled(false); | 168 | setUpdatesEnabled(false); |
163 | // This is needed because showNormal() forcefully changes the window | 169 | // This is needed because showNormal() forcefully changes the window |
164 | // style to WSTyle_TopLevel. | 170 | // style to WSTyle_TopLevel. |
165 | reparent(0, WStyle_Customize | WStyle_NoBorder, QPoint(0,0)); | 171 | reparent(0, WStyle_Customize | WStyle_NoBorder, QPoint(0,0)); |
166 | // Enable fullscreen. | 172 | // Enable fullscreen. |
167 | /* this is the trick - I don't now why, but after a showFullScreen QTE toggles the focus | 173 | /* this is the trick - I don't now why, but after a showFullScreen QTE toggles the focus |
168 | * so we must block it here! */ | 174 | * so we must block it here! */ |
169 | m_ignore_next_in = true; | 175 | m_ignore_next_in = true; |
170 | showFullScreen(); | 176 | showFullScreen(); |
171 | setUpdatesEnabled(true); | 177 | setUpdatesEnabled(true); |
172 | 178 | ||
173 | } | 179 | } |
174 | 180 | ||