MDIWindow最小化到任务栏

本文介绍了一种在Flex应用中自定义MDIWindow最小化行为的方法,通过添加HorizontalList来替代默认的任务栏最小化功能,并提供了详细的代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

MDIWindow本身的最小化到任务栏的功能用着很不方便,因此自己丰衣足食重写了最小化事件。先截个图让大家看看效果,项目组没有美工MM,因此界面比较丑请大家见谅。

 

 

 

思路如下:

          1.在MDICanvas的下面添加一个HorizontalList

          2.给MDICanvas的中添加MDIManagerEvent.WINDOW_MINIMIZE和MDIManagerEvent.WINDOW_CLOSE事件。

             WINDOW_MINIMIZE:最小化时屏蔽MDIwindow自身的最小化事件。

             WINDOW_CLOSE:点击窗口关闭按钮时,从HorizontalList中移除该窗口。

          3.MDICanvas中添加MDIwindow时向HorizontalList中添加数据

 

最小化和最小化按钮事件的代码如下:

 

/**
			 * 点击窗口的最小化按钮 最小化到任务栏
			 * 
			 */
			private function windowMinimizeHandler(event:MDIManagerEvent):void
			{
				if(event is MDIManagerEvent)
				{
					var mgrEvent:MDIManagerEvent=event as MDIManagerEvent;
					mgrEvent.window.visible=false;
					event.stopPropagation();
				}
			}
			/**
			 * 关闭窗口事件
			 * 
			 */
			private function windowCloseHandler(event:MDIManagerEvent):void{
				if(event is MDIManagerEvent)
				{
					var mgrEvent:MDIManagerEvent=event as MDIManagerEvent;
					for(var index:int;index<tbl.ac.length;index++){
						var item:TaskBarItem=tbl.ac.getItemAt(index) as TaskBarItem;
						if(mgrEvent.window==item.window){
							tbl.ac.removeItemAt(tbl.ac.getItemIndex(item));
						}
					}
					event.stopPropagation();
				}
			}

 

HorizontalList组件的代码如下:

 

<?xml version="1.0" encoding="utf-8"?>
<mx:HorizontalList xmlns:mx="http://www.adobe.com/2006/mxml"   dataProvider="{ac}" backgroundColor="#22668B" width="100%" height="35" borderStyle="outset" borderThickness="5">
	<mx:Script>
		<![CDATA[
			import flexmdi.events.MDIWindowEvent;
			import mx.collections.ArrayCollection;
			[Bindable]
			public var ac:ArrayCollection=new ArrayCollection();
			
			public function itemClick(obj:Object):void{
				var item:TaskBarItem=obj as TaskBarItem;
				if(item.window.visible){
					item.window.visible = false;
					item.window.dispatchEvent(new MDIWindowEvent(MDIWindowEvent.MINIMIZE,item.window));
				}else{
					item.window.visible = true;
					item.window.dispatchEvent(new MDIWindowEvent(MDIWindowEvent.MAXIMIZE,item.window));
					//把窗口置为顶层
					item.window.windowManager.bringToFront(item.window);
					//显示窗口上的最小化 最大化 正常按钮 记住一定要加这句 因为默认是隐藏的,只有鼠标点击顶部时才显示出来
					item.window.showControls=true;
				}
			}
			public function closeWindow(obj:Object):void{
				var item:TaskBarItem=obj as TaskBarItem;
				item.window.visible = false;
				item.window.dispatchEvent(new MDIWindowEvent(MDIWindowEvent.CLOSE,item.window));
			}
		]]>
	</mx:Script>
	<mx:itemRenderer>
		<mx:Component>
			<mx:HBox height="30" width="120" paddingRight="5" backgroundColor="#ADD6FB"  click="changeStyle('inset')" mouseOver="changeStyle('outset')"  
				borderStyle="outset"  verticalScrollPolicy="off"  horizontalScrollPolicy="off">
			    <mx:Script>
				<![CDATA[
					import mx.states.SetStyle;
					import mx.controls.Alert;
					private function changeStyle(borderStyle:String):void{
						this.setStyle("borderStyle",borderStyle);
					}
					
				]]>
				</mx:Script>
				<mx:HBox  height="30" width="80" click="outerDocument.itemClick(data)" paddingTop="0" paddingLeft="0">
					<mx:Image source="{data.icon}" includeInLayout="{data.icon==null?false:true}"/>
					<mx:Label text="{data.title}"/>
				</mx:HBox>
				<mx:HBox  height="30" width="20"  paddingTop="0" paddingLeft="0">
					<mx:Image source="img/ResizableTitleWindow/close.png"  alpha="0.2" toolTip="关闭该窗口" 
						 mouseOver="delImg.alpha=1" mouseOut="delImg.alpha=0.2"
						 id="delImg" click="outerDocument.closeWindow(data)" />
				</mx:HBox>
			</mx:HBox>
		</mx:Component>
	</mx:itemRenderer>
</mx:HorizontalList>

 

         

 

以上给出了实现最小化到任务栏的大部分代码,希望能和大家一起交流Flex的开发经验。

加上注释,不要分隔,写出当前类的功能/**************************************************************************** ** ** This file is part of the LibreCAD project, a 2D CAD program ** ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl) ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved. ** ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file gpl-2.0.txt included in the ** packaging of this file. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ** ** This copyright notice MUST APPEAR in all copies of the script! ** **********************************************************************/ #ifndef QC_MDIWINDOW_H #define QC_MDIWINDOW_H #include <qmainwindow.h> #include <qlist.h> #include "qc_graphicview.h" #include "qg_layerwidget.h" #include "qg_recentfiles.h" #include "qg_pentoolbar.h" //Added by qt3to4: #include <QCloseEvent> #include "rs_document.h" /** * MDI document window. Contains a document and a view (window). * * @author Andrew Mustun */ class QC_MDIWindow: public QMainWindow { Q_OBJECT public: QC_MDIWindow(RS_Document* doc, QWidget* parent, const char* name=NULL, Qt::WindowFlags wflags=Qt::WDestructiveClose); ~QC_MDIWindow(); void initDoc(RS_Document* doc=NULL); void initView(); public slots: void slotPenChanged(RS_Pen p); void slotFileNew(); bool slotFileOpen(const QString& fileName, RS2::FormatType type); bool slotFileSave(bool &cancelled, bool isAutoSave=false); bool slotFileSaveAs(bool &cancelled); bool slotFileClose(bool force); void slotFilePrint(); public: /** @return Pointer to graphic view */ QC_GraphicView* getGraphicView() { return graphicView; } /** @return Pointer to document */ RS_Document* getDocument() { return document; } /** @return Pointer to graphic or NULL */ RS_Graphic* getGraphic() { return document->getGraphic(); } /** @return Pointer to current event handler */ RS_EventHandler* getEventHandler() { if (graphicView!=NULL) { return graphicView->getEventHandler(); } else { return NULL; } } void addChildWindow(QC_MDIWindow* w); void removeChildWindow(QC_MDIWindow* w); QC_MDIWindow* getPrintPreview(); /** * Sets the parent window that will be notified if this */ void setParentWindow(QC_MDIWindow* p) { RS_DEBUG->print("setParentWindow"); parentWindow = p; } /** * @return The MDI window id. */ int getId() { return id; } bool closeMDI(bool force, bool ask=true); void setForceClosing(bool on) { forceClosing = on; } friend std::ostream& operator << (std::ostream& os, QC_MDIWindow& w); signals: void signalClosing(); protected: void closeEvent(QCloseEvent*); private: void drawChars(); private: /** window ID */ int id; /** ID counter */ static int idCounter; /** Graphic view */ QC_GraphicView* graphicView; /** Document */ RS_Document* document; /** Does the window own the document? */ bool owner; /** * List of known child windows that show blocks of the same drawing. */ QList<QC_MDIWindow*> childWindows; /** * Pointer to parent window which needs to know if this window * is closed or NULL. */ QC_MDIWindow* parentWindow; /** * If flag is set, the user will not be asked about closing this file. */ bool forceClosing; }; #endif
最新发布
07-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值