开发者

How to use QLPreviewPanel?

开发者 https://www.devze.com 2023-02-17 06:15 出处:网络
How do I use QLPreviewPanel? I know it wasn\'t a public API before, but it is in 10.6. How can I use it to show a preview of a fil开发者_Go百科e in a standard QuickLook panel?Check out the QuickLookDo

How do I use QLPreviewPanel? I know it wasn't a public API before, but it is in 10.6. How can I use it to show a preview of a fil开发者_Go百科e in a standard QuickLook panel?


Check out the QuickLookDownloader code. It walks you through a couple of things you need to do to incorporate QLPreviewPanel into your code. Some of these include:

  1. Making your objects conform to the QLPreviewItem protocol - this tells Quick Look where to find the file you want to preview (and you are previewing files - you can't pass in custom data).
  2. Defining a data source and delegate for the QLPreviewPanel (if you're worked with NSTableViews before, this should be pretty familiar).
  3. Configuring the preview panel via the QLPreviewPanelController protocol (where you assign the data source and delegate).
  4. Displaying shared preview panel.

Items 1-3 are handled in the MyDocument class of the sample code. Toggling the display is mostly handled in the AppDelegate class. There's also support in the DownloadsTableView class that toggles the QLPreviewPanel via the space key, a la the Finder.


Sadly Apples QuickLookDownloader Demo uses Obj-C. I extended Josh's Demo with a show panel functionality to show how it is done in Swift: Panel and Popover example


I am just looking at this myself. And have found that Apple provide a good guide with examples in the Docs, Also there is a good example code and files here -> animgifqlgen

I am using the Enriched HTML method, which seems to be working for what I need.

The idea is to Use what ever code you would normally use to parse the info on the file. And use html for the layout and embedding the parsed info,the html is then displayed within the QL Panel. A lot of the normal html code works like size width length,bgcolor,src ...

The example will show how to write the code including the html parts.Which uses a NSMutableString and its appendString and appendFormat: to build the html.

I have not tried the other methods yet.

For testing I just configured the Document Content Type UTIs in the plist and the put a copy of the built product (the plugin) in my /Users/username/Library/QuickLook/ folder.

You may have to create the Folder.

Note that when you want to replace the plugin in the QuickLook folder by drag and dropping a new copy in the folder, it may be in use. Just put the old one in the trash. I also found it helped quitting the Quick Look Helper process using the Activity Monitor app. Doing so made sure I was seeing the results from the New version plugin rather than the old one still in memory. ( I sure someone will tell me I am doing bad ;-) )

0

精彩评论

暂无评论...
验证码 换一张
取 消